diff options
Diffstat (limited to 'src/dbus-execute.c')
-rw-r--r-- | src/dbus-execute.c | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/src/dbus-execute.c b/src/dbus-execute.c index 8840396bc1..a41b63992b 100644 --- a/src/dbus-execute.c +++ b/src/dbus-execute.c @@ -21,8 +21,228 @@ #include <errno.h> #include <dbus/dbus.h> +#include <sys/prctl.h> #include "dbus-execute.h" +#include "missing.h" +#include "ioprio.h" DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput); DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput); + +int bus_execute_append_oom_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + int32_t n; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (c->oom_adjust_set) + n = c->oom_adjust; + else { + char *t; + + n = 0; + if (read_one_line_file("/proc/self/oom_adj", &t) >= 0) { + safe_atoi(t, &n); + free(t); + } + } + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n)) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + int32_t n; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (c->nice_set) + n = c->nice; + else + n = getpriority(PRIO_PROCESS, 0); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n)) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + int32_t n; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (c->ioprio_set) + n = c->ioprio; + else + n = ioprio_get(IOPRIO_WHO_PROCESS, 0); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n)) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + int32_t n; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (c->cpu_sched_set) + n = c->cpu_sched_policy; + else + n = sched_getscheduler(0); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n)) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + int32_t n; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (c->cpu_sched_set) + n = c->cpu_sched_priority; + else { + struct sched_param p; + n = 0; + + zero(p); + if (sched_getparam(0, &p) >= 0) + n = p.sched_priority; + } + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n)) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + dbus_bool_t b; + DBusMessageIter sub; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (!(dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "y", &sub))) + return -ENOMEM; + + if (c->cpuset) + b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus)); + else + b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &c->cpuset, 0); + + if (!b) + return -ENOMEM; + + if (!dbus_message_iter_close_container(i, &sub)) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_timer_slack_ns(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + uint64_t u; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (c->timer_slack_ns_set) + u = (uint64_t) c->timer_slack_ns_set; + else + u = (uint64_t) prctl(PR_GET_TIMERSLACK); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u)) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + char *t = NULL; + const char *s; + dbus_bool_t b; + + assert(m); + assert(i); + assert(property); + assert(c); + + if (c->capabilities) + s = t = cap_to_text(c->capabilities, NULL); + else + s = ""; + + if (!t) + return -ENOMEM; + + b = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &s); + cap_free(t); + + if (!b) + return -ENOMEM; + + return 0; +} + +int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data) { + ExecContext *c = data; + int r; + uint64_t u; + + assert(m); + assert(i); + assert(property); + assert(c); + + assert_se((r = rlimit_from_string(property)) >= 0); + + if (c->rlimit[r]) + u = (uint64_t) c->rlimit[r]->rlim_max; + else { + struct rlimit rl; + + zero(rl); + getrlimit(r, &rl); + + u = (uint64_t) rl.rlim_max; + } + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u)) + return -ENOMEM; + + return 0; +} |