summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-19 19:02:47 +0200
committerLennart Poettering <lennart@poettering.net>2015-10-19 19:02:47 +0200
commitaa486a72be9903daf870b050616769d1b4e78a33 (patch)
tree6561f4ea355882a41dbc4267c652a27dd85c5586
parent9badb85de0821c98c7adf5dc90b2ba590987dbb5 (diff)
parente9cc999a306a789049304997f855dec2eabe5579 (diff)
Merge pull request #1598 from evverx/run-oomscoreadjust
systemd-run can launch units with OOMScoreAdjust
-rw-r--r--shell-completion/bash/systemd-run2
-rw-r--r--src/basic/util.c5
-rw-r--r--src/basic/util.h2
-rw-r--r--src/core/dbus-execute.c18
-rw-r--r--src/shared/bus-util.c15
5 files changed, 41 insertions, 1 deletions
diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run
index 518812e040..ea59a42407 100644
--- a/shell-completion/bash/systemd-run
+++ b/shell-completion/bash/systemd-run
@@ -84,7 +84,7 @@ _systemd_run() {
LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices=
PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory=
TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=
- SyslogFacility= TimerSlackNSec='
+ SyslogFacility= TimerSlackNSec= OOMScoreAdjust='
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
diff --git a/src/basic/util.c b/src/basic/util.c
index 8b896a2df3..2565b0f547 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -29,6 +29,7 @@
#include <libintl.h>
#include <limits.h>
#include <linux/magic.h>
+#include <linux/oom.h>
#include <linux/sched.h>
#include <locale.h>
#include <netinet/ip.h>
@@ -6800,3 +6801,7 @@ bool fdname_is_valid(const char *s) {
return p - s < 256;
}
+
+bool oom_score_adjust_is_valid(int oa) {
+ return oa >= OOM_SCORE_ADJ_MIN && oa <= OOM_SCORE_ADJ_MAX;
+}
diff --git a/src/basic/util.h b/src/basic/util.h
index 2544ad0830..6c63bc221f 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -941,3 +941,5 @@ void nop_signal_handler(int sig);
int version(void);
bool fdname_is_valid(const char *s);
+
+bool oom_score_adjust_is_valid(int oa);
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index 436229330e..2662b07525 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -1186,6 +1186,24 @@ int bus_exec_context_set_transient_property(
return 1;
+ } else if (streq(name, "OOMScoreAdjust")) {
+ int oa;
+
+ r = sd_bus_message_read(message, "i", &oa);
+ if (r < 0)
+ return r;
+
+ if (!oom_score_adjust_is_valid(oa))
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
+
+ if (mode != UNIT_CHECK) {
+ c->oom_score_adjust = oa;
+ c->oom_score_adjust_set = true;
+ unit_write_drop_in_private_format(u, mode, name, "OOMScoreAdjust=%i\n", oa);
+ }
+
+ return 1;
+
} else if (rlimit_from_string(name) >= 0) {
uint64_t rl;
rlim_t x;
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index a5d6edbba9..78d6b0eb27 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -1665,6 +1665,21 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
}
r = sd_bus_message_append(m, "v", "t", n);
+ } else if (streq(field, "OOMScoreAdjust")) {
+ int oa;
+
+ r = safe_atoi(eq, &oa);
+ if (r < 0) {
+ log_error("Failed to parse %s value %s", field, eq);
+ return -EINVAL;
+ }
+
+ if (!oom_score_adjust_is_valid(oa)) {
+ log_error("OOM score adjust value out of range");
+ return -EINVAL;
+ }
+
+ r = sd_bus_message_append(m, "v", "i", oa);
} else {
log_error("Unknown assignment %s.", assignment);
return -EINVAL;