Skip to content

Commit 3fc75e5

Browse files
service: new NotifyAccess= value for control processes (#4212)
Setting NotifyAccess=exec allows notifications coming directly from any control process.
1 parent e438663 commit 3fc75e5

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

man/systemd.service.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,14 @@
798798
notification socket, as accessible via the
799799
<citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
800800
call. Takes one of <option>none</option> (the default),
801-
<option>main</option> or <option>all</option>. If
802-
<option>none</option>, no daemon status updates are accepted
803-
from the service processes, all status update messages are
804-
ignored. If <option>main</option>, only service updates sent
805-
from the main process of the service are accepted. If
801+
<option>main</option>, <option>exec</option> or
802+
<option>all</option>. If <option>none</option>, no daemon status
803+
updates are accepted from the service processes, all status
804+
update messages are ignored. If <option>main</option>, only
805+
service updates sent from the main process of the service are
806+
accepted. If <option>exec</option>, only service updates sent
807+
from any of the control processes originating from one of the
808+
<varname>Exec*=</varname> commands are accepted. If
806809
<option>all</option>, all services updates from all members of
807810
the service's control group are accepted. This option should
808811
be set to open access to the notification socket when using

src/core/service.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,8 @@ static int service_spawn(
12521252
if (!our_env)
12531253
return -ENOMEM;
12541254

1255-
if ((flags & EXEC_IS_CONTROL) ? s->notify_access == NOTIFY_ALL : s->notify_access != NOTIFY_NONE)
1255+
if ((flags & EXEC_IS_CONTROL) ? IN_SET(s->notify_access, NOTIFY_ALL, NOTIFY_EXEC)
1256+
: s->notify_access != NOTIFY_NONE)
12561257
if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=%s", UNIT(s)->manager->notify_socket) < 0)
12571258
return -ENOMEM;
12581259

@@ -3059,6 +3060,16 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds)
30593060
else
30603061
log_unit_debug(u, "Got notification message from PID "PID_FMT", but reception only permitted for main PID which is currently not known", pid);
30613062
return;
3063+
} else if (s->notify_access == NOTIFY_EXEC && pid != s->main_pid && pid != s->control_pid) {
3064+
if (s->main_pid != 0 && s->control_pid != 0)
3065+
log_unit_warning(u, "Got notification message from PID "PID_FMT", but reception only permitted for main PID "PID_FMT" and control PID "PID_FMT,
3066+
pid, s->main_pid, s->control_pid);
3067+
else if (s->main_pid != 0 || s->control_pid != 0)
3068+
log_unit_warning(u, "Got notification message from PID "PID_FMT", but reception only permitted for %s PID "PID_FMT,
3069+
pid, s->main_pid ? "main" : "control", s->main_pid | s->control_pid);
3070+
else
3071+
log_unit_debug(u, "Got notification message from PID "PID_FMT", but reception only permitted for main PID and control PID which are currently not known", pid);
3072+
return;
30623073
} else
30633074
log_unit_debug(u, "Got notification message from PID "PID_FMT" (%s)", pid, isempty(cc) ? "n/a" : cc);
30643075

@@ -3384,6 +3395,7 @@ DEFINE_STRING_TABLE_LOOKUP(service_exec_command, ServiceExecCommand);
33843395
static const char* const notify_access_table[_NOTIFY_ACCESS_MAX] = {
33853396
[NOTIFY_NONE] = "none",
33863397
[NOTIFY_MAIN] = "main",
3398+
[NOTIFY_EXEC] = "exec",
33873399
[NOTIFY_ALL] = "all"
33883400
};
33893401

src/core/service.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef enum NotifyAccess {
6565
NOTIFY_NONE,
6666
NOTIFY_ALL,
6767
NOTIFY_MAIN,
68+
NOTIFY_EXEC,
6869
_NOTIFY_ACCESS_MAX,
6970
_NOTIFY_ACCESS_INVALID = -1
7071
} NotifyAccess;

0 commit comments

Comments
 (0)