[問題] 使用 Policykit 重新開啟程式。

看板LinuxDev作者 (阿金)時間16年前 (2009/11/21 02:25), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
Hi All! 小弟寫了一隻 Gtk+ 的程式,其中一段流程如下: 當 Normal User 開啟時, 程式經由 polkit_gnome_auth_obtain() function 彈出身份驗證視窗, 等待確認無誤後,polkit_gnome_auth_obtain() 呼叫 callback function, 小弟打算在 callback function 中完成以下兩件事情: (1.) 結束原本的程式。 (2.) 改由 Privilege 權限開啟程式。 小弟的問題為: (1.) 請問在 callback function 內, 是否「一定」要透過呼叫某個 DBus Service來完成所有的事情呢? (2.) 依小弟 Google 搜尋後的結果,網路上大多數的例子, 都只提到要呼叫某個 DBus Service,就完成了。 例如:http://ftd4linux.nl/svn/nntpgrab/trunk/tests/shutdown_linux.c 所以小弟依樣畫葫蘆,寫了一個 DBus Dervice 如下: /usr/share/dbus-1/dbus.service: [D-BUS Service] Name=dbus Exec=/usr/bin/my_program User=root 並且在 polkit_gnome_auth_obtain() 的 callback function 之下嚐試呼叫: static void Privilege_Gain(PolKitAction *Action, gboolean Gain_Privilege) { DBusGConnection *Connection; DBusGProxy *Proxy; GError *Error = NULL; const char *Service = "dbus.service"; const char *Path = "dbus/service"; const char *Interface = "dbus.service"; polkit_action_debug(Action); if(!Gain_Privilege) gtk_main_quit(); Connection =dbus_g_bus_get(DBUS_BUS_SESSION, &Error); if (!Connection) { g_print("Connection = NULL: %s\n", Error->message); g_error_free(Error); } Proxy = dbus_g_proxy_new_for_name_owner (Connection, Service, Path, Interface, &Error); if (!Proxy) { g_warning ("proxy = NULL: %s\n", Error->message); g_error_free(Error); dbus_g_connection_unref(Connection); } } 執行後,在輸入完驗證視窗的密碼之後,出現警告訊息如下: (當然,DBus Service 的內容也就沒有正確執行了。) ** WARNING **: proxy = NULL: Could not get owner of name 'dbus.service': no such name. 以上兩問題,還請各位先進釋疑,小弟先謝謝了。 ^^ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.9.199.20 ※ 編輯: yillkid 來自: 124.9.199.20 (11/21 02:37)
文章代碼(AID): #1B1jycEX (LinuxDev)
文章代碼(AID): #1B1jycEX (LinuxDev)