Help with gconf (and sudo)

Hi All

I'm in the process of writing a GTK/GNOME app for copying USB flash
drives.  The basic flow is:

 * the contents of a master USB key are copied to a temporary folder
   on the hard drive
 * and then every time a blank key is inserted, the data is copied
   from the temp folder to the key

The program handles copying to multiple blank keys in parallel, the user
gets visual feedback of progress and (eventually) audible feedback when
all current copying activity is complete - so they can rip out the keys,
put in more blanks and repeat.

My program uses DBus to get device events from HAL and automatically
starts work when it sees a device it likes.

The copy process initialises the device with mkfs, mounts it, copies the
files, unmounts it (to ensure buffers are flushed), remounts it, does
file checksums to make sure it all worked and finally unmounts it.

The basics are working pretty well but I'm currently hung up on one
nice-to-have feature.  GNOME/Nautilus wants to automatically mount every
USB drive as it is plugged in.  That obviously is not desirable in my
case so I turned it off with this command:

gconftool-2 --type bool --set /apps/nautilus/preferences/media_automount

When I'm not running my copy program I *do* like the automount feature,
so I can manually re enable it by setting that gconf key back to true.

What I would like ("Finally!" I hear you say) is to have my program turn
automount off when it starts and restore it when it exits.  The wrinkle
is that because my program uses mkfs, mount, umount etc it needs to run
as root - so I invoke it using sudo.  The fact that it's running as root
means that the gconf update seems to affect the root user's settings and
not the settings for the user who 'owns' the desktop.

I tried to workaround this by having my program run:

  su -c 'gconf ...' $SUDO_USER

which doesn't fail but seems to affect a gconf database in a different
session (if that makes sense).  I can set and query that key and it all
looks good from within my program but it has no effect on the automount
behaviour and it doesn't affect the gconf database as seen from a
non-sudo'd terminal window.

Any suggestions gratefully accepted.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]