2010-08-14 19:59:25 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
2010-04-18 03:08:16 +02:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2010 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2010-04-18 03:08:16 +02:00
|
|
|
(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
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2010-04-18 03:08:16 +02:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2010-04-18 03:08:16 +02:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2010-07-04 16:44:58 +02:00
|
|
|
#include <sys/prctl.h>
|
2010-04-18 03:08:16 +02:00
|
|
|
|
2014-02-13 00:24:00 +01:00
|
|
|
#ifdef HAVE_SECCOMP
|
|
|
|
#include <seccomp.h>
|
|
|
|
#endif
|
|
|
|
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "af-list.h"
|
2013-11-19 21:12:59 +01:00
|
|
|
#include "bus-util.h"
|
2014-01-01 04:35:54 +01:00
|
|
|
#include "capability.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "dbus-execute.h"
|
2014-02-05 02:02:00 +01:00
|
|
|
#include "env-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "execute.h"
|
|
|
|
#include "fd-util.h"
|
|
|
|
#include "fileio.h"
|
|
|
|
#include "ioprio.h"
|
|
|
|
#include "missing.h"
|
2014-06-03 23:41:44 +02:00
|
|
|
#include "namespace.h"
|
2015-10-26 16:18:16 +01:00
|
|
|
#include "parse-util.h"
|
2014-12-22 19:45:32 +01:00
|
|
|
#include "path-util.h"
|
2015-10-26 19:40:43 +01:00
|
|
|
#include "rlimit-util.h"
|
2014-02-13 00:24:00 +01:00
|
|
|
#ifdef HAVE_SECCOMP
|
|
|
|
#include "seccomp-util.h"
|
|
|
|
#endif
|
2015-10-26 16:18:16 +01:00
|
|
|
#include "strv.h"
|
|
|
|
#include "utf8.h"
|
2014-02-13 00:24:00 +01:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput);
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput);
|
2011-03-04 03:44:43 +01:00
|
|
|
|
2015-08-23 13:14:04 +02:00
|
|
|
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
|
|
|
|
|
2014-06-04 18:07:55 +02:00
|
|
|
static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_home, protect_home, ProtectHome);
|
|
|
|
static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_system, protect_system, ProtectSystem);
|
2014-06-03 23:41:44 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_environment_files(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2011-03-04 03:44:43 +01:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
ExecContext *c = userdata;
|
|
|
|
char **j;
|
|
|
|
int r;
|
2011-03-04 03:44:43 +01:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
r = sd_bus_message_open_container(reply, 'a', "(sb)");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-03-04 03:44:43 +01:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
STRV_FOREACH(j, c->environment_files) {
|
|
|
|
const char *fn = *j;
|
2011-03-04 03:44:43 +01:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-');
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-03-04 03:44:43 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_close_container(reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int property_get_oom_score_adjust(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
int32_t n;
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 16:44:58 +02:00
|
|
|
assert(c);
|
|
|
|
|
2010-08-31 01:33:39 +02:00
|
|
|
if (c->oom_score_adjust_set)
|
|
|
|
n = c->oom_score_adjust;
|
2010-07-04 16:44:58 +02:00
|
|
|
else {
|
2013-07-25 17:36:01 +02:00
|
|
|
_cleanup_free_ char *t = NULL;
|
2010-07-04 16:44:58 +02:00
|
|
|
|
|
|
|
n = 0;
|
2013-11-19 21:12:59 +01:00
|
|
|
if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0)
|
2015-10-26 16:41:43 +01:00
|
|
|
safe_atoi32(t, &n);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append(reply, "i", n);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_nice(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
int32_t n;
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 16:44:58 +02:00
|
|
|
assert(c);
|
|
|
|
|
|
|
|
if (c->nice_set)
|
|
|
|
n = c->nice;
|
2013-11-19 21:12:59 +01:00
|
|
|
else {
|
|
|
|
errno = 0;
|
2010-07-04 16:44:58 +02:00
|
|
|
n = getpriority(PRIO_PROCESS, 0);
|
2013-11-19 21:12:59 +01:00
|
|
|
if (errno != 0)
|
|
|
|
n = 0;
|
|
|
|
}
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append(reply, "i", n);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_ioprio(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
int32_t n;
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 16:44:58 +02:00
|
|
|
assert(c);
|
|
|
|
|
|
|
|
if (c->ioprio_set)
|
|
|
|
n = c->ioprio;
|
2013-11-19 21:12:59 +01:00
|
|
|
else {
|
2010-07-04 16:44:58 +02:00
|
|
|
n = ioprio_get(IOPRIO_WHO_PROCESS, 0);
|
2013-11-19 21:12:59 +01:00
|
|
|
if (n < 0)
|
|
|
|
n = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 4);
|
|
|
|
}
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append(reply, "i", n);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_cpu_sched_policy(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
int32_t n;
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 16:44:58 +02:00
|
|
|
assert(c);
|
|
|
|
|
|
|
|
if (c->cpu_sched_set)
|
|
|
|
n = c->cpu_sched_policy;
|
2013-11-19 21:12:59 +01:00
|
|
|
else {
|
2010-07-04 16:44:58 +02:00
|
|
|
n = sched_getscheduler(0);
|
2013-11-19 21:12:59 +01:00
|
|
|
if (n < 0)
|
|
|
|
n = SCHED_OTHER;
|
|
|
|
}
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append(reply, "i", n);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_cpu_sched_priority(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
int32_t n;
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 16:44:58 +02:00
|
|
|
assert(c);
|
|
|
|
|
|
|
|
if (c->cpu_sched_set)
|
|
|
|
n = c->cpu_sched_priority;
|
|
|
|
else {
|
2013-03-25 00:59:00 +01:00
|
|
|
struct sched_param p = {};
|
2010-07-04 16:44:58 +02:00
|
|
|
|
|
|
|
if (sched_getparam(0, &p) >= 0)
|
|
|
|
n = p.sched_priority;
|
2013-03-25 00:45:16 +01:00
|
|
|
else
|
|
|
|
n = 0;
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append(reply, "i", n);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_cpu_affinity(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
2010-07-04 16:44:58 +02:00
|
|
|
|
|
|
|
if (c->cpuset)
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append_array(reply, 'y', c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus));
|
2010-07-04 16:44:58 +02:00
|
|
|
else
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append_array(reply, 'y', NULL, 0);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_timer_slack_nsec(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
uint64_t u;
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 16:44:58 +02:00
|
|
|
assert(c);
|
|
|
|
|
2014-07-29 12:23:31 +02:00
|
|
|
if (c->timer_slack_nsec != NSEC_INFINITY)
|
2010-07-04 21:12:10 +02:00
|
|
|
u = (uint64_t) c->timer_slack_nsec;
|
2010-07-04 16:44:58 +02:00
|
|
|
else
|
|
|
|
u = (uint64_t) prctl(PR_GET_TIMERSLACK);
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append(reply, "t", u);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_capability_bounding_set(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2011-03-18 03:13:15 +01:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
ExecContext *c = userdata;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2011-03-18 03:13:15 +01:00
|
|
|
assert(c);
|
|
|
|
|
2011-06-15 10:16:49 +02:00
|
|
|
/* We store this negated internally, to match the kernel, but
|
2011-03-18 03:13:15 +01:00
|
|
|
* we expose it normalized. */
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_append(reply, "t", ~c->capability_bounding_set_drop);
|
2011-03-18 03:13:15 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_capabilities(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
2014-01-01 04:35:54 +01:00
|
|
|
_cleanup_cap_free_charp_ char *t = NULL;
|
2010-07-04 16:44:58 +02:00
|
|
|
const char *s;
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 16:44:58 +02:00
|
|
|
assert(c);
|
|
|
|
|
|
|
|
if (c->capabilities)
|
|
|
|
s = t = cap_to_text(c->capabilities, NULL);
|
|
|
|
else
|
|
|
|
s = "";
|
|
|
|
|
2010-08-12 01:01:55 +02:00
|
|
|
if (!s)
|
2010-07-04 16:44:58 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-01-01 04:35:54 +01:00
|
|
|
return sd_bus_message_append(reply, "s", s);
|
2010-07-04 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
static int property_get_syscall_filter(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2014-02-12 18:28:21 +01:00
|
|
|
ExecContext *c = userdata;
|
|
|
|
_cleanup_strv_free_ char **l = NULL;
|
2014-02-13 00:24:00 +01:00
|
|
|
int r;
|
|
|
|
|
2014-02-12 18:44:40 +01:00
|
|
|
#ifdef HAVE_SECCOMP
|
2014-02-12 18:28:21 +01:00
|
|
|
Iterator i;
|
|
|
|
void *id;
|
2014-02-12 18:44:40 +01:00
|
|
|
#endif
|
2014-02-12 18:28:21 +01:00
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
2014-02-13 00:24:00 +01:00
|
|
|
r = sd_bus_message_open_container(reply, 'r', "bas");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_bus_message_append(reply, "b", c->syscall_whitelist);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2014-02-12 18:44:40 +01:00
|
|
|
#ifdef HAVE_SECCOMP
|
2014-02-12 18:28:21 +01:00
|
|
|
SET_FOREACH(id, c->syscall_filter, i) {
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1);
|
|
|
|
if (!name)
|
|
|
|
continue;
|
|
|
|
|
2014-03-04 15:20:51 +01:00
|
|
|
r = strv_consume(&l, name);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-02-12 18:28:21 +01:00
|
|
|
}
|
2014-02-12 18:44:40 +01:00
|
|
|
#endif
|
2014-02-12 18:28:21 +01:00
|
|
|
|
|
|
|
strv_sort(l);
|
|
|
|
|
2014-02-13 00:24:00 +01:00
|
|
|
r = sd_bus_message_append_strv(reply, l);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-02-12 18:28:21 +01:00
|
|
|
|
2014-02-13 00:24:00 +01:00
|
|
|
return sd_bus_message_close_container(reply);
|
|
|
|
}
|
2014-02-12 18:28:21 +01:00
|
|
|
|
2014-02-13 00:24:00 +01:00
|
|
|
static int property_get_syscall_archs(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
_cleanup_strv_free_ char **l = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
#ifdef HAVE_SECCOMP
|
|
|
|
Iterator i;
|
|
|
|
void *id;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
2014-02-12 18:28:21 +01:00
|
|
|
|
2014-02-13 00:24:00 +01:00
|
|
|
#ifdef HAVE_SECCOMP
|
|
|
|
SET_FOREACH(id, c->syscall_archs, i) {
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = seccomp_arch_to_string(PTR_TO_UINT32(id) - 1);
|
|
|
|
if (!name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r = strv_extend(&l, name);
|
|
|
|
if (r < 0)
|
|
|
|
return -ENOMEM;
|
2014-02-12 18:28:21 +01:00
|
|
|
}
|
2014-02-13 00:24:00 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
strv_sort(l);
|
|
|
|
|
|
|
|
r = sd_bus_message_append_strv(reply, l);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-02-12 18:28:21 +01:00
|
|
|
|
2014-02-13 00:24:00 +01:00
|
|
|
return 0;
|
2014-02-12 18:28:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int property_get_syscall_errno(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
ExecContext *c = userdata;
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2014-02-12 18:28:21 +01:00
|
|
|
return sd_bus_message_append(reply, "i", (int32_t) c->syscall_errno);
|
2013-11-19 21:12:59 +01:00
|
|
|
}
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2014-02-17 16:52:52 +01:00
|
|
|
static int property_get_selinux_context(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context);
|
|
|
|
}
|
|
|
|
|
2014-02-20 16:19:44 +01:00
|
|
|
static int property_get_apparmor_profile(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile);
|
|
|
|
}
|
|
|
|
|
2014-11-24 12:46:20 +01:00
|
|
|
static int property_get_smack_process_label(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label);
|
|
|
|
}
|
|
|
|
|
2014-02-19 02:15:24 +01:00
|
|
|
static int property_get_personality(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
return sd_bus_message_append(reply, "s", personality_to_string(c->personality));
|
|
|
|
}
|
|
|
|
|
2014-02-25 20:37:03 +01:00
|
|
|
static int property_get_address_families(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
_cleanup_strv_free_ char **l = NULL;
|
|
|
|
Iterator i;
|
|
|
|
void *af;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
r = sd_bus_message_open_container(reply, 'r', "bas");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_bus_message_append(reply, "b", c->address_families_whitelist);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
SET_FOREACH(af, c->address_families, i) {
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = af_to_name(PTR_TO_INT(af));
|
|
|
|
if (!name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r = strv_extend(&l, name);
|
|
|
|
if (r < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
strv_sort(l);
|
|
|
|
|
|
|
|
r = sd_bus_message_append_strv(reply, l);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return sd_bus_message_close_container(reply);
|
|
|
|
}
|
|
|
|
|
2015-09-23 19:46:23 +02:00
|
|
|
static int property_get_working_directory(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
const char *wd;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
if (c->working_directory_home)
|
|
|
|
wd = "~";
|
|
|
|
else
|
|
|
|
wd = c->working_directory;
|
|
|
|
|
|
|
|
if (c->working_directory_missing_ok)
|
|
|
|
wd = strjoina("!", wd);
|
|
|
|
|
|
|
|
return sd_bus_message_append(reply, "s", wd);
|
|
|
|
}
|
|
|
|
|
2015-10-11 06:57:17 +02:00
|
|
|
static int property_get_syslog_level(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
return sd_bus_message_append(reply, "i", LOG_PRI(c->syslog_priority));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int property_get_syslog_facility(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
ExecContext *c = userdata;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
return sd_bus_message_append(reply, "i", LOG_FAC(c->syslog_priority));
|
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
const sd_bus_vtable bus_exec_vtable[] = {
|
|
|
|
SD_BUS_VTABLE_START(0),
|
2013-12-22 02:24:05 +01:00
|
|
|
SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
|
2015-10-12 07:16:05 +02:00
|
|
|
SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
|
2015-09-23 19:46:23 +02:00
|
|
|
SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2013-12-22 02:24:05 +01:00
|
|
|
SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
|
2015-10-11 06:57:17 +02:00
|
|
|
SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2013-12-22 02:24:05 +01:00
|
|
|
SD_BUS_PROPERTY("Capabilities", "s", property_get_capabilities, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("CapabilityBoundingSet", "t", property_get_capability_bounding_set, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_dirs), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_dirs), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_dirs), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-01-20 19:54:51 +01:00
|
|
|
SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-06-04 18:07:55 +02:00
|
|
|
SD_BUS_PROPERTY("ProtectHome", "s", bus_property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("ProtectSystem", "s", bus_property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
|
2013-12-22 02:24:05 +01:00
|
|
|
SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
|
2015-08-23 13:14:04 +02:00
|
|
|
SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-02-17 16:52:52 +01:00
|
|
|
SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-02-20 16:19:44 +01:00
|
|
|
SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-11-24 12:46:20 +01:00
|
|
|
SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2013-12-22 02:24:05 +01:00
|
|
|
SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-02-13 00:24:00 +01:00
|
|
|
SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-02-12 18:28:21 +01:00
|
|
|
SD_BUS_PROPERTY("SystemCallErrorNumber", "i", property_get_syscall_errno, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-02-19 02:15:24 +01:00
|
|
|
SD_BUS_PROPERTY("Personality", "s", property_get_personality, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-02-25 20:37:03 +01:00
|
|
|
SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
2014-03-03 17:14:07 +01:00
|
|
|
SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, runtime_directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
|
SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, runtime_directory), SD_BUS_VTABLE_PROPERTY_CONST),
|
2013-11-19 21:12:59 +01:00
|
|
|
SD_BUS_VTABLE_END
|
|
|
|
};
|
2010-07-04 16:44:58 +02:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
static int append_exec_command(sd_bus_message *reply, ExecCommand *c) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(reply);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
if (!c->path)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = sd_bus_message_open_container(reply, 'r', "sasbttttuii");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_bus_message_append(reply, "s", c->path);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_bus_message_append_strv(reply, c->argv);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_bus_message_append(reply, "bttttuii",
|
|
|
|
c->ignore,
|
|
|
|
c->exec_status.start_timestamp.realtime,
|
|
|
|
c->exec_status.start_timestamp.monotonic,
|
|
|
|
c->exec_status.exit_timestamp.realtime,
|
|
|
|
c->exec_status.exit_timestamp.monotonic,
|
|
|
|
(uint32_t) c->exec_status.pid,
|
|
|
|
(int32_t) c->exec_status.code,
|
|
|
|
(int32_t) c->exec_status.status);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return sd_bus_message_close_container(reply);
|
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
int bus_property_get_exec_command(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
2013-11-21 19:34:37 +01:00
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *ret_error) {
|
2010-07-04 20:38:14 +02:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
ExecCommand *c = (ExecCommand*) userdata;
|
2013-11-19 21:12:59 +01:00
|
|
|
int r;
|
2010-07-04 20:38:14 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
2010-07-04 20:38:14 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2010-07-04 20:38:14 +02:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
r = append_exec_command(reply, c);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2010-07-04 20:38:14 +02:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
return sd_bus_message_close_container(reply);
|
|
|
|
}
|
2013-11-19 21:12:59 +01:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
int bus_property_get_exec_command_list(
|
|
|
|
sd_bus *bus,
|
|
|
|
const char *path,
|
|
|
|
const char *interface,
|
|
|
|
const char *property,
|
|
|
|
sd_bus_message *reply,
|
|
|
|
void *userdata,
|
|
|
|
sd_bus_error *ret_error) {
|
2013-11-19 21:12:59 +01:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
ExecCommand *c = *(ExecCommand**) userdata;
|
|
|
|
int r;
|
2013-11-19 21:12:59 +01:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
assert(bus);
|
|
|
|
assert(reply);
|
|
|
|
|
|
|
|
r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2013-11-19 21:12:59 +01:00
|
|
|
|
2013-11-25 16:59:51 +01:00
|
|
|
LIST_FOREACH(command, c, c) {
|
|
|
|
r = append_exec_command(reply, c);
|
2013-11-19 21:12:59 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2010-07-04 20:38:14 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
return sd_bus_message_close_container(reply);
|
2012-07-17 04:17:53 +02:00
|
|
|
}
|
2014-02-05 02:02:00 +01:00
|
|
|
|
|
|
|
int bus_exec_context_set_transient_property(
|
|
|
|
Unit *u,
|
|
|
|
ExecContext *c,
|
|
|
|
const char *name,
|
|
|
|
sd_bus_message *message,
|
|
|
|
UnitSetPropertiesMode mode,
|
|
|
|
sd_bus_error *error) {
|
|
|
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(u);
|
|
|
|
assert(c);
|
|
|
|
assert(name);
|
|
|
|
assert(message);
|
|
|
|
|
|
|
|
if (streq(name, "User")) {
|
|
|
|
const char *uu;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &uu);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
|
|
|
|
if (isempty(uu)) {
|
2015-09-08 18:43:11 +02:00
|
|
|
c->user = mfree(c->user);
|
2014-02-05 02:02:00 +01:00
|
|
|
} else {
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
t = strdup(uu);
|
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
free(c->user);
|
|
|
|
c->user = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "User=%s\n", uu);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if (streq(name, "Group")) {
|
|
|
|
const char *gg;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &gg);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
|
|
|
|
if (isempty(gg)) {
|
2015-09-08 18:43:11 +02:00
|
|
|
c->group = mfree(c->group);
|
2014-02-05 02:02:00 +01:00
|
|
|
} else {
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
t = strdup(gg);
|
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
free(c->group);
|
|
|
|
c->group = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "Group=%s\n", gg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2015-10-09 14:37:50 +02:00
|
|
|
} else if (streq(name, "SyslogIdentifier")) {
|
|
|
|
const char *id;
|
2014-02-05 02:02:00 +01:00
|
|
|
|
2015-10-09 14:37:50 +02:00
|
|
|
r = sd_bus_message_read(message, "s", &id);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
|
|
|
|
if (isempty(id)) {
|
|
|
|
c->syslog_identifier = mfree(c->syslog_identifier);
|
|
|
|
} else {
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
t = strdup(id);
|
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
free(c->syslog_identifier);
|
|
|
|
c->syslog_identifier = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "SyslogIdentifier=%s\n", id);
|
|
|
|
}
|
|
|
|
|
2015-10-11 05:37:50 +02:00
|
|
|
return 1;
|
|
|
|
} else if (streq(name, "SyslogLevel")) {
|
|
|
|
int level;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "i", &level);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2015-10-14 18:30:35 +02:00
|
|
|
if (!log_level_is_valid(level))
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
|
|
|
|
|
2015-10-11 05:37:50 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-10-11 05:55:41 +02:00
|
|
|
return 1;
|
|
|
|
} else if (streq(name, "SyslogFacility")) {
|
|
|
|
int facility;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "i", &facility);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2015-10-14 18:30:35 +02:00
|
|
|
if (!log_facility_unshifted_is_valid(facility))
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
|
|
|
|
|
2015-10-11 05:55:41 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-10-09 14:37:50 +02:00
|
|
|
return 1;
|
2014-02-05 02:02:00 +01:00
|
|
|
} else if (streq(name, "Nice")) {
|
|
|
|
int n;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "i", &n);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (n < PRIO_MIN || n >= PRIO_MAX)
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Nice value out of range");
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->nice = n;
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "Nice=%i\n", n);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-09-23 19:46:23 +02:00
|
|
|
} else if (STR_IN_SET(name, "TTYPath", "RootDirectory")) {
|
2015-09-23 09:45:50 +02:00
|
|
|
const char *s;
|
2014-12-22 19:45:32 +01:00
|
|
|
|
2015-09-23 09:45:50 +02:00
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
2014-12-22 19:45:32 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2015-09-23 09:45:50 +02:00
|
|
|
if (!path_is_absolute(s))
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s takes an absolute path", name);
|
2014-12-22 19:45:32 +01:00
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
2015-09-23 19:46:23 +02:00
|
|
|
if (streq(name, "TTYPath"))
|
|
|
|
r = free_and_strdup(&c->tty_path, s);
|
|
|
|
else {
|
|
|
|
assert(streq(name, "RootDirectory"));
|
|
|
|
r = free_and_strdup(&c->root_directory, s);
|
2015-09-23 09:45:50 +02:00
|
|
|
}
|
2015-09-23 19:46:23 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-12-22 19:45:32 +01:00
|
|
|
|
2015-09-23 09:45:50 +02:00
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, s);
|
2014-12-22 19:45:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-09-23 19:46:23 +02:00
|
|
|
} else if (streq(name, "WorkingDirectory")) {
|
|
|
|
const char *s;
|
|
|
|
bool missing_ok;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (s[0] == '-') {
|
|
|
|
missing_ok = true;
|
|
|
|
s++;
|
|
|
|
} else
|
|
|
|
missing_ok = false;
|
|
|
|
|
|
|
|
if (!streq(s, "~") && !path_is_absolute(s))
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
if (streq(s, "~")) {
|
|
|
|
c->working_directory = mfree(c->working_directory);
|
|
|
|
c->working_directory_home = true;
|
|
|
|
} else {
|
|
|
|
r = free_and_strdup(&c->working_directory, s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
c->working_directory_home = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->working_directory_missing_ok = missing_ok;
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2014-12-22 19:45:32 +01:00
|
|
|
} else if (streq(name, "StandardInput")) {
|
|
|
|
const char *s;
|
|
|
|
ExecInput p;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
p = exec_input_from_string(s);
|
|
|
|
if (p < 0)
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard input name");
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->std_input = p;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "StandardInput=%s\n", exec_input_to_string(p));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
} else if (streq(name, "StandardOutput")) {
|
|
|
|
const char *s;
|
|
|
|
ExecOutput p;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
p = exec_output_from_string(s);
|
|
|
|
if (p < 0)
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard output name");
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->std_output = p;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "StandardOutput=%s\n", exec_output_to_string(p));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if (streq(name, "StandardError")) {
|
|
|
|
const char *s;
|
|
|
|
ExecOutput p;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
p = exec_output_from_string(s);
|
|
|
|
if (p < 0)
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard error name");
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->std_error = p;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "StandardError=%s\n", exec_output_to_string(p));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-09-10 16:45:28 +02:00
|
|
|
} else if (STR_IN_SET(name,
|
|
|
|
"IgnoreSIGPIPE", "TTYVHangup", "TTYReset",
|
|
|
|
"PrivateTmp", "PrivateDevices", "PrivateNetwork",
|
2015-10-09 14:17:41 +02:00
|
|
|
"NoNewPrivileges", "SyslogLevelPrefix")) {
|
2015-08-23 13:19:21 +02:00
|
|
|
int b;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "b", &b);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
2015-09-10 16:45:28 +02:00
|
|
|
if (streq(name, "IgnoreSIGPIPE"))
|
|
|
|
c->ignore_sigpipe = b;
|
|
|
|
else if (streq(name, "TTYVHangup"))
|
|
|
|
c->tty_vhangup = b;
|
|
|
|
else if (streq(name, "TTYReset"))
|
|
|
|
c->tty_reset = b;
|
|
|
|
else if (streq(name, "PrivateTmp"))
|
|
|
|
c->private_tmp = b;
|
|
|
|
else if (streq(name, "PrivateDevices"))
|
|
|
|
c->private_devices = b;
|
|
|
|
else if (streq(name, "PrivateNetwork"))
|
|
|
|
c->private_network = b;
|
|
|
|
else if (streq(name, "NoNewPrivileges"))
|
|
|
|
c->no_new_privileges = b;
|
2015-10-09 14:17:41 +02:00
|
|
|
else if (streq(name, "SyslogLevelPrefix"))
|
|
|
|
c->syslog_level_prefix = b;
|
2015-09-10 16:45:28 +02:00
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, yes_no(b));
|
2015-08-23 13:19:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if (streq(name, "UtmpIdentifier")) {
|
|
|
|
const char *id;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &id);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
if (isempty(id))
|
|
|
|
c->utmp_id = mfree(c->utmp_id);
|
|
|
|
else if (free_and_strdup(&c->utmp_id, id) < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "UtmpIdentifier=%s\n", strempty(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if (streq(name, "UtmpMode")) {
|
|
|
|
const char *s;
|
|
|
|
ExecUtmpMode m;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
m = exec_utmp_mode_from_string(s);
|
|
|
|
if (m < 0)
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid utmp mode");
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->utmp_mode = m;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "UtmpMode=%s\n", exec_utmp_mode_to_string(m));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if (streq(name, "PAMName")) {
|
|
|
|
const char *n;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &n);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
if (isempty(n))
|
|
|
|
c->pam_name = mfree(c->pam_name);
|
|
|
|
else if (free_and_strdup(&c->pam_name, n) < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "PAMName=%s\n", strempty(n));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2014-02-05 02:02:00 +01:00
|
|
|
} else if (streq(name, "Environment")) {
|
|
|
|
|
|
|
|
_cleanup_strv_free_ char **l = NULL;
|
|
|
|
|
|
|
|
r = sd_bus_message_read_strv(message, &l);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!strv_env_is_valid(l))
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
2014-02-07 00:01:19 +01:00
|
|
|
_cleanup_free_ char *joined = NULL;
|
2014-02-05 02:02:00 +01:00
|
|
|
char **e;
|
|
|
|
|
2015-10-20 04:04:10 +02:00
|
|
|
if (strv_length(l) == 0) {
|
|
|
|
c->environment = strv_free(c->environment);
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "Environment=\n");
|
|
|
|
} else {
|
|
|
|
e = strv_env_merge(2, c->environment, l);
|
|
|
|
if (!e)
|
|
|
|
return -ENOMEM;
|
2014-02-05 02:02:00 +01:00
|
|
|
|
2015-10-20 04:04:10 +02:00
|
|
|
strv_free(c->environment);
|
|
|
|
c->environment = e;
|
2014-02-05 02:02:00 +01:00
|
|
|
|
2015-10-20 04:04:10 +02:00
|
|
|
joined = strv_join_quoted(c->environment);
|
|
|
|
if (!joined)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "Environment=%s\n", joined);
|
|
|
|
}
|
2014-02-05 02:02:00 +01:00
|
|
|
}
|
|
|
|
|
2014-03-05 03:49:00 +01:00
|
|
|
return 1;
|
|
|
|
|
2015-10-15 11:57:28 +02:00
|
|
|
} else if (streq(name, "TimerSlackNSec")) {
|
|
|
|
|
|
|
|
nsec_t n;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "t", &n);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->timer_slack_nsec = n;
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "TimerSlackNSec=" NSEC_FMT "\n", n);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-10-17 21:58:29 +02:00
|
|
|
} 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;
|
|
|
|
|
2015-10-19 21:57:01 +02:00
|
|
|
} else if (streq(name, "EnvironmentFiles")) {
|
|
|
|
|
|
|
|
_cleanup_free_ char *joined = NULL;
|
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
2015-10-19 23:43:19 +02:00
|
|
|
_cleanup_free_ char **l = NULL;
|
2015-10-19 21:57:01 +02:00
|
|
|
size_t size = 0;
|
2015-10-19 23:43:19 +02:00
|
|
|
char **i;
|
2015-10-19 21:57:01 +02:00
|
|
|
|
|
|
|
r = sd_bus_message_enter_container(message, 'a', "(sb)");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
f = open_memstream(&joined, &size);
|
|
|
|
if (!f)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-10-19 23:43:19 +02:00
|
|
|
STRV_FOREACH(i, c->environment_files)
|
|
|
|
fprintf(f, "EnvironmentFile=%s\n", *i);
|
2015-10-19 21:57:01 +02:00
|
|
|
|
|
|
|
while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
|
|
|
|
const char *path;
|
|
|
|
int b;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "sb", &path, &b);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_bus_message_exit_container(message);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!isempty(path) && !path_is_absolute(path))
|
|
|
|
return sd_bus_error_set_errnof(error, EINVAL, "Path %s is not absolute.", path);
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
char *buf = NULL;
|
|
|
|
|
|
|
|
buf = strjoin(b ? "-" : "", path, NULL);
|
2015-10-19 23:43:19 +02:00
|
|
|
if (!buf)
|
2015-10-19 21:57:01 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
fprintf(f, "EnvironmentFile=%s\n", buf);
|
|
|
|
|
2015-10-19 23:43:19 +02:00
|
|
|
r = strv_consume(&l, buf);
|
2015-10-19 21:57:01 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2015-10-22 02:02:17 +02:00
|
|
|
r = sd_bus_message_exit_container(message);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2015-10-19 23:43:19 +02:00
|
|
|
r = fflush_and_check(f);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2015-10-19 21:57:01 +02:00
|
|
|
|
2015-10-19 23:43:19 +02:00
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
if (strv_isempty(l)) {
|
|
|
|
c->environment_files = strv_free(c->environment_files);
|
2015-10-19 21:57:01 +02:00
|
|
|
unit_write_drop_in_private(u, mode, name, "EnvironmentFile=\n");
|
2015-10-19 23:43:19 +02:00
|
|
|
} else {
|
|
|
|
r = strv_extend_strv(&c->environment_files, l, true);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2015-10-19 21:57:01 +02:00
|
|
|
unit_write_drop_in_private(u, mode, name, joined);
|
2015-10-19 23:43:19 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-19 21:57:01 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-10-20 21:57:04 +02:00
|
|
|
} else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories")) {
|
|
|
|
|
|
|
|
_cleanup_strv_free_ char **l = NULL;
|
|
|
|
char ***dirs;
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
r = sd_bus_message_read_strv(message, &l);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
STRV_FOREACH(p, l) {
|
|
|
|
int offset;
|
|
|
|
if (!utf8_is_valid(*p))
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
|
|
|
|
|
|
|
|
offset = **p == '-';
|
|
|
|
if (!path_is_absolute(*p + offset))
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
_cleanup_free_ char *joined = NULL;
|
|
|
|
|
|
|
|
if (streq(name, "ReadWriteDirectories"))
|
|
|
|
dirs = &c->read_write_dirs;
|
|
|
|
else if (streq(name, "ReadOnlyDirectories"))
|
|
|
|
dirs = &c->read_only_dirs;
|
|
|
|
else if (streq(name, "InaccessibleDirectories"))
|
|
|
|
dirs = &c->inaccessible_dirs;
|
|
|
|
|
|
|
|
if (strv_length(l) == 0) {
|
|
|
|
*dirs = strv_free(*dirs);
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=\n", name);
|
|
|
|
} else {
|
|
|
|
r = strv_extend_strv(dirs, l, true);
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
joined = strv_join_quoted(*dirs);
|
|
|
|
if (!joined)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, joined);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-10-25 00:48:33 +02:00
|
|
|
} else if (streq(name, "ProtectSystem")) {
|
|
|
|
const char *s;
|
|
|
|
ProtectSystem ps;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = parse_boolean(s);
|
|
|
|
if (r > 0)
|
|
|
|
ps = PROTECT_SYSTEM_YES;
|
|
|
|
else if (r == 0)
|
|
|
|
ps = PROTECT_SYSTEM_NO;
|
|
|
|
else {
|
|
|
|
ps = protect_system_from_string(s);
|
|
|
|
if (ps < 0)
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse protect system value");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->protect_system = ps;
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-10-26 01:20:49 +01:00
|
|
|
} else if (streq(name, "ProtectHome")) {
|
|
|
|
const char *s;
|
|
|
|
ProtectHome ph;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "s", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = parse_boolean(s);
|
|
|
|
if (r > 0)
|
|
|
|
ph = PROTECT_HOME_YES;
|
|
|
|
else if (r == 0)
|
|
|
|
ph = PROTECT_HOME_NO;
|
|
|
|
else {
|
|
|
|
ph = protect_home_from_string(s);
|
|
|
|
if (ph < 0)
|
|
|
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse protect home value");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
c->protect_home = ph;
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2014-03-05 03:49:00 +01:00
|
|
|
} else if (rlimit_from_string(name) >= 0) {
|
|
|
|
uint64_t rl;
|
|
|
|
rlim_t x;
|
|
|
|
|
|
|
|
r = sd_bus_message_read(message, "t", &rl);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (rl == (uint64_t) -1)
|
|
|
|
x = RLIM_INFINITY;
|
|
|
|
else {
|
|
|
|
x = (rlim_t) rl;
|
|
|
|
|
|
|
|
if ((uint64_t) x != rl)
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != UNIT_CHECK) {
|
|
|
|
int z;
|
|
|
|
|
|
|
|
z = rlimit_from_string(name);
|
|
|
|
|
|
|
|
if (!c->rlimit[z]) {
|
|
|
|
c->rlimit[z] = new(struct rlimit, 1);
|
|
|
|
if (!c->rlimit[z])
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->rlimit[z]->rlim_cur = c->rlimit[z]->rlim_max = x;
|
|
|
|
|
|
|
|
if (x == RLIM_INFINITY)
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=infinity\n", name);
|
|
|
|
else
|
|
|
|
unit_write_drop_in_private_format(u, mode, name, "%s=%" PRIu64 "\n", name, rl);
|
|
|
|
}
|
|
|
|
|
2014-02-05 02:02:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|