为啥未设置 DBUS_SESSION_BUS_ADDRESS 时 g_file_copy 返回 Operation not supported

Posted

技术标签:

【中文标题】为啥未设置 DBUS_SESSION_BUS_ADDRESS 时 g_file_copy 返回 Operation not supported【英文标题】:why does g_file_copy return Operation not supported when DBUS_SESSION_BUS_ADDRESS is not set为什么未设置 DBUS_SESSION_BUS_ADDRESS 时 g_file_copy 返回 Operation not supported 【发布时间】:2013-01-18 04:50:21 【问题描述】:

以下代码可以作为普通用户会话正常工作:

#include <gio/gio.h>
int main()

        const gchar *uri = "https://***.com/questions/5758770/";
        GFile *in;
        GFile *out;
        GError *error = NULL;
        gboolean ret;
        g_type_init();
        in = g_file_new_for_uri(uri);
        out = g_file_new_for_path("/tmp/a");
        ret = g_file_copy(in, out, G_FILE_COPY_OVERWRITE,
                          NULL, NULL, NULL, &error);
        if (!ret)
                g_message("%s", error->message);
        return 0;

(取自glib-network-connection-example)

但是当 'su -' 到另一个用户并执行相同的二进制文件时,我收到以下错误:

**** 消息:不支持操作**

下面的strace转储:

execve("./uri_copy", ["./uri_copy"], [/* 24 vars */]) = 0
brk(0)                                  = 0x2318000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8757f3000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, st_mode=S_IFREG|0644, st_size=113424, ...) = 0
mmap(NULL, 113424, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc8757d7000
close(3)                                = 0
open("/usr/lib/libgio-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\21\3\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=7332859, ...) = 0
mmap(NULL, 3481536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc875281000
mprotect(0x7fc8753cd000, 2093056, PROT_NONE) = 0
mmap(0x7fc8755cc000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14b000) = 0x7fc8755cc000
mmap(0x7fc8755d2000, 4032, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc8755d2000
close(3)                                = 0
open("/usr/lib/libgobject-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\256\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=1571328, ...) = 0
mmap(NULL, 2416416, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc875033000
mprotect(0x7fc87507f000, 2097152, PROT_NONE) = 0
mmap(0x7fc87527f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4c000) = 0x7fc87527f000
close(3)                                = 0
open("/usr/lib/libglib-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\230\1\0\0\0\0\0"..., 832) = 832
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8757d6000
fstat(3, st_mode=S_IFREG|0755, st_size=4565491, ...) = 0
mmap(NULL, 3279624, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc874d12000
mprotect(0x7fc874e31000, 2097152, PROT_NONE) = 0
mmap(0x7fc875031000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11f000) = 0x7fc875031000
close(3)                                = 0
open("/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340l\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=776444, ...) = 0
mmap(NULL, 2212768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc874af5000
mprotect(0x7fc874b0c000, 2097152, PROT_NONE) = 0
mmap(0x7fc874d0c000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7fc874d0c000
mmap(0x7fc874d0e000, 13216, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc874d0e000
close(3)                                = 0
open("/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \30\2\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=10464009, ...) = 0
mmap(NULL, 3820672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc874750000
mprotect(0x7fc8748eb000, 2097152, PROT_NONE) = 0
mmap(0x7fc874aeb000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19b000) = 0x7fc874aeb000
mmap(0x7fc874af1000, 15488, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc874af1000
close(3)                                = 0
open("/usr/lib/libgthread-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\6\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=10190, ...) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8757d5000
mmap(NULL, 2100144, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc87454f000
mprotect(0x7fc874550000, 2093056, PROT_NONE) = 0
mmap(0x7fc87474f000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x7fc87474f000
close(3)                                = 0
open("/usr/lib/libffi.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\30\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=160444, ...) = 0
mmap(NULL, 2128152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc874347000
mprotect(0x7fc87434e000, 2097152, PROT_NONE) = 0
mmap(0x7fc87454e000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7000) = 0x7fc87454e000
close(3)                                = 0
open("/usr/lib/libgmodule-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\21\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=48372, ...) = 0
mmap(NULL, 2107576, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc874144000
mprotect(0x7fc874147000, 2093056, PROT_NONE) = 0
mmap(0x7fc874346000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7fc874346000
close(3)                                = 0
open("/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=110348, ...) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8757d4000
mmap(NULL, 2109720, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc873f40000
mprotect(0x7fc873f42000, 2097152, PROT_NONE) = 0
mmap(0x7fc874142000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7fc874142000
close(3)                                = 0
open("/lib/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\"\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=197331, ...) = 0
mmap(NULL, 2128888, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc873d38000
mprotect(0x7fc873d3f000, 2093056, PROT_NONE) = 0
mmap(0x7fc873f3e000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7fc873f3e000
close(3)                                = 0
open("/lib/libz.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360 \0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=102874, ...) = 0
mmap(NULL, 2188616, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc873b21000
mprotect(0x7fc873b37000, 2097152, PROT_NONE) = 0
mmap(0x7fc873d37000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16000) = 0x7fc873d37000
close(3)                                = 0
open("/lib/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260:\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=397849, ...) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8757d3000
mmap(NULL, 2189936, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc87390a000
mprotect(0x7fc87391e000, 2093056, PROT_NONE) = 0
mmap(0x7fc873b1d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13000) = 0x7fc873b1d000
mmap(0x7fc873b1f000, 6768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc873b1f000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc873909000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc873908000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc873907000
arch_prctl(ARCH_SET_FS, 0x7fc873908700) = 0
mprotect(0x7fc874aeb000, 16384, PROT_READ) = 0
mprotect(0x7fc873b1d000, 4096, PROT_READ) = 0
mprotect(0x7fc874d0c000, 4096, PROT_READ) = 0
mprotect(0x7fc873f3e000, 4096, PROT_READ) = 0
mprotect(0x7fc874142000, 4096, PROT_READ) = 0
mprotect(0x7fc8757f4000, 4096, PROT_READ) = 0
munmap(0x7fc8757d7000, 113424)          = 0
set_tid_address(0x7fc8739089d0)         = 3023
set_robust_list(0x7fc8739089e0, 24)     = 0
futex(0x7fff6deb5014, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 7fc873908700) = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGRTMIN, 0x7fc874afb7d0, [], SA_RESTORER|SA_SIGINFO, 0x7fc874b047b0, NULL, 8) = 0
rt_sigaction(SIGRT_1, 0x7fc874afb850, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7fc874b047b0, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY) = 0
brk(0)                                  = 0x2318000
brk(0x2339000)                          = 0x2339000
getresuid([0], [0], [0])                = 0
getresgid([0], [0], [0])                = 0
openat(AT_FDCWD, "/usr/lib/gio/modules", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
stat("/usr/lib/gio/modules/giomodule.cache", st_mode=S_IFREG|0644, st_size=317, ...) = 0
open("/usr/lib/charset.alias", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/gio/modules/giomodule.cache", O_RDONLY) = 4
fstat(4, st_mode=S_IFREG|0644, st_size=317, ...) = 0
read(4, "libgvfsdbus.so: gio-vfs,gio-volu"..., 317) = 317
close(4)                                = 0
getdents(3, /* 17 entries */, 32768)    = 704
stat("/usr/lib/gio/modules/libgvfsdbus.so", st_mode=S_IFREG|0755, st_size=1008539, ...) = 0
stat("/usr/lib/gio/modules/libgiognutls.so", st_mode=S_IFREG|0755, st_size=528214, ...) = 0
stat("/usr/lib/gio/modules/libgiolibproxy.so", st_mode=S_IFREG|0755, st_size=38152, ...) = 0
stat("/usr/lib/gio/modules/libgiognomeproxy.so", st_mode=S_IFREG|0755, st_size=61385, ...) = 0
stat("/usr/lib/gio/modules/libgsettingsgconfbackend.so", st_mode=S_IFREG|0755, st_size=80091, ...) = 0
stat("/usr/lib/gio/modules/libgioremote-volume-monitor.so", st_mode=S_IFREG|0755, st_size=520847, ...) = 0
stat("/usr/lib/gio/modules/libdconfsettings.so", st_mode=S_IFREG|0755, st_size=197917, ...) = 0
getdents(3, /* 0 entries */, 32768)     = 0
close(3)                                = 0
stat("/usr/lib/gio/modules/libgvfsdbus.so", st_mode=S_IFREG|0755, st_size=1008539, ...) = 0
futex(0x7fc8741430c8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
open("/usr/lib/gio/modules/libgvfsdbus.so", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\311\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=1008539, ...) = 0
mmap(NULL, 2296960, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc8736d6000
mprotect(0x7fc873705000, 2097152, PROT_NONE) = 0
mmap(0x7fc873905000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2f000) = 0x7fc873905000
close(3)                                = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, st_mode=S_IFREG|0644, st_size=113424, ...) = 0
mmap(NULL, 113424, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc8736ba000
close(3)                                = 0
open("/usr/lib/libgvfscommon.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 .\1\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=935965, ...) = 0
mmap(NULL, 2338440, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc87347f000
mprotect(0x7fc8734b5000, 2093056, PROT_NONE) = 0
mmap(0x7fc8736b4000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x35000) = 0x7fc8736b4000
close(3)                                = 0
open("/lib/libpcre.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\23\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=270107, ...) = 0
mmap(NULL, 2356392, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc87323f000
mprotect(0x7fc87327e000, 2097152, PROT_NONE) = 0
mmap(0x7fc87347e000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3f000) = 0x7fc87347e000
close(3)                                = 0
open("/lib/libudev.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@L\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=1088628, ...) = 0
mmap(NULL, 2173032, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc87302c000
mprotect(0x7fc87303d000, 2097152, PROT_NONE) = 0
mmap(0x7fc87323d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11000) = 0x7fc87323d000
close(3)                                = 0
open("/lib/libutil.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, st_mode=S_IFREG|0755, st_size=33117, ...) = 0
mmap(NULL, 2105600, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc872e29000
mprotect(0x7fc872e2b000, 2093056, PROT_NONE) = 0
mmap(0x7fc87302a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7fc87302a000
close(3)                                = 0
mprotect(0x7fc87302a000, 4096, PROT_READ) = 0
mprotect(0x7fc87323d000, 4096, PROT_READ) = 0
munmap(0x7fc8736ba000, 113424)          = 0
munmap(0x7fc8736d6000, 2296960)         = 0
munmap(0x7fc87347f000, 2338440)         = 0
munmap(0x7fc87323f000, 2356392)         = 0
munmap(0x7fc87302c000, 2173032)         = 0
munmap(0x7fc872e29000, 2105600)         = 0
open("/usr/lib64/gconv/gconv-modules.cache", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/gconv/gconv-modules", O_RDONLY|O_CLOEXEC) = 3
fstat(3, st_mode=S_IFREG|0644, st_size=56302, ...) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8757f2000
read(3, "# GNU libc iconv configuration.\n"..., 4096) = 4096
read(3, "lias\tCSISO141JUSIB1002//\tJUS_I.B"..., 4096) = 4096
read(3, "odule\t\tcost\nalias\tISO-IR-110//\t\t"..., 4096) = 4096
read(3, "9-14//\nalias\tL8//\t\t\tISO-8859-14/"..., 4096) = 4096
read(3, "CSEBCDICES//\t\tEBCDIC-ES//\nalias\t"..., 4096) = 4096
read(3, "IBM284//\nalias\tEBCDIC-CP-ES//\t\tI"..., 4096) = 4096
brk(0x235a000)                          = 0x235a000
read(3, "ias\t864//\t\t\tIBM864//\nalias\tCSIBM"..., 4096) = 4096
read(3, "lias\tCSIBM939//\t\tIBM939//\nmodule"..., 4096) = 4096
read(3, "alias\tcsGB2312//\t\tEUC-CN//\nalias"..., 4096) = 4096
read(3, "//\t\tISO-2022-CN-EXT//\nmodule\tISO"..., 4096) = 4096
read(3, "st\nalias\tISO-IR-55//\t\tISO_5428//"..., 4096) = 4096
read(3, "\tARMSCII-8//\t\tARMSCII-8\t1\n\n#\tfro"..., 4096) = 4096
read(3, "2//\t\tIBM1112\t\t1\n\n#\tfrom\t\t\tto\t\t\tm"..., 4096) = 4096
read(3, "module\tIBM9448//\t\tINTERNAL\t\tIBM9"..., 4096) = 3054
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7fc8757f2000, 4096)            = 0
futex(0x7fc874af08f8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
write(2, "** Message: Operation not suppor"..., 36** Message: Operation not supported
) = 36
exit_group(0)                           = ?
+++ exited with 0 +++

我已将问题缩小到未设置 DBUS_SESSION_BUS_ADDRESS 变量。

我想知道为什么上述解决方案需要 dbus,因为在 glib/gio 文档中没有提到这一点,并且是否有不需要 dbus 的下载文件解决方案,或者,我可以将 DBUS_SESSION_BUS_ADDRESS 设置为无论我如何切换到另一个用户的会话,它都能正常工作。

【问题讨论】:

尝试strace你的程序。你会发现哪些系统调用失败了。 我在以 root 身份运行二进制文件时添加了 strace 输出。它开始偏离 'mprotect(0x7fc87302a000, 4096, PROT_READ) = 0' 行,我仍然无法确定是什么原因造成的。 我发现当我作为任何其他用户而不只是 root 用户“su -”时会出现此问题。如果我通过 GDM 以其他用户身份登录,则不会出现问题。只有当我进入另一个用户时才会出现此问题。我认为这与 dbus 会话有关(在成功执行期间,我可以在 strace 中看到额外的 dbus 活动),但我不明白为什么 dbus 应该参与这样的操作。 猜测,http 处理是通过 fuse 模块完成的,当您更改用户时,由于某种原因,正确的 fuse 后端不会启动 - 但它会在您运行桌面时启动以该用户身份进行会话(即通过 gdm 登录) 【参考方案1】:

通过 GIO 访问本地文件不需要 DBus,但是通过 gvfsd 进行网络文件访问,DBus 用于在您的程序和守护程序之间进行通信。更多技术细节可以在GNOME 2.22 Release Notes找到。

这个问题Access another user's D-Bus session给出的答案应该可以解决你的问题。

【讨论】:

以上是关于为啥未设置 DBUS_SESSION_BUS_ADDRESS 时 g_file_copy 返回 Operation not supported的主要内容,如果未能解决你的问题,请参考以下文章

为啥谷歌分析显示未知(未设置)位置?

为啥在 Java 7 中未正确设置文件写入权限?

为啥在javascript中单击时未设置输入值?

为啥浏览器中未设置 res 标头中的 cookie?

为啥在 bash if 语句中未设置的变量被评估为 0

为啥没有在 CORS 未命中时设置“Vary: Origin”响应?