From a8a1357560aa6b2618dfe65674c9c9179940ef88 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sun, 11 Oct 2015 03:37:50 +0000 Subject: systemd-run: can launch units with SyslogLevel --- src/core/dbus-execute.c | 13 +++++++++++++ src/shared/bus-util.c | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 88db179958..73290002f6 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -880,6 +880,19 @@ int bus_exec_context_set_transient_property( unit_write_drop_in_private_format(u, mode, name, "SyslogIdentifier=%s\n", id); } + return 1; + } else if (streq(name, "SyslogLevel")) { + int level; + + r = sd_bus_message_read(message, "i", &level); + if (r < 0) + return r; + + if (mode != UNIT_CHECK) { + c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level; + unit_write_drop_in_private_format(u, mode, name, "SyslogLevel=%i\n", level); + } + return 1; } else if (streq(name, "Nice")) { int n; diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 65922dd93b..bf9320b0e0 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1497,7 +1497,18 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen "RootDirectory", "SyslogIdentifier")) r = sd_bus_message_append(m, "v", "s", eq); - else if (streq(field, "DeviceAllow")) { + else if (streq(field, "SyslogLevel")) { + int level; + + level = log_level_from_string(eq); + if (level < 0) { + log_error("Failed to parse %s value %s.", field, eq); + return -EINVAL; + } + + r = sd_bus_message_append(m, "v", "i", level); + + } else if (streq(field, "DeviceAllow")) { if (isempty(eq)) r = sd_bus_message_append(m, "v", "a(ss)", 0); -- cgit v1.2.3-54-g00ecf From 7135129e0aa24f6e4c36d78ccf782761c9780cad Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sun, 11 Oct 2015 03:39:46 +0000 Subject: shell-completion: systemd-run: add SyslogLevel property --- shell-completion/bash/systemd-run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run index b1387a28b6..fe1aa36ca9 100644 --- a/shell-completion/bash/systemd-run +++ b/shell-completion/bash/systemd-run @@ -83,7 +83,7 @@ _systemd_run() { LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE= LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices= PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory= - TTYPath= SyslogIdentifier= SyslogLevelPrefix=' + TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=' COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) return 0 -- cgit v1.2.3-54-g00ecf From 460ed929cf2081e5a445b9e8fedbbaf0da7eff44 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sun, 11 Oct 2015 03:55:41 +0000 Subject: systemd-run: can launch units with SyslogFacility --- src/core/dbus-execute.c | 13 +++++++++++++ src/shared/bus-util.c | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 73290002f6..b87192a9ae 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -893,6 +893,19 @@ int bus_exec_context_set_transient_property( unit_write_drop_in_private_format(u, mode, name, "SyslogLevel=%i\n", level); } + return 1; + } else if (streq(name, "SyslogFacility")) { + int facility; + + r = sd_bus_message_read(message, "i", &facility); + if (r < 0) + return r; + + if (mode != UNIT_CHECK) { + c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority); + unit_write_drop_in_private_format(u, mode, name, "SyslogFacility=%i\n", facility); + } + return 1; } else if (streq(name, "Nice")) { int n; diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index bf9320b0e0..3a45ac4064 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1508,6 +1508,17 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen r = sd_bus_message_append(m, "v", "i", level); + } else if (streq(field, "SyslogFacility")) { + int facility; + + facility = log_facility_unshifted_from_string(eq); + if (facility < 0) { + log_error("Failed to parse %s value %s.", field, eq); + return -EINVAL; + } + + r = sd_bus_message_append(m, "v", "i", facility); + } else if (streq(field, "DeviceAllow")) { if (isempty(eq)) -- cgit v1.2.3-54-g00ecf From 75d73dc9d08c39ca5e413e4045daf1de61ea7ee6 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sun, 11 Oct 2015 03:57:07 +0000 Subject: shell-completion: systemd-run: add SyslogFacility property --- shell-completion/bash/systemd-run | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run index fe1aa36ca9..462ee33959 100644 --- a/shell-completion/bash/systemd-run +++ b/shell-completion/bash/systemd-run @@ -83,7 +83,8 @@ _systemd_run() { LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE= LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices= PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory= - TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=' + TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel= + SyslogFacility=' COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) return 0 -- cgit v1.2.3-54-g00ecf From adb8ec96f2918fa7b39722ead6b2fe949fc3a7c5 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Wed, 14 Oct 2015 16:28:40 +0000 Subject: util: add functions for validating syslog level and facility --- src/basic/util.c | 8 ++++++++ src/basic/util.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/basic/util.c b/src/basic/util.c index ca5e4befa0..8b896a2df3 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -3699,6 +3699,10 @@ static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = { DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0)); +bool log_facility_unshifted_is_valid(int facility) { + return facility >= 0 && facility <= LOG_FAC(~0); +} + static const char *const log_level_table[] = { [LOG_EMERG] = "emerg", [LOG_ALERT] = "alert", @@ -3712,6 +3716,10 @@ static const char *const log_level_table[] = { DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG); +bool log_level_is_valid(int level) { + return level >= 0 && level <= LOG_DEBUG; +} + static const char* const sched_policy_table[] = { [SCHED_OTHER] = "other", [SCHED_BATCH] = "batch", diff --git a/src/basic/util.h b/src/basic/util.h index 79c7ad1b39..2544ad0830 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -456,9 +456,11 @@ int sigchld_code_from_string(const char *s) _pure_; int log_facility_unshifted_to_string_alloc(int i, char **s); int log_facility_unshifted_from_string(const char *s); +bool log_facility_unshifted_is_valid(int faciliy); int log_level_to_string_alloc(int i, char **s); int log_level_from_string(const char *s); +bool log_level_is_valid(int level); int sched_policy_to_string_alloc(int i, char **s); int sched_policy_from_string(const char *s); -- cgit v1.2.3-54-g00ecf From e0d6e0fa55054b7eacf58c511abff710fef5712f Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Wed, 14 Oct 2015 16:30:35 +0000 Subject: core: execute: validate syslog level and facility --- src/core/dbus-execute.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index b87192a9ae..8b1f830476 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -888,6 +888,9 @@ int bus_exec_context_set_transient_property( if (r < 0) return r; + if (!log_level_is_valid(level)) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range"); + if (mode != UNIT_CHECK) { c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level; unit_write_drop_in_private_format(u, mode, name, "SyslogLevel=%i\n", level); @@ -901,6 +904,9 @@ int bus_exec_context_set_transient_property( if (r < 0) return r; + if (!log_facility_unshifted_is_valid(facility)) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range"); + if (mode != UNIT_CHECK) { c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority); unit_write_drop_in_private_format(u, mode, name, "SyslogFacility=%i\n", facility); -- cgit v1.2.3-54-g00ecf