dbus_bool_t _dbus_loop_iterate (DBusLoop *loop, dbus_bool_t block) { #define N_STACK_DESCRIPTORS 64 dbus_bool_t retval; DBusPollFD *fds; DBusPollFD stack_fds[N_STACK_DESCRIPTORS]; int n_fds; WatchCallback **watches_for_fds; WatchCallback *stack_watches_for_fds[N_STACK_DESCRIPTORS]; int i; DBusList *link; int n_ready; int initial_serial; long timeout; dbus_bool_t oom_watch_pending; int orig_depth; retval = FALSE; fds = NULL; watches_for_fds = NULL; n_fds = 0; oom_watch_pending = FALSE; orig_depth = loop->depth; #if MAINLOOP_SPEW _dbus_verbose ("Iteration block=%d depth=%d timeout_count=%d watch_count=%d\n", block, loop->depth, loop->timeout_count, loop->watch_count); #endif if (loop->callbacks == NULL) goto next_iteration; if (loop->watch_count > N_STACK_DESCRIPTORS) { fds = dbus_new0 (DBusPollFD, loop->watch_count); while (fds == NULL) { _dbus_wait_for_memory (); fds = dbus_new0 (DBusPollFD, loop->watch_count); } watches_for_fds = dbus_new (WatchCallback*, loop->watch_count); while (watches_for_fds == NULL) { _dbus_wait_for_memory (); watches_for_fds = dbus_new (WatchCallback*, loop->watch_count); } }
dbus_bool_t bus_connection_dispatch_one_message (DBusConnection *connection) { DBusDispatchStatus status; while ((status = dbus_connection_dispatch (connection)) == DBUS_DISPATCH_NEED_MEMORY) _dbus_wait_for_memory (); return status == DBUS_DISPATCH_DATA_REMAINS; }
static void dispatch_status_function (DBusConnection *connection, DBusDispatchStatus new_status, void *data) { DBusLoop *loop = data; if (new_status != DBUS_DISPATCH_COMPLETE) { while (!_dbus_loop_queue_dispatch (loop, connection)) _dbus_wait_for_memory (); } }
dbus_bool_t _dbus_loop_dispatch (DBusLoop *loop) { #if MAINLOOP_SPEW _dbus_verbose (" %d connections to dispatch\n", _dbus_list_get_length (&loop->need_dispatch)); #endif if (loop->need_dispatch == NULL) return FALSE; next: while (loop->need_dispatch != NULL) { DBusConnection *connection = _dbus_list_pop_first (&loop->need_dispatch); while (TRUE) { DBusDispatchStatus status; status = dbus_connection_dispatch (connection); if (status == DBUS_DISPATCH_COMPLETE) { dbus_connection_unref (connection); goto next; } else { if (status == DBUS_DISPATCH_NEED_MEMORY) _dbus_wait_for_memory (); } } } return TRUE; }
static dbus_bool_t handle_reload_watch (DBusWatch *watch, unsigned int flags, void *data) { DBusError error; DBusString str; while (!_dbus_string_init (&str)) _dbus_wait_for_memory (); if ((reload_pipe[RELOAD_READ_END] > 0) && _dbus_read_socket (reload_pipe[RELOAD_READ_END], &str, 1) != 1) { _dbus_warn ("Couldn't read from reload pipe.\n"); close_reload_pipe (); return TRUE; } _dbus_string_free (&str); /* this can only fail if we don't understand the config file * or OOM. Either way we should just stick with the currently * loaded config. */ dbus_error_init (&error); if (! bus_context_reload_config (context, &error)) { _DBUS_ASSERT_ERROR_IS_SET (&error); _dbus_assert (dbus_error_has_name (&error, DBUS_ERROR_FAILED) || dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)); _dbus_warn ("Unable to reload configuration: %s\n", error.message); dbus_error_free (&error); } return TRUE; }
static dbus_bool_t handle_reload_watch (DBusWatch *watch, unsigned int flags, void *data) { DBusError error; DBusString str; char *action_str; char action = '\0'; while (!_dbus_string_init (&str)) _dbus_wait_for_memory (); if ((reload_pipe[RELOAD_READ_END] > 0) && _dbus_read_socket (reload_pipe[RELOAD_READ_END], &str, 1) != 1) { _dbus_warn ("Couldn't read from reload pipe.\n"); close_reload_pipe (&watch); return TRUE; } action_str = _dbus_string_get_data (&str); if (action_str != NULL) { action = action_str[0]; } _dbus_string_free (&str); /* this can only fail if we don't understand the config file * or OOM. Either way we should just stick with the currently * loaded config. */ dbus_error_init (&error); switch (action) { case ACTION_RELOAD: if (! bus_context_reload_config (context, &error)) { _DBUS_ASSERT_ERROR_IS_SET (&error); _dbus_assert (dbus_error_has_name (&error, DBUS_ERROR_FAILED) || dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)); _dbus_warn ("Unable to reload configuration: %s\n", error.message); dbus_error_free (&error); } break; case ACTION_QUIT: { DBusLoop *loop; /* * On OSs without abstract sockets, we want to quit * gracefully rather than being killed by SIGTERM, * so that DBusServer gets a chance to clean up the * sockets from the filesystem. fd.o #38656 */ loop = bus_context_get_loop (context); if (loop != NULL) { _dbus_loop_quit (loop); } } break; default: break; } return TRUE; }