Extreme weirdness with HandbrakeCLI and switching users

Support for HandBrake on Linux, Solaris, and other Unix-like platforms
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
tbabb
Posts: 2
Joined: Fri Dec 23, 2011 2:57 am

Extreme weirdness with HandbrakeCLI and switching users

Post by tbabb »

Consider this python file:

titleinfo.py

Code: Select all

#!/usr/bin/python

import sys
import os
import subprocess as subp

os.setgid(1002) #gid of "media"
os.setuid(1005) #uid of "jack"

# output uids/gids just to show you it works
print os.getuid(), os.geteuid()
print os.getgid(), os.getegid()

p = subp.Popen(["HandBrakeCLI", "-i", "/dev/sr0", "-t", "0"])
sout, serr = p.communicate()

sys.exit(p.returncode)
Can someone tell me why the following works:

Code: Select all

   sudo -u jack -g media HandBrakeCLI -i /dev/sr0 -t 0
...and outputs the title info, but:

Code: Select all

   sudo ./titleinfo.py
fails?

Specifically, HandBrakeCLI prints "libdvdread: Can't open /dev/sr0 for reading"
on failure.

even more weirdly:

Code: Select all

   sudo -u jack -g media ./titleinfo.py
succeeds (and prints the same uid/gids as when set from within the script using setuid/setgid).

What the *heck* is going on? It seems the only thing that could be different about these two execution environments is the uid/gid... but they're explicitly the same! Is this a configuration problem, or a bug? If it's a configuration problem, how on earth do I fix it?

(I can't just run as jack:media directly using sudo because HandBrakeCLI is being called from a daemon which chooses its user with setuid/setgid; and I would prefer to understand why one usage case works and the other doesn't).

Activity logs:

Failure:

Code: Select all

[18:50:12] hb_init: starting libhb thread
HandBrake svn4292 (2011101601) - Linux i686 - http://handbrake.fr
4 CPUs detected
Opening /dev/sr0...
[18:50:12] hb_scan: path=/dev/sr0, title_index=0
libbluray/bdnav/index_parse.c:157: indx_parse(): error opening /dev/sr0/BDMV/index.bdmv
libbluray/bluray.c:1471: nav_get_title_list(/dev/sr0) failed (0x9506828)
[18:50:12] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 4.1.3
libdvdread: Using libdvdcss version 1.2.10 for DVD access
libdvdread: Could not open /dev/sr0 with libdvdcss.
libdvdread: Can't open /dev/sr0 for reading
libdvdnav: vm: failed to open/read the DVD
[18:50:12] dvd: not a dvd - trying as a stream/file instead
[18:50:12] hb_stream_open: open /dev/sr0 failed
[18:50:12] scan: unrecognized file type
[18:50:12] libhb: scan thread found 0 valid title(s)
No title found.

HandBrake has exited.
Success:

Code: Select all

[18:49:52] hb_init: starting libhb thread
HandBrake svn4292 (2011101601) - Linux i686 - http://handbrake.fr
4 CPUs detected
Opening /dev/sr0...
[18:49:52] hb_scan: path=/dev/sr0, title_index=0
libbluray/bdnav/index_parse.c:157: indx_parse(): error opening /dev/sr0/BDMV/index.bdmv
libbluray/bluray.c:1471: nav_get_title_list(/dev/sr0) failed (0x9b8b828)
[18:49:52] bd: not a bd - trying as a stream/file instead
[18:49:54] dvd: Region mask 0xff
[18:49:54] dvd: Warning, DVD device has no region set
libdvdnav: Using dvdnav version 4.1.3
libdvdread: Using libdvdcss version 1.2.10 for DVD access
libdvdnav: DVD Title: AMADEUS_SIDE_B_16X9_LB
libdvdnav: DVD Serial Number: 237580C3
libdvdnav: DVD Title (Alternative): AMADEUS_SIDE_B_16X9_LB
libdvdnav: Unable to find map file '/home/tbabb/.dvdnav/AMADEUS_SIDE_B_16X9_LB.map'
libdvdnav: DVD disk reports itself with Region mask 0x00fe0000. Regions: 1

libdvdread: Attempting to retrieve all CSS keys
libdvdread: This can take a _long_ time, please be patient

libdvdread: Get key for /VIDEO_TS/VIDEO_TS.VOB at 0x00000120
libdvdread: Elapsed time 0
libdvdread: Get key for /VIDEO_TS/VTS_01_0.VOB at 0x0000cd31
libdvdread: Elapsed time 0
libdvdread: Get key for /VIDEO_TS/VTS_01_1.VOB at 0x0000f7ff
libdvdread: Elapsed time 0
libdvdread: Found 1 VTS's
libdvdread: Elapsed time 0
libdvdread: Using libdvdcss version 1.2.10 for DVD access
[18:49:54] scan: DVD has 2 title(s)
[18:49:54] scan: scanning title 1
[18:49:54] scan: opening IFO for VTS 1
[18:49:55] scan: duration is 00:56:50 (3410043 ms)
[18:49:55] pgc_id: 1, pgn: 1: pgc: 0x9b98530
[18:49:55] scan: vts=1, ttn=1, cells=0->14, blocks=0->1200818, 1200819 blocks
[18:49:55] scan: checking audio 1
[18:49:55] scan: id=0x80bd, lang=English (AC3), 3cc=eng ext=0
[18:49:55] scan: checking audio 2
[18:49:55] scan: id=0x81bd, lang=Francais (AC3), 3cc=fra ext=0
[18:49:55] scan: checking audio 3
[18:49:55] scan: id=0x82bd, lang=Unknown (AC3), 3cc=und ext=0
[18:49:55] scan: checking subtitle 1
[18:49:55] scan: id=0x21bd, lang=English, 3cc=eng
[18:49:55] scan: checking subtitle 2
[18:49:55] scan: id=0x23bd, lang=Francais, 3cc=fra
[18:49:55] scan: title 1 has 15 chapters
[18:49:55] scan: chap 1 c=0->0, b=0->71108 (71109), 214266 ms
[18:49:55] scan: chap 2 c=1->1, b=71109->112293 (41185), 133449 ms
[18:49:55] scan: chap 3 c=2->2, b=112294->215851 (103558), 247558 ms
[18:49:55] scan: chap 4 c=3->3, b=215852->261273 (45422), 126197 ms
[18:49:55] scan: chap 5 c=4->4, b=261274->328609 (67336), 211296 ms
[18:49:55] scan: chap 6 c=5->5, b=328610->433572 (104963), 327628 ms
[18:49:55] scan: chap 7 c=6->6, b=433573->488645 (55073), 156296 ms
[18:49:55] scan: chap 8 c=7->7, b=488646->586050 (97405), 243530 ms
[18:49:55] scan: chap 9 c=8->8, b=586051->693324 (107274), 330511 ms
[18:49:55] scan: chap 10 c=9->9, b=693325->803102 (109778), 327374 ms
[18:49:55] scan: chap 11 c=10->10, b=803103->862751 (59649), 178319 ms
[18:49:55] scan: chap 12 c=11->11, b=862752->946638 (83887), 255542 ms
[18:49:55] scan: chap 13 c=12->12, b=946639->1025132 (78494), 201230 ms
[18:49:55] scan: chap 14 c=13->13, b=1025133->1070344 (45212), 128387 ms
[18:49:55] scan: chap 15 c=14->14, b=1070345->1200818 (130474), 328453 ms
[18:49:55] scan: aspect = 0
[18:49:55] scan: scanning title 2
[18:49:55] scan: opening IFO for VTS 1
[18:49:55] scan: duration is 00:00:32 (32033 ms)
[18:49:55] pgc_id: 2, pgn: 1: pgc: 0x9b99288
[18:49:55] scan: vts=1, ttn=2, cells=0->0, blocks=1200819->1213762, 12944 blocks
[18:49:55] scan: checking audio 1
[18:49:55] scan: audio channel is not active
[18:49:55] scan: checking audio 2
[18:49:55] scan: audio channel is not active
[18:49:55] scan: checking audio 3
[18:49:55] scan: audio channel is not active
[18:49:55] scan: checking subtitle 1
[18:49:55] scan: id=0x20bd, lang=English, 3cc=eng
[18:49:55] scan: checking subtitle 2
[18:49:55] scan: id=0x20bd, lang=Francais, 3cc=fra
[18:49:55] scan: title 2 has 1 chapters
[18:49:55] scan: chap 1 c=0->0, b=1200819->1213762 (12944), 32033 ms
[18:49:55] scan: aspect = 0
libdvdnav: DVD disk reports itself with Region mask 0x00fe0000. Regions: 1
[18:49:59] scan: decoding previews for title 1
libdvdnav: DVD disk reports itself with Region mask 0x00fe0000. Regions: 1
[18:49:59] scan: title angle(s) 1
Scanning title 1 of 2...
[18:49:59] scan: audio 0x82bd: AC-3, rate=48000Hz, bitrate=192000 Unknown (AC3) (Dolby Surround)
[18:49:59] scan: audio 0x81bd: AC-3, rate=48000Hz, bitrate=192000 Francais (AC3) (Dolby Surround)
[18:49:59] scan: audio 0x80bd: AC-3, rate=48000Hz, bitrate=384000 English (AC3) (5.1 ch)
Scanning title 1 of 2...
Scanning title 1 of 2...
Scanning title 1 of 2...
Scanning title 1 of 2...
Scanning title 1 of 2...
Scanning title 1 of 2...
Scanning title 1 of 2...
[18:50:01] scan: content PAR gives wrong aspect 1.78; using container aspect 1.78
[18:50:01] scan: 10 previews, 720x480, 23.976 fps, autocrop = 52/56/0/0, aspect 1.78:1, PAR 853:720
[18:50:01] scan: decoding previews for title 2
libdvdnav: DVD disk reports itself with Region mask 0x00fe0000. Regions: 1
[18:50:01] scan: title angle(s) 1
Scanning title 2 of 2...
Scanning title 2 of 2...
Scanning title 2 of 2...
Scanning title 2 of 2...
Scanning title 2 of 2...
Scanning title 2 of 2...
[18:50:03] scan: content PAR gives wrong aspect 1.78; using container aspect 1.78
[18:50:03] scan: 10 previews, 720x480, 29.970 fps, autocrop = 0/0/20/6, aspect 1.78:1, PAR 853:720
[18:50:03] Title is likely interlaced or telecined (7 out of 10 previews). You should do something about that.
[18:50:03] scan: title (0) job->width:720, job->height:320
[18:50:03] scan: title (1) job->width:688, job->height:400
[18:50:03] libhb: scan thread found 2 valid title(s)
+ title 1:
  + Main Feature
  + vts 1, ttn 1, cells 0->14 (1200819 blocks)
  + duration: 00:56:50
  + size: 720x480, pixel aspect: 853/720, display aspect: 1.78, 23.976 fps
  + autocrop: 52/56/0/0
  + chapters:
    + 1: cells 0->0, 71109 blocks, duration 00:03:34
    + 2: cells 1->1, 41185 blocks, duration 00:02:13
    + 3: cells 2->2, 103558 blocks, duration 00:04:08
    + 4: cells 3->3, 45422 blocks, duration 00:02:06
    + 5: cells 4->4, 67336 blocks, duration 00:03:31
    + 6: cells 5->5, 104963 blocks, duration 00:05:28
    + 7: cells 6->6, 55073 blocks, duration 00:02:36
    + 8: cells 7->7, 97405 blocks, duration 00:04:04
    + 9: cells 8->8, 107274 blocks, duration 00:05:31
    + 10: cells 9->9, 109778 blocks, duration 00:05:27
    + 11: cells 10->10, 59649 blocks, duration 00:02:58
    + 12: cells 11->11, 83887 blocks, duration 00:04:16
    + 13: cells 12->12, 78494 blocks, duration 00:03:21
    + 14: cells 13->13, 45212 blocks, duration 00:02:08
    + 15: cells 14->14, 130474 blocks, duration 00:05:28
  + audio tracks:
    + 1, English (AC3) (5.1 ch) (iso639-2: eng), 48000Hz, 384000bps
    + 2, Francais (AC3) (Dolby Surround) (iso639-2: fra), 48000Hz, 192000bps
    + 3, Unknown (AC3) (Dolby Surround) (iso639-2: und), 48000Hz, 192000bps
  + subtitle tracks:
    + 1, English (iso639-2: eng) (Bitmap)(VOBSUB)
    + 2, Francais (iso639-2: fra) (Bitmap)(VOBSUB)
    + 3, Closed Captions (iso639-2: eng) (Text)(CC)
+ title 2:
  + vts 1, ttn 2, cells 0->0 (12944 blocks)
  + duration: 00:00:32
  + size: 720x480, pixel aspect: 853/720, display aspect: 1.78, 29.970 fps
  + autocrop: 0/0/20/6
  + chapters:
    + 1: cells 0->0, 12944 blocks, duration 00:00:32
  + audio tracks:
  + subtitle tracks:
    + 1, English (iso639-2: eng) (Bitmap)(VOBSUB)
    + 2, Francais (iso639-2: fra) (Bitmap)(VOBSUB)
    + 3, Closed Captions (iso639-2: und) (Text)(CC)
  + combing detected, may be interlaced or telecined

HandBrake has exited.
Post Reply