Re:Re: Could connect GVFS session bus from a root privilege program?



Best regards.
I have a problem with GVFS when trying as root user.
Searching the net on hundreds of pages I have not found a clue to solve it.

Between the pages I found in this mailing list that that problem comes
from years ago.

 Https://mail.gnome.org/archives/gvfs-list/2010-May/msg00000.html

Someone can help me or know how to solve that problem. Thank you all.

##################################################
Hi All,

I have a problem that I need get the information from GVFS(I thought
it is), but the program run as root users.

I use g_volume_monitor_get() to get a monitor for the removable
devices and do something while removable devices connect or
disconnect, it works normally while run as  a plain user but failed
when run as the root user.

How could I do?   Hope for someone give me any clue, and thanks in advance.

Below is my test program.

#include <gio/gio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

static void print_drive_info(GDrive *drive)
{
    gchar *name;
    name = g_drive_get_name(drive);
    g_print("\tname: %s\n",
        name ? name : "(null)");
    g_free(name);
}

static void on_drive_changed(GVolumeMonitor *volume_monitor, GDrive *drive)
{
    g_print("Drive changed:\n");
    print_drive_info(drive);
}

static void on_drive_connected(GVolumeMonitor *volume_monitor, GDrive *drive)
{
    g_print("Drive connected:\n");
    print_drive_info(drive);
}

static void on_drive_disconnected(GVolumeMonitor *volume_monitor, GDrive *drive)
{
    g_print("Drive disconnected:\n");
    print_drive_info(drive);
}


int main(int argc, char *argv[])
{
    GVolumeMonitor *monitor;
    gtk_init(&argc, &argv);
    #if 0
    /*the following is my test by setting euid */
    int old_uid = getuid();
    int old_euid = geteuid();
    printf("uid is %d \n euid is %d \n",getuid(), geteuid() );
    //if (setuid(500) == -1)
    if (seteuid(500) == -1)
    {
    printf ("seteuid : %s \n", strerror(errno));
    return -1;
    }
    printf("uid is %d \n euid is %d \n",getuid(), geteuid() );
    #endif
    monitor = g_volume_monitor_get();
    g_signal_connect(monitor, "drive-changed",
G_CALLBACK(on_drive_changed), NULL);
    g_signal_connect(monitor, "drive-connected",
G_CALLBACK(on_drive_connected), NULL);
    g_signal_connect(monitor, "drive-disconnected",
G_CALLBACK(on_drive_disconnected), NULL);

    gtk_main();
    return 0;
}


--
 Best Regards,






Mis proyectos de software libre en:
Github - edwinspire


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