chiark / gitweb /
Set $NOTIFY_SOCKET for control procs if NotifyAccess=all
[elogind.git] / src / core / service.c
index 3f6595c5c820fd184a84e13ff4af4eebaec913d9..76763441b089b07776a5dabafb026778103879a8 100644 (file)
@@ -883,7 +883,6 @@ static int service_spawn(
                 bool apply_permissions,
                 bool apply_chroot,
                 bool apply_tty_stdin,
-                bool set_notify_socket,
                 bool is_control,
                 pid_t *_pid) {
 
@@ -901,6 +900,7 @@ static int service_spawn(
                 .apply_chroot      = apply_chroot,
                 .apply_tty_stdin   = apply_tty_stdin,
                 .bus_endpoint_fd   = -1,
+                .selinux_context_net = s->socket_fd_selinux_context_net
         };
 
         assert(s);
@@ -947,7 +947,7 @@ static int service_spawn(
                 goto fail;
         }
 
-        if (set_notify_socket)
+        if (is_control ? s->notify_access == NOTIFY_ALL : s->notify_access != NOTIFY_NONE)
                 if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=%s", UNIT(s)->manager->notify_socket) < 0) {
                         r = -ENOMEM;
                         goto fail;
@@ -1152,7 +1152,6 @@ static void service_enter_stop_post(Service *s, ServiceResult f) {
                                   !s->permissions_start_only,
                                   !s->root_directory_start_only,
                                   true,
-                                  false,
                                   true,
                                   &s->control_pid);
                 if (r < 0)
@@ -1226,7 +1225,8 @@ static void service_enter_stop_by_notify(Service *s) {
         if (s->timeout_stop_usec > 0)
                 service_arm_timer(s, s->timeout_stop_usec);
 
-        service_set_state(s, SERVICE_STOP);
+        /* The service told us it's stopping, so it's as if we SIGTERM'd it. */
+        service_set_state(s, SERVICE_STOP_SIGTERM);
 }
 
 static void service_enter_stop(Service *s, ServiceResult f) {
@@ -1251,7 +1251,6 @@ static void service_enter_stop(Service *s, ServiceResult f) {
                                   !s->permissions_start_only,
                                   !s->root_directory_start_only,
                                   false,
-                                  false,
                                   true,
                                   &s->control_pid);
                 if (r < 0)
@@ -1314,7 +1313,6 @@ static void service_enter_start_post(Service *s) {
                                   !s->permissions_start_only,
                                   !s->root_directory_start_only,
                                   false,
-                                  false,
                                   true,
                                   &s->control_pid);
                 if (r < 0)
@@ -1381,7 +1379,6 @@ static void service_enter_start(Service *s) {
                           true,
                           true,
                           true,
-                          s->notify_access != NOTIFY_NONE,
                           false,
                           &pid);
         if (r < 0)
@@ -1447,7 +1444,6 @@ static void service_enter_start_pre(Service *s) {
                                   !s->permissions_start_only,
                                   !s->root_directory_start_only,
                                   true,
-                                  false,
                                   true,
                                   &s->control_pid);
                 if (r < 0)
@@ -1528,7 +1524,6 @@ static void service_enter_reload(Service *s) {
                                   !s->permissions_start_only,
                                   !s->root_directory_start_only,
                                   false,
-                                  false,
                                   true,
                                   &s->control_pid);
                 if (r < 0)
@@ -1566,7 +1561,6 @@ static void service_run_next_control(Service *s) {
                           !s->root_directory_start_only,
                           s->control_command_id == SERVICE_EXEC_START_PRE ||
                           s->control_command_id == SERVICE_EXEC_STOP_POST,
-                          false,
                           true,
                           &s->control_pid);
         if (r < 0)
@@ -1609,7 +1603,6 @@ static void service_run_next_main(Service *s) {
                           true,
                           true,
                           true,
-                          s->notify_access != NOTIFY_NONE,
                           false,
                           &pid);
         if (r < 0)
@@ -2748,7 +2741,7 @@ static void service_bus_name_owner_change(
         }
 }
 
-int service_set_socket_fd(Service *s, int fd, Socket *sock) {
+int service_set_socket_fd(Service *s, int fd, Socket *sock, bool selinux_context_net) {
         _cleanup_free_ char *peer = NULL;
         int r;
 
@@ -2786,6 +2779,7 @@ int service_set_socket_fd(Service *s, int fd, Socket *sock) {
         }
 
         s->socket_fd = fd;
+        s->socket_fd_selinux_context_net = selinux_context_net;
 
         unit_ref_set(&s->accept_socket, UNIT(sock));