dbus-execute.c revision d200735e13c52dcfe36c0e066f9f6c2fbfb85a9c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include "dbus-execute.h"
#include "missing.h"
#include "ioprio.h"
#include "strv.h"
#include "dbus-common.h"
assert(i);
return -ENOMEM;
STRV_FOREACH(j, env_files) {
dbus_bool_t b = false;
char *fn = *j;
if (fn[0] == '-') {
b = true;
fn++;
}
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
ExecContext *c = data;
int32_t n;
assert(i);
assert(c);
if (c->oom_score_adjust_set)
n = c->oom_score_adjust;
else {
char *t;
n = 0;
if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0) {
safe_atoi(t, &n);
free(t);
} else if (read_one_line_file("/proc/self/oom_adj", &t) >= 0) {
safe_atoi(t, &n);
free(t);
if (n == OOM_ADJUST_MAX)
n = OOM_SCORE_ADJ_MAX;
else
n = (n * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
}
}
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
return -ENOMEM;
return 0;
}
ExecContext *c = data;
int32_t n;
assert(i);
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;
}
ExecContext *c = data;
int32_t n;
assert(i);
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;
}
ExecContext *c = data;
int32_t n;
assert(i);
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;
}
ExecContext *c = data;
int32_t n;
assert(i);
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;
}
ExecContext *c = data;
dbus_bool_t b;
assert(i);
assert(c);
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
if (!b)
return -ENOMEM;
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
ExecContext *c = data;
uint64_t u;
assert(i);
assert(c);
if (c->timer_slack_nsec_set)
u = (uint64_t) c->timer_slack_nsec;
else
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
return -ENOMEM;
return 0;
}
ExecContext *c = data;
assert(i);
assert(c);
/* We store this negated internally, to match the kernel, but
* we expose it normalized. */
}
ExecContext *c = data;
char *t = NULL;
const char *s;
dbus_bool_t b;
assert(i);
assert(c);
if (c->capabilities)
else
s = "";
if (!s)
return -ENOMEM;
b = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &s);
if (t)
cap_free(t);
if (!b)
return -ENOMEM;
return 0;
}
ExecContext *c = data;
int r;
uint64_t u;
assert(i);
assert(c);
if (c->rlimit[r])
else {
}
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
return -ENOMEM;
return 0;
}
ExecCommand *c = data;
assert(i);
return -ENOMEM;
LIST_FOREACH(command, c, c) {
char **l;
dbus_bool_t b;
if (!c->path)
continue;
return -ENOMEM;
STRV_FOREACH(l, c->argv)
return -ENOMEM;
b = !!c->ignore;
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.start_timestamp.realtime) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.start_timestamp.monotonic) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.exit_timestamp.realtime) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.exit_timestamp.monotonic) ||
return -ENOMEM;
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
const BusProperty bus_exec_context_properties[] = {
{ "EnvironmentFiles", bus_execute_append_env_files, "a(sb)", offsetof(ExecContext, environment_files), true },
{ "WorkingDirectory", bus_property_append_string, "s", offsetof(ExecContext, working_directory), true },
{ "CPUSchedulingResetOnFork", bus_property_append_bool, "b", offsetof(ExecContext, cpu_sched_reset_on_fork) },
{ "SyslogIdentifier", bus_property_append_string, "s", offsetof(ExecContext, syslog_identifier), true },
{ "CapabilityBoundingSet", bus_execute_append_capability_bs, "t", offsetof(ExecContext, capability_bounding_set_drop) },
{ "SupplementaryGroups", bus_property_append_strv, "as", offsetof(ExecContext, supplementary_groups), true },
{ "ReadWriteDirectories", bus_property_append_strv, "as", offsetof(ExecContext, read_write_dirs), true },
{ "ReadOnlyDirectories", bus_property_append_strv, "as", offsetof(ExecContext, read_only_dirs), true },
{ "InaccessibleDirectories", bus_property_append_strv, "as", offsetof(ExecContext, inaccessible_dirs), true },
{ "ControlGroupModify", bus_property_append_bool, "b", offsetof(ExecContext, control_group_modify) },
{ NULL, }
};