chiark / gitweb /
dbus: explicitly flush message queue before disconnecting
[elogind.git] / socket.c
index 91832128f5a9c9f83d8d8d517ac448976e9e488f..22658dcb009c3d273c418f35cfa67dcdf76c7c0c 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -35,6 +35,7 @@
 #include "load-fragment.h"
 #include "strv.h"
 #include "unit-name.h"
+#include "dbus-socket.h"
 
 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = UNIT_INACTIVE,
@@ -111,19 +112,12 @@ static void socket_init(Unit *u) {
         assert(u);
         assert(u->meta.load_state == UNIT_STUB);
 
-        s->state = 0;
         s->timer_watch.type = WATCH_INVALID;
-        s->bind_ipv6_only = false;
         s->backlog = SOMAXCONN;
         s->timeout_usec = DEFAULT_TIMEOUT_USEC;
         s->directory_mode = 0755;
         s->socket_mode = 0666;
-        s->kill_mode = 0;
-        s->failure = false;
-        s->control_pid = 0;
-        s->service = NULL;
-        s->accept = false;
-        s->n_accepted = 0;
+
         exec_context_init(&s->exec_context);
 }
 
@@ -899,13 +893,13 @@ static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
         int cfd = -1;
 
         assert(s);
+        assert(fd >= 0);
 
         log_debug("Incoming traffic on %s", u->meta.id);
 
         if (events != EPOLLIN) {
                 log_error("Got invalid poll event on socket.");
-                socket_enter_stop_pre(s, false);
-                return;
+                goto fail;
         }
 
         if (w->data.socket_accept) {
@@ -917,8 +911,7 @@ static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
                                         continue;
 
                                 log_error("Failed to accept socket: %m");
-                                socket_enter_stop_pre(s, false);
-                                return;
+                                goto fail;
                         }
 
                         break;
@@ -926,6 +919,10 @@ static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
         }
 
         socket_enter_running(s, cfd);
+        return;
+
+fail:
+        socket_enter_stop_pre(s, false);
 }
 
 static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
@@ -1102,5 +1099,7 @@ const UnitVTable socket_vtable = {
 
         .fd_event = socket_fd_event,
         .sigchld_event = socket_sigchld_event,
-        .timer_event = socket_timer_event
+        .timer_event = socket_timer_event,
+
+        .bus_message_handler = bus_socket_message_handler
 };