From: Yu Watanabe Date: Sat, 11 Nov 2017 12:40:20 +0000 (+0900) Subject: core: allow to specify errno number in SystemCallErrorNumber= X-Git-Tag: v236~238^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3df90f24cc699e001063a27ff4c9a45376497e40;p=thirdparty%2Fsystemd.git core: allow to specify errno number in SystemCallErrorNumber= --- diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 0aaccb9298b..7545c75d770 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 e480bacdcb2..30861617bd4 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 fdd57cd0051..9f7181549e7 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 33f8ca98b40..ede62e7b3d0 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 b891d246532..57de9975c79 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);