[dbus] Poll on dbus connection fd
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
dfa0cbcb8d
commit
9058bd1fd3
12
awesome.c
12
awesome.c
|
@ -293,7 +293,7 @@ main(int argc, char **argv)
|
|||
{
|
||||
char buf[1024];
|
||||
const char *confpath = NULL;
|
||||
int r, xfd, csfd, i, screen_nbr, opt;
|
||||
int r, xfd, csfd, dbusfd, i, screen_nbr, opt;
|
||||
ssize_t cmdlen = 1;
|
||||
const xcb_query_extension_reply_t *shape_query, *randr_query;
|
||||
statusbar_t *statusbar;
|
||||
|
@ -494,7 +494,8 @@ main(int argc, char **argv)
|
|||
warn("error binding UNIX domain socket: %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
a_dbus_init();
|
||||
if(!a_dbus_init(&dbusfd))
|
||||
dbusfd = -1;
|
||||
|
||||
/* register function for signals */
|
||||
signal(SIGINT, &exit_on_signal);
|
||||
|
@ -511,8 +512,10 @@ main(int argc, char **argv)
|
|||
FD_ZERO(&rd);
|
||||
if(csfd >= 0)
|
||||
FD_SET(csfd, &rd);
|
||||
if(dbusfd >= 0)
|
||||
FD_SET(dbusfd, &rd);
|
||||
FD_SET(xfd, &rd);
|
||||
if(select(MAX(xfd, csfd) + 1, &rd, NULL, NULL, NULL) == -1)
|
||||
if(select(MAX(MAX(xfd, csfd), dbusfd) + 1, &rd, NULL, NULL, NULL) == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
|
@ -536,7 +539,8 @@ main(int argc, char **argv)
|
|||
layout_refresh();
|
||||
}
|
||||
|
||||
/* a_dbus_process_requests(); */
|
||||
if(dbusfd >= 0 && FD_ISSET(dbusfd, &rd))
|
||||
a_dbus_process_requests(&dbusfd);
|
||||
|
||||
/* two level XPending:
|
||||
* we need to first check we have XEvent to handle
|
||||
|
|
20
dbus.c
20
dbus.c
|
@ -32,7 +32,7 @@ a_dbus_process_widget_tell(DBusMessage *req)
|
|||
{
|
||||
char *arg, *path = NULL;
|
||||
DBusMessageIter iter;
|
||||
|
||||
|
||||
if(!dbus_message_iter_init(req, &iter))
|
||||
{
|
||||
warn("message has no argument: %s\n", err.message);
|
||||
|
@ -52,12 +52,12 @@ a_dbus_process_widget_tell(DBusMessage *req)
|
|||
}
|
||||
|
||||
void
|
||||
a_dbus_process_requests(void)
|
||||
a_dbus_process_requests(int *fd)
|
||||
{
|
||||
DBusMessage *msg;
|
||||
int nmsg = 0;
|
||||
|
||||
if(!dbus_connection && !a_dbus_init())
|
||||
if(!dbus_connection && !a_dbus_init(fd))
|
||||
return;
|
||||
|
||||
while(true)
|
||||
|
@ -87,7 +87,7 @@ a_dbus_process_requests(void)
|
|||
}
|
||||
|
||||
bool
|
||||
a_dbus_init(void)
|
||||
a_dbus_init(int *fd)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
|
@ -97,11 +97,8 @@ a_dbus_init(void)
|
|||
if(dbus_error_is_set(&err))
|
||||
{
|
||||
warn("DBus system bus connection failed: %s\n", err.message);
|
||||
|
||||
dbus_connection = NULL;
|
||||
|
||||
dbus_error_free(&err);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -112,18 +109,21 @@ a_dbus_init(void)
|
|||
if(dbus_error_is_set(&err))
|
||||
{
|
||||
warn("failed to request DBus name: %s\n", err.message);
|
||||
|
||||
a_dbus_cleanup();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
|
||||
{
|
||||
warn("not primary DBus name owner\n");
|
||||
|
||||
a_dbus_cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!dbus_connection_get_unix_fd(dbus_connection, fd))
|
||||
{
|
||||
warn("cannot get DBus connection file descriptor\n");
|
||||
a_dbus_cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue