1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include <dbus/dbus.h>
24 #include <sys/prctl.h>
26 #include "dbus-execute.h"
30 DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput);
31 DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput);
33 int bus_execute_append_oom_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data) {
34 ExecContext *c = data;
42 if (c->oom_adjust_set)
48 if (read_one_line_file("/proc/self/oom_adj", &t) >= 0) {
54 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
60 int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property, void *data) {
61 ExecContext *c = data;
72 n = getpriority(PRIO_PROCESS, 0);
74 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
80 int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *property, void *data) {
81 ExecContext *c = data;
92 n = ioprio_get(IOPRIO_WHO_PROCESS, 0);
94 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
100 int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data) {
101 ExecContext *c = data;
109 if (c->cpu_sched_set)
110 n = c->cpu_sched_policy;
112 n = sched_getscheduler(0);
114 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
120 int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) {
121 ExecContext *c = data;
129 if (c->cpu_sched_set)
130 n = c->cpu_sched_priority;
132 struct sched_param p;
136 if (sched_getparam(0, &p) >= 0)
137 n = p.sched_priority;
140 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
146 int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *property, void *data) {
147 ExecContext *c = data;
156 if (!(dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "y", &sub)))
160 b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus));
162 b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &c->cpuset, 0);
167 if (!dbus_message_iter_close_container(i, &sub))
173 int bus_execute_append_timer_slack_ns(Manager *m, DBusMessageIter *i, const char *property, void *data) {
174 ExecContext *c = data;
182 if (c->timer_slack_ns_set)
183 u = (uint64_t) c->timer_slack_ns_set;
185 u = (uint64_t) prctl(PR_GET_TIMERSLACK);
187 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
193 int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *property, void *data) {
194 ExecContext *c = data;
205 s = t = cap_to_text(c->capabilities, NULL);
212 b = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &s);
221 int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data) {
222 ExecContext *c = data;
231 assert_se((r = rlimit_from_string(property)) >= 0);
234 u = (uint64_t) c->rlimit[r]->rlim_max;
241 u = (uint64_t) rl.rlim_max;
244 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))