core: allow to specify errno number in SystemCallErrorNumber=

This commit is contained in:
Yu Watanabe 2017-11-11 21:40:20 +09:00
parent b4891260b9
commit 3df90f24cc
5 changed files with 22 additions and 21 deletions

View file

@ -1622,15 +1622,11 @@ CapabilityBoundingSet=~CAP_B CAP_C</programlisting>
<varlistentry>
<term><varname>SystemCallErrorNumber=</varname></term>
<listitem><para>Takes an <literal>errno</literal> error number
name to return when the system call filter configured with
<varname>SystemCallFilter=</varname> is triggered, instead of
terminating the process immediately. Takes an error name such
as <constant>EPERM</constant>, <constant>EACCES</constant> or
<constant>EUCLEAN</constant>. When this setting is not used,
or when the empty string is assigned, the process will be
terminated immediately when the filter is
triggered.</para></listitem>
<listitem><para>Takes an <literal>errno</literal> error number (between 1 and 4095) or errno name such as
<constant>EPERM</constant>, <constant>EACCES</constant> or <constant>EUCLEAN</constant>, to return when the
system call filter configured with <varname>SystemCallFilter=</varname> 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.</para></listitem>
</varlistentry>
<varlistentry>

View file

@ -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;

View file

@ -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,

View file

@ -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;
}

View file

@ -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);