From 3df90f24cc699e001063a27ff4c9a45376497e40 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 11 Nov 2017 21:40:20 +0900 Subject: [PATCH] core: allow to specify errno number in SystemCallErrorNumber= --- man/systemd.exec.xml | 14 +++++--------- src/core/dbus-execute.c | 6 ++---- src/core/execute.c | 15 +++++++++++---- src/core/load-fragment.c | 4 ++-- src/shared/bus-unit-util.c | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 0aaccb9..7545c75 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -1622,15 +1622,11 @@ CapabilityBoundingSet=~CAP_B CAP_C SystemCallErrorNumber= - Takes an errno error number - name to return when the system call filter configured with - SystemCallFilter= is triggered, instead of - terminating the process immediately. Takes an error name such - as EPERM, EACCES or - EUCLEAN. When this setting is not used, - or when the empty string is assigned, the process will be - terminated immediately when the filter is - triggered. + Takes an errno error number (between 1 and 4095) or errno name such as + EPERM, EACCES or EUCLEAN, to return when the + system call filter configured with SystemCallFilter= is triggered, instead of terminating + the process immediately. When this setting is not used, or when the empty string is assigned, the process + will be terminated immediately when the filter is triggered. diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index e480bac..3086161 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -1334,20 +1334,18 @@ int bus_exec_context_set_transient_property( } else if (streq(name, "SystemCallErrorNumber")) { int32_t n; - const char *str; r = sd_bus_message_read(message, "i", &n); if (r < 0) return r; - str = errno_to_name(n); - if (!str) + if (n <= 0 || n > ERRNO_MAX) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid SystemCallErrorNumber"); if (mode != UNIT_CHECK) { c->syscall_errno = n; - unit_write_drop_in_private_format(u, mode, name, "SystemCallErrorNumber=%s", str); + unit_write_drop_in_private_format(u, mode, name, "SystemCallErrorNumber=%d", n); } return 1; diff --git a/src/core/execute.c b/src/core/execute.c index fdd57cd..9f71815 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -4129,10 +4129,17 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) { prefix, s); } - if (c->syscall_errno > 0) - fprintf(f, - "%sSystemCallErrorNumber: %s\n", - prefix, strna(errno_to_name(c->syscall_errno))); + if (c->syscall_errno > 0) { + const char *errno_name; + + fprintf(f, "%sSystemCallErrorNumber: ", prefix); + + errno_name = errno_to_name(c->syscall_errno); + if (errno_name) + fprintf(f, "%s\n", errno_name); + else + fprintf(f, "%d\n", c->syscall_errno); + } if (c->apparmor_profile) fprintf(f, diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 33f8ca9..ede62e7 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -2839,8 +2839,8 @@ int config_parse_syscall_errno( return 0; } - e = errno_from_name(rvalue); - if (e < 0) { + e = parse_errno(rvalue); + if (e <= 0) { log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse error number, ignoring: %s", rvalue); return 0; } diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index b891d24..57de997 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -690,8 +690,8 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen } else if (streq(field, "SystemCallErrorNumber")) { int n; - n = errno_from_name(eq); - if (n < 0) + n = parse_errno(eq); + if (n <= 0) return log_error_errno(r, "Failed to parse %s value: %s", field, eq); r = sd_bus_message_append(m, "v", "i", (int32_t) n); -- 2.7.4