QtService 应用程序在作为服务运行时无法连接到系统总线
Posted
技术标签:
【中文标题】QtService 应用程序在作为服务运行时无法连接到系统总线【英文标题】:QtService application cannot connect to system bus when running as a service 【发布时间】:2013-08-07 07:35:48 【问题描述】:我已经用集成的 dbus 重新编译了 Qt for windows。
此外,我还实现了一个QtService
应用程序,它在系统总线上注册了一个服务和一个对象,如下所示:
QDBusConnection::systemBus().registerService("com.mycompany.Configuration");
QDBusConnection::systemBus().registerObject("/com/mycompany/Configuration/MySetting", myObject);
现在,当我使用-e
参数(作为常规应用程序运行)运行服务应用程序时,它工作正常,dbus-monitor
和qdbus --system
都向我显示注册的服务和对象。
但是,当我将应用程序作为 Windows 服务运行时,它不会在系统总线上注册任何内容。
调试服务会给我错误消息
未连接到 D-Bus 服务器
当调用registerService(...)
和registerObject(...)
时。
我已经设置了环境变量:
DBUS_SYSTEM_BUS_ADDRESS = autolaunch:
DBUS_SYSTEM_BUS_DEFAULT_ADDRESS = autolaunch:
我的 system.conf 文件:
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<type>system</type>
<fork/>
<pidfile>/pid</pidfile>
<listen>autolaunch:</listen>
<policy context="default">
<allow user="*"/>
<deny own="*"/>
<deny send_type="method_call"/>
<allow send_type="signal"/>
<allow send_requested_reply="true" send_type="method_return"/>
<allow send_requested_reply="true" send_type="error"/>
<allow receive_type="method_call"/>
<allow receive_type="method_return"/>
<allow receive_type="error"/>
<allow receive_type="signal"/>
<allow send_destination="org.freedesktop.DBus"/>
<deny send_destination="org.freedesktop.DBus"
send_interface="org.freedesktop.DBus"
send_member="UpdateActivationEnvironment"/>
</policy>
<includedir>system.d</includedir>
<include ignore_missing="yes">system-local.conf</include>
<include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
</busconfig>
另外,我在 system.d 文件夹中有一个com.mycompany.Configuration.conf
文件:
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only root can own the service -->
<policy context="default">
<allow own="com.mycompany.Configuration"/>
<allow send_interface="com.mycompany.Configuration"/>
<allow send_destination="com.mycompany.Configuration"/>
<allow receive_sender="com.mycompany.Configuration"/>
</policy>
</busconfig>
windows 服务本身称为 com.mycompany.Configuration 并作为本地系统帐户执行。
此外,dbus 详细输出显示我的 Windows 服务启动时正在发生一些事情:
[...]
1292: [dbus\dbus-connection.c(1154):_dbus_connection_release_io_path] locking io_path_mutex
1292: [dbus\dbus-connection.c(1160):_dbus_connection_release_io_path] start connection->io_path_acquired = 1
1292: [dbus\dbus-connection.c(1165):_dbus_connection_release_io_path] unlockingio_path_mutex
1292: [dbus\dbus-connection.c(1522):_dbus_connection_handle_watch] middle
1292: [dbus\dbus-connection.c(4222):_dbus_connection_get_dispatch_status_unlocked] dispatch status = complete is_connected = 1
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(1529):_dbus_connection_handle_watch] end
1292: [dbus\dbus-watch.c(696):dbus_watch_handle] After sanitization, watch flags on fd 1932 were 0
1292: [dbus\dbus-sysdeps-win.c(1110):_dbus_poll] select: to=7875
R:1944 E:1944
R:1936 E:1936
R:1932 E:1932
[dbus\dbus-sysdeps-win.c(1162):_dbus_poll] select: = 1:
R:1932
[dbus\dbus-connection.c(1503):_dbus_connection_handle_watch] start
1292: [dbus\dbus-connection.c(1505):_dbus_connection_handle_watch] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(1081):_dbus_connection_acquire_io_path] locking io_path_mutex
1292: [dbus\dbus-connection.c(1085):_dbus_connection_acquire_io_path] start connection->io_path_acquired = 0 timeout = 1
1292: [dbus\dbus-connection.c(1128):_dbus_connection_acquire_io_path] end connection->io_path_acquired = 1 we_acquired = 1
1292: [dbus\dbus-connection.c(1130):_dbus_connection_acquire_io_path] unlocking io_path_mutex
1292: [dbus\dbus-connection.c(1133):_dbus_connection_acquire_io_path] LOCK
1292: [dbus\dbus-transport-socket.c(919):socket_handle_watch] handling read watch 003d6f58 flags = 1
1292: [dbus\dbus-transport-socket.c(345):exchange_credentials] exchange_credentials: do_reading = 1, do_writing = 0
1292: [dbus\dbus-transport-socket.c(446):do_authentication] server auth state:waiting for input
1292: [dbus\dbus-sysdeps-win.c(207):_dbus_read_socket] recv: count=2048 fd=1932
1292: [dbus\dbus-sysdeps-win.c(217):_dbus_read_socket] recv: = 153
1292: [dbus\dbus-transport-socket.c(263):read_data_into_auth] read 153 bytes in auth phase
1292: [dbus\dbus-auth.c(2187):process_command] server: got command "DATA 30333432316532346364316236363730303938303934303836666364653631372063303064313764623036653935643732336665666330396131633131653265353030643632616237"
1292: [dbus\dbus-auth.c(1624):process_data] server: data: '03421e24cd1b6670098094086fcde617 c00d17db06e95d723fefc09a1c11e2e500d62ab7'
1292: [dbus\dbus-auth.c(2134):goto_state] server: going from state WaitingForData to state WaitingForBegin
1292: [dbus\dbus-auth.c(760):sha1_handle_second_client_response] server: authenticated client using DBUS_COOKIE_SHA1
1292: [dbus\dbus-transport-socket.c(345):exchange_credentials] exchange_credentials: do_reading = 1, do_writing = 0
1292: [dbus\dbus-transport-socket.c(460):do_authentication] server auth state:bytes to send
1292: [dbus\dbus-transport-socket.c(180):check_read_watch] fd = 1932
1292: [dbus\dbus-transport-socket.c(226):check_read_watch] setting read watch enabled = 0
1292: [dbus\dbus-watch.c(449):_dbus_watch_list_toggle_watch] Toggling watch 003d6f58 on fd 1932 to 0
1292: [dbus\dbus-transport-socket.c(165):check_write_watch] check_write_watch(): needed = 1 on connection 003d88b0 watch 003d7260 fd = 1932 outgoing messages exist 0
1292: [dbus\dbus-watch.c(449):_dbus_watch_list_toggle_watch] Toggling watch 003d7260 on fd 1932 to 1
1292: [dbus\dbus-transport-socket.c(703):do_reading] fd = 1932
1292: [dbus\dbus-connection.c(1154):_dbus_connection_release_io_path] locking io_path_mutex
1292: [dbus\dbus-connection.c(1160):_dbus_connection_release_io_path] start connection->io_path_acquired = 1
1292: [dbus\dbus-connection.c(1165):_dbus_connection_release_io_path] unlockingio_path_mutex
1292: [dbus\dbus-connection.c(1522):_dbus_connection_handle_watch] middle
1292: [dbus\dbus-connection.c(4222):_dbus_connection_get_dispatch_status_unlocked] dispatch status = complete is_connected = 1
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(1529):_dbus_connection_handle_watch] end
1292: [dbus\dbus-sysdeps-win.c(1110):_dbus_poll] select: to=5641
R:1944 E:1944
R:1936 E:1936
W:1932 E:1932
[dbus\dbus-sysdeps-win.c(1162):_dbus_poll] select: = 1:
W:1932
[dbus\dbus-connection.c(1503):_dbus_connection_handle_watch] start
1292: [dbus\dbus-connection.c(1505):_dbus_connection_handle_watch] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(1081):_dbus_connection_acquire_io_path] locking io_path_mutex
1292: [dbus\dbus-connection.c(1085):_dbus_connection_acquire_io_path] start connection->io_path_acquired = 0 timeout = 1
1292: [dbus\dbus-connection.c(1128):_dbus_connection_acquire_io_path] end connection->io_path_acquired = 1 we_acquired = 1
1292: [dbus\dbus-connection.c(1130):_dbus_connection_acquire_io_path] unlockingio_path_mutex
1292: [dbus\dbus-connection.c(1133):_dbus_connection_acquire_io_path] LOCK
1292: [dbus\dbus-transport-socket.c(948):socket_handle_watch] handling write watch, have_outgoing_messages = 0
1292: [dbus\dbus-transport-socket.c(345):exchange_credentials] exchange_credentials: do_reading = 0, do_writing = 1
1292: [dbus\dbus-transport-socket.c(460):do_authentication] server auth state:bytes to send
1292: [dbus\dbus-sysdeps-win.c(267):_dbus_write_socket] send: len=37 fd=1932
1292: [dbus\dbus-sysdeps-win.c(277):_dbus_write_socket] send: = 37
1292: [dbus\dbus-auth.c(2506):_dbus_auth_bytes_sent] server: Sent 37 bytes of: OK 4d63998db68399d8b48494595200cd61
1292: [dbus\dbus-transport-socket.c(345):exchange_credentials] exchange_credentials: do_reading = 0, do_writing = 1
1292: [dbus\dbus-transport-socket.c(446):do_authentication] server auth state:waiting for input
1292: [dbus\dbus-transport-socket.c(180):check_read_watch] fd = 1932
1292: [dbus\dbus-transport-socket.c(226):check_read_watch] setting read watchenabled = 1
1292: [dbus\dbus-watch.c(449):_dbus_watch_list_toggle_watch] Toggling watch 003d6f58 on fd 1932 to 1
1292: [dbus\dbus-transport-socket.c(165):check_write_watch] check_write_watch(): needed = 0 on connection 003d88b0 watch 003d7260 fd = 1932 outgoing messages exist 0
1292: [dbus\dbus-watch.c(449):_dbus_watch_list_toggle_watch] Toggling watch 003d7260 on fd 1932 to 0
1292: [dbus\dbus-transport-socket.c(503):do_writing] Not authenticated, not writing anything
1292: [dbus\dbus-transport-socket.c(165):check_write_watch] check_write_watch(): needed = 0 on connection 003d88b0 watch 003d7260 fd = 1932 outgoing messages exist 0
1292: [dbus\dbus-connection.c(1154):_dbus_connection_release_io_path] locking io_path_mutex
1292: [dbus\dbus-connection.c(1160):_dbus_connection_release_io_path] start connection->io_path_acquired = 1
1292: [dbus\dbus-connection.c(1165):_dbus_connection_release_io_path] unlockingio_path_mutex
1292: [dbus\dbus-connection.c(1522):_dbus_connection_handle_watch] middle
1292: [dbus\dbus-connection.c(4222):_dbus_connection_get_dispatch_status_unlocked] dispatch status = complete is_connected = 1
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(1529):_dbus_connection_handle_watch] end
1292: [dbus\dbus-watch.c(696):dbus_watch_handle] After sanitization, watch flags on fd 1932 were 0
1292: [dbus\dbus-sysdeps-win.c(1110):_dbus_poll] select: to=3484
R:1944 E:1944
R:1936 E:1936
R:1932 E:1932
[dbus\dbus-sysdeps-win.c(1162):_dbus_poll] select: = 1:
R:1932
[dbus\dbus-connection.c(1503):_dbus_connection_handle_watch] start
1292: [dbus\dbus-connection.c(1505):_dbus_connection_handle_watch] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(1081):_dbus_connection_acquire_io_path] locking io_path_mutex
1292: [dbus\dbus-connection.c(1085):_dbus_connection_acquire_io_path] start connection->io_path_acquired = 0 timeout = 1
1292: [dbus\dbus-connection.c(1128):_dbus_connection_acquire_io_path] end connection->io_path_acquired = 1 we_acquired = 1
1292: [dbus\dbus-connection.c(1130):_dbus_connection_acquire_io_path] unlockingio_path_mutex
1292: [dbus\dbus-connection.c(1133):_dbus_connection_acquire_io_path] LOCK
1292: [dbus\dbus-transport-socket.c(919):socket_handle_watch] handling read watch 003d6f58 flags = 1
1292: [dbus\dbus-transport-socket.c(345):exchange_credentials] exchange_credentials: do_reading = 1, do_writing = 0
1292: [dbus\dbus-transport-socket.c(446):do_authentication] server auth state:waiting for input
1292: [dbus\dbus-sysdeps-win.c(207):_dbus_read_socket] recv: count=2048 fd=1932
1292: [dbus\dbus-sysdeps-win.c(217):_dbus_read_socket] recv: = 135
1292: [dbus\dbus-transport-socket.c(263):read_data_into_auth] read 135 bytes in auth phase
1292: [dbus\dbus-auth.c(2187):process_command] server: got command "BEGIN"
1292: [dbus\dbus-auth.c(2134):goto_state] server: going from state WaitingForBegin to state Authenticated
1292: [dbus\dbus-sysdeps-win.c(787):_dbus_getsid] _dbus_getsid() returns 1
1292: [dbus\dbus-transport.c(673):auth_via_default_rules] Client authorized as S ID 'S-1-5-18' but our SID is 'S-1-5-21-4012214046-2405994403-1636280286-500', disconnecting
1292: [dbus\dbus-transport.c(503):_dbus_transport_disconnect] start
1292: [dbus\dbus-transport-socket.c(985):socket_disconnect]
1292: [dbus\dbus-transport-socket.c(76):free_watches] start
1292: [dbus\dbus-watch.c(417):_dbus_watch_list_remove_watch] Removing watch on fd 1932
1292: [dbus\dbus-watch.c(417):_dbus_watch_list_remove_watch] Removing watch on fd 1932
1292: [dbus\dbus-socket-set-poll.c(221):socket_set_poll_remove] after removing fd 1932 from 003d2430, 2 en/2 res/9 alloc
1292: [dbus\dbus-watch.c(628):dbus_watch_set_data] Setting watch fd -1 data to data = 00000000 function = 00000000 from data = 00000000 function = 00000000
1292: [dbus\dbus-transport-socket.c(98):free_watches] end
1292: [dbus\dbus-sysdeps-win.c(317):_dbus_close_socket] _dbus_close_socket: socket=1932,
1292: [dbus\dbus-transport.c(514):_dbus_transport_disconnect] end
1292: [dbus\dbus-transport-socket.c(180):check_read_watch] fd = -1
1292: [dbus\dbus-transport-socket.c(703):do_reading] fd = -1
1292: [dbus\dbus-watch.c(628):dbus_watch_set_data] Setting watch fd -1 data to data = 00000000 function = 00000000 from data = 00000000 function = 00000000
1292: [dbus\dbus-connection.c(1154):_dbus_connection_release_io_path] locking io_path_mutex
1292: [dbus\dbus-connection.c(1160):_dbus_connection_release_io_path] start connection->io_path_acquired = 1
1292: [dbus\dbus-connection.c(1165):_dbus_connection_release_io_path] unlockingio_path_mutex
1292: [dbus\dbus-connection.c(1522):_dbus_connection_handle_watch] middle
1292: [dbus\dbus-connection.c(4222):_dbus_connection_get_dispatch_status_unlocked] dispatch status = complete is_connected = 0
1292: [dbus\dbus-connection.c(4184):notify_disconnected_and_dispatch_complete_unlocked] Sending disconnect message
1292: [dbus\dbus-connection.c(567):_dbus_connection_queue_synthesized_message_link] Synthesized message 003d8948 added to incoming queue 003d88b0, 1 incoming
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(4299):_dbus_connection_update_dispatch_status_and_unlock] Notifying of change to dispatch status of 003d88b0 now 0 (data remains)
1292: [dbus\dbus-connection.c(1529):_dbus_connection_handle_watch] end
1292: [dbus\dbus-connection.c(4515):dbus_connection_dispatch]
1292: [dbus\dbus-connection.c(4517):dbus_connection_dispatch] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(4090):_dbus_connection_acquire_dispatch] locking dispatch_mutex
1292: [dbus\dbus-connection.c(4104):_dbus_connection_acquire_dispatch] unlocking dispatch_mutex
1292: [dbus\dbus-connection.c(4107):_dbus_connection_acquire_dispatch] LOCK
1292: [dbus\dbus-connection.c(3954):_dbus_connection_pop_message_link_unlocked]Message 003d8948 (signal /org/freedesktop/DBus/Local org.freedesktop.DBus.Local Disconnected '') removed from incoming queue 003d88b0, 0 incoming
1292: [dbus\dbus-connection.c(4563):dbus_connection_dispatch] dispatching message 003d8948 (signal org.freedesktop.DBus.Local Disconnected '')
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(4630):dbus_connection_dispatch] running filter on message 003d8948
1292: [dbus\dbus-connection.c(3126):dbus_connection_preallocate_send] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [bus\dispatch.c(216):bus_dispatch] DISPATCH: org.freedesktop.DBus.Local Disconnected (no error name) to peer
1292: [bus\connection.c(198):bus_connection_disconnected] (inactive) disconnected, dropping all service ownership and releasing
1292: [dbus\dbus-connection.c(5526):dbus_connection_remove_filter] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(4891):dbus_connection_set_watch_functions] LOCK
1292: [dbus\dbus-watch.c(347):_dbus_watch_list_set_functions] Removing all pre-existing watches
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(4954):dbus_connection_set_timeout_functions] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(5268):dbus_connection_set_unix_user_function] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(5367):dbus_connection_set_windows_user_function] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(5037):dbus_connection_set_dispatch_status_function] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [bus\connection.c(1587):bus_connection_drop_pending_replies] Dropping pending replies that involve connection 003d88b0
1292: [dbus\dbus-connection.c(4644):dbus_connection_dispatch] LOCK
1292: [dbus\dbus-connection.c(4653):dbus_connection_dispatch] filter handled message in dispatch
1292: [dbus\dbus-connection.c(4784):dbus_connection_dispatch] ... done dispatching
1292: [dbus\dbus-connection.c(4123):_dbus_connection_release_dispatch] locking dispatch_mutex
1292: [dbus\dbus-connection.c(4131):_dbus_connection_release_dispatch] unlocking dispatch_mutex
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(4801):dbus_connection_dispatch] LOCK
1292: [dbus\dbus-connection.c(4807):dbus_connection_dispatch] before final status update
1292: [dbus\dbus-connection.c(4222):_dbus_connection_get_dispatch_status_unlocked] dispatch status = complete is_connected = 0
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(2670):_dbus_connection_last_unref] Finalizing connection 003d88b0
1292: [dbus\dbus-connection.c(5037):dbus_connection_set_dispatch_status_function] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(4991):dbus_connection_set_wakeup_main_function] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-connection.c(5268):dbus_connection_set_unix_user_function] LOCK
1292: [dbus\dbus-connection.c(413):_dbus_connection_unlock] UNLOCK
1292: [dbus\dbus-transport.c(484):_dbus_transport_unref] finalizing
1292: [dbus\dbus-transport-socket.c(106):socket_finalize]
1292: [dbus\dbus-transport-socket.c(76):free_watches] start
1292: [dbus\dbus-transport-socket.c(98):free_watches] end
1292: [dbus\dbus-auth.c(430):shutdown_mech] server: Shutting down mechanism DBUS_COOKIE_SHA1
1292: [dbus\dbus-sysdeps-win.c(1110):_dbus_poll] select: to=0
R:1944 E:1944
R:1936 E:1936
[dbus\dbus-sysdeps-win.c(1140):_dbus_poll] select: = 0
1292: [bus\connection.c(828):expire_incomplete_timeout] Running
1292: [bus\expirelist.c(111):bus_expire_timeout_set_interval] Disabled an expire timeout
1292: [dbus\dbus-sysdeps-win.c(1110):_dbus_poll] select: to=-1
R:1944 E:1944
R:1936 E:1936
[...]
我真的不知道问题出在哪里,如果有任何帮助,我将不胜感激。
编辑: 这个似乎有同样的问题:http://comments.gmane.org/gmane.comp.freedesktop.dbus/14895
【问题讨论】:
【参考方案1】:最后我解决了问题,我的服务现在可以连接到系统总线了。
我做了以下更改:
在 system.conf 中,我更改了 listen 属性和 authentication 属性:
<listen>tcp:host=localhost,port=13337,family=ipv4</listen>
<auth>ANONYMOUS</auth>
<allow_anonymous/>
根据这些变化,我类似地设置了系统环境变量:
DBUS_SYSTEM_BUS_ADDRESS = tcp:host=localhost,port=13337,family=ipv4
DBUS_SYSTEM_BUS_DEFAULT_ADDRESS = tcp:host=localhost,port=13337,family=ipv4
This 的回答让我朝着正确的方向前进。
【讨论】:
以上是关于QtService 应用程序在作为服务运行时无法连接到系统总线的主要内容,如果未能解决你的问题,请参考以下文章