chiark / gitweb /
unit-printf: before resolving exec context specifiers check whether the object actual...
[elogind.git] / src / core / socket.c
index 6d417878b5e1b5c48d9b29efa4b313d5779aff9b..361404512c71701cafdc30f29d8d39c4cd642a13 100644 (file)
@@ -39,6 +39,7 @@
 #include "mkdir.h"
 #include "path-util.h"
 #include "unit-name.h"
+#include "unit-printf.h"
 #include "dbus-socket.h"
 #include "missing.h"
 #include "special.h"
@@ -374,7 +375,7 @@ static int socket_load(Unit *u) {
                         if ((r = socket_add_default_dependencies(s)) < 0)
                                 return r;
 
-                r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+                r = unit_exec_context_defaults(u, &s->exec_context);
                 if (r < 0)
                         return r;
         }
@@ -584,7 +585,7 @@ static int instance_from_socket(int fd, unsigned nr, char **instance) {
         }
 
         case AF_INET6: {
-                static const char ipv4_prefix[] = {
+                static const unsigned char ipv4_prefix[] = {
                         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF
                 };
 
@@ -1850,7 +1851,8 @@ static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
         if (w->socket_accept) {
                 for (;;) {
 
-                        if ((cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK)) < 0) {
+                        cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK);
+                        if (cfd < 0) {
 
                                 if (errno == EINTR)
                                         continue;
@@ -1884,7 +1886,7 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
 
         s->control_pid = 0;
 
-        if (is_clean_exit(code, status))
+        if (is_clean_exit(code, status, NULL))
                 f = SOCKET_SUCCESS;
         else if (code == CLD_EXITED)
                 f = SOCKET_FAILURE_EXIT_CODE;
@@ -2104,7 +2106,7 @@ static void socket_reset_failed(Unit *u) {
         s->result = SOCKET_SUCCESS;
 }
 
-static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
+static int socket_kill(Unit *u, KillWho who, int signo, DBusError *error) {
         Socket *s = SOCKET(u);
         int r = 0;
         Set *pid_set = NULL;
@@ -2126,23 +2128,25 @@ static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError
                         if (kill(s->control_pid, signo) < 0)
                                 r = -errno;
 
-        if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) {
+        if (who == KILL_ALL) {
                 int q;
 
-                if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func)))
+                pid_set = set_new(trivial_hash_func, trivial_compare_func);
+                if (!pid_set)
                         return -ENOMEM;
 
                 /* Exclude the control pid from being killed via the cgroup */
-                if (s->control_pid > 0)
-                        if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) {
+                if (s->control_pid > 0) {
+                        q = set_put(pid_set, LONG_TO_PTR(s->control_pid));
+                        if (q < 0) {
                                 r = q;
                                 goto finish;
                         }
+                }
 
                 q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, false, pid_set, NULL);
-                if (q < 0)
-                        if (q != -EAGAIN && q != -ESRCH && q != -ENOENT)
-                                r = q;
+                if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT)
+                        r = q;
         }
 
 finish:
@@ -2192,6 +2196,8 @@ DEFINE_STRING_TABLE_LOOKUP(socket_result, SocketResult);
 
 const UnitVTable socket_vtable = {
         .object_size = sizeof(Socket),
+        .exec_context_offset = offsetof(Socket, exec_context),
+
         .sections =
                 "Unit\0"
                 "Socket\0"