/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
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
(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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_SECCOMP
#include <seccomp.h>
#endif
#include "af-list.h"
#include "alloc-util.h"
#include "bus-util.h"
#include "capability-util.h"
#include "dbus-execute.h"
#include "env-util.h"
#include "execute.h"
#include "fd-util.h"
#include "fileio.h"
#include "ioprio.h"
#include "missing.h"
#include "namespace.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "rlimit-util.h"
#ifdef HAVE_SECCOMP
#include "seccomp-util.h"
#endif
#include "strv.h"
#include "syslog-util.h"
#include "utf8.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_system, protect_system, ProtectSystem);
static int property_get_environment_files(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
char **j;
int r;
assert(c);
if (r < 0)
return r;
STRV_FOREACH(j, c->environment_files) {
const char *fn = *j;
if (r < 0)
return r;
}
return sd_bus_message_close_container(reply);
}
static int property_get_oom_score_adjust(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
int32_t n;
assert(c);
if (c->oom_score_adjust_set)
n = c->oom_score_adjust;
else {
_cleanup_free_ char *t = NULL;
n = 0;
if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0)
safe_atoi32(t, &n);
}
}
static int property_get_nice(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
int32_t n;
assert(c);
if (c->nice_set)
n = c->nice;
else {
errno = 0;
n = getpriority(PRIO_PROCESS, 0);
if (errno > 0)
n = 0;
}
}
static int property_get_ioprio(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
int32_t n;
assert(c);
if (c->ioprio_set)
n = c->ioprio;
else {
n = ioprio_get(IOPRIO_WHO_PROCESS, 0);
if (n < 0)
}
}
static int property_get_cpu_sched_policy(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
int32_t n;
assert(c);
if (c->cpu_sched_set)
n = c->cpu_sched_policy;
else {
n = sched_getscheduler(0);
if (n < 0)
n = SCHED_OTHER;
}
}
static int property_get_cpu_sched_priority(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
int32_t n;
assert(c);
if (c->cpu_sched_set)
n = c->cpu_sched_priority;
else {
struct sched_param p = {};
if (sched_getparam(0, &p) >= 0)
n = p.sched_priority;
else
n = 0;
}
}
static int property_get_cpu_affinity(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
if (c->cpuset)
else
}
static int property_get_timer_slack_nsec(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
uint64_t u;
assert(c);
if (c->timer_slack_nsec != NSEC_INFINITY)
u = (uint64_t) c->timer_slack_nsec;
else
}
static int property_get_capability_bounding_set(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_ambient_capabilities(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_capabilities(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
_cleanup_cap_free_charp_ char *t = NULL;
const char *s;
assert(c);
if (c->capabilities)
else
s = "";
if (!s)
return -ENOMEM;
}
static int property_get_syscall_filter(
const char *path,
const char *interface,
const char *property,
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(c);
if (r < 0)
return r;
if (r < 0)
return r;
#ifdef HAVE_SECCOMP
char *name;
if (!name)
continue;
r = strv_consume(&l, name);
if (r < 0)
return r;
}
#endif
strv_sort(l);
r = sd_bus_message_append_strv(reply, l);
if (r < 0)
return r;
return sd_bus_message_close_container(reply);
}
static int property_get_syscall_archs(
const char *path,
const char *interface,
const char *property,
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(c);
#ifdef HAVE_SECCOMP
const char *name;
if (!name)
continue;
r = strv_extend(&l, name);
if (r < 0)
return -ENOMEM;
}
#endif
strv_sort(l);
r = sd_bus_message_append_strv(reply, l);
if (r < 0)
return r;
return 0;
}
static int property_get_syscall_errno(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_selinux_context(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_apparmor_profile(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_smack_process_label(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_personality(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_address_families(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
_cleanup_strv_free_ char **l = NULL;
Iterator i;
void *af;
int r;
assert(c);
if (r < 0)
return r;
if (r < 0)
return r;
const char *name;
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);
}
static int property_get_working_directory(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
const char *wd;
assert(c);
if (c->working_directory_home)
wd = "~";
else
wd = c->working_directory;
if (c->working_directory_missing_ok)
}
static int property_get_syslog_level(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
static int property_get_syslog_facility(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
}
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("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("LimitCPUSoft", "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("LimitFSIZESoft", "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("LimitDATASoft", "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("LimitSTACKSoft", "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("LimitCORESoft", "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("LimitRSSSoft", "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("LimitNOFILESoft", "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("LimitASSoft", "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("LimitNPROCSoft", "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("LimitMEMLOCKSoft", "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("LimitLOCKSSoft", "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("LimitSIGPENDINGSoft", "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("LimitMSGQUEUESoft", "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("LimitNICESoft", "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("LimitRTPRIOSoft", "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),
SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
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("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("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),
SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, 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("AmbientCapabilities", "t", property_get_ambient_capabilities, 0, 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),
SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
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),
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),
SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
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),
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),
SD_BUS_PROPERTY("SystemCallErrorNumber", "i", property_get_syscall_errno, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
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),
};
int r;
assert(c);
if (!c->path)
return 0;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
c->ignore,
if (r < 0)
return r;
return sd_bus_message_close_container(reply);
}
const char *path,
const char *interface,
const char *property,
void *userdata,
int r;
if (r < 0)
return r;
r = append_exec_command(reply, c);
if (r < 0)
return r;
return sd_bus_message_close_container(reply);
}
const char *path,
const char *interface,
const char *property,
void *userdata,
int r;
if (r < 0)
return r;
r = append_exec_command(reply, c);
if (r < 0)
return r;
}
return sd_bus_message_close_container(reply);
}
Unit *u,
ExecContext *c,
const char *name,
sd_bus_error *error) {
int r, ri;
assert(u);
assert(c);
const char *uu;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
} else {
char *t;
if (!t)
return -ENOMEM;
c->user = t;
}
}
return 1;
const char *gg;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
} else {
char *t;
if (!t)
return -ENOMEM;
c->group = t;
}
}
return 1;
const char *id;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
} else {
char *t;
if (!t)
return -ENOMEM;
free(c->syslog_identifier);
c->syslog_identifier = t;
}
}
return 1;
int level;
if (r < 0)
return r;
if (!log_level_is_valid(level))
if (mode != UNIT_CHECK) {
}
return 1;
int facility;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
}
return 1;
int n;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->nice = n;
}
return 1;
const char *s;
if (r < 0)
return r;
if (!path_is_absolute(s))
if (mode != UNIT_CHECK) {
r = free_and_strdup(&c->tty_path, s);
else {
r = free_and_strdup(&c->root_directory, s);
}
if (r < 0)
return r;
}
return 1;
const char *s;
bool missing_ok;
if (r < 0)
return r;
if (s[0] == '-') {
missing_ok = true;
s++;
} else
missing_ok = false;
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_home = true;
} else {
r = free_and_strdup(&c->working_directory, s);
if (r < 0)
return r;
c->working_directory_home = false;
}
unit_write_drop_in_private_format(u, mode, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
}
return 1;
const char *s;
ExecInput p;
if (r < 0)
return r;
p = exec_input_from_string(s);
if (p < 0)
if (mode != UNIT_CHECK) {
c->std_input = p;
}
return 1;
const char *s;
ExecOutput p;
if (r < 0)
return r;
p = exec_output_from_string(s);
if (p < 0)
if (mode != UNIT_CHECK) {
c->std_output = p;
}
return 1;
const char *s;
ExecOutput p;
if (r < 0)
return r;
p = exec_output_from_string(s);
if (p < 0)
if (mode != UNIT_CHECK) {
c->std_error = p;
}
return 1;
} else if (STR_IN_SET(name,
"IgnoreSIGPIPE", "TTYVHangup", "TTYReset",
"PrivateTmp", "PrivateDevices", "PrivateNetwork",
"NoNewPrivileges", "SyslogLevelPrefix")) {
int b;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->ignore_sigpipe = b;
c->tty_vhangup = b;
c->tty_reset = b;
c->private_tmp = b;
c->private_devices = b;
c->private_network = b;
c->no_new_privileges = b;
c->syslog_level_prefix = b;
}
return 1;
const char *id;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
return -ENOMEM;
}
return 1;
const char *s;
ExecUtmpMode m;
if (r < 0)
return r;
m = exec_utmp_mode_from_string(s);
if (m < 0)
if (mode != UNIT_CHECK) {
c->utmp_mode = m;
}
return 1;
const char *n;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
if (isempty(n))
else if (free_and_strdup(&c->pam_name, n) < 0)
return -ENOMEM;
}
return 1;
_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))
if (mode != UNIT_CHECK) {
char **e;
if (strv_length(l) == 0) {
} else {
if (!e)
return -ENOMEM;
strv_free(c->environment);
c->environment = e;
if (!joined)
return -ENOMEM;
}
}
return 1;
nsec_t n;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->timer_slack_nsec = n;
}
return 1;
int oa;
if (r < 0)
return r;
if (!oom_score_adjust_is_valid(oa))
if (mode != UNIT_CHECK) {
c->oom_score_adjust = oa;
c->oom_score_adjust_set = true;
}
return 1;
_cleanup_free_ char **l = NULL;
char **i;
if (r < 0)
return r;
if (!f)
return -ENOMEM;
STRV_FOREACH(i, c->environment_files)
fprintf(f, "EnvironmentFile=%s\n", *i);
const char *path;
int b;
if (r < 0)
return r;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
if (!buf)
return -ENOMEM;
r = strv_consume(&l, buf);
if (r < 0)
return r;
}
}
if (r < 0)
return r;
if (r < 0)
return r;
r = fflush_and_check(f);
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
if (strv_isempty(l)) {
} else {
r = strv_extend_strv(&c->environment_files, l, true);
if (r < 0)
return r;
}
}
return 1;
_cleanup_strv_free_ char **l = NULL;
r = sd_bus_message_read_strv(message, &l);
if (r < 0)
return r;
if (!strv_env_name_is_valid(l))
if (mode != UNIT_CHECK) {
if (strv_isempty(l)) {
} else {
r = strv_extend_strv(&c->pass_environment, l, true);
if (r < 0)
return r;
if (!joined)
return -ENOMEM;
}
}
return 1;
} 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))
offset = **p == '-';
if (!path_is_absolute(*p + offset))
}
if (mode != UNIT_CHECK) {
dirs = &c->read_write_dirs;
dirs = &c->read_only_dirs;
else /* "InaccessibleDirectories" */
dirs = &c->inaccessible_dirs;
if (strv_length(l) == 0) {
} else {
r = strv_extend_strv(dirs, l, true);
if (r < 0)
return -ENOMEM;
if (!joined)
return -ENOMEM;
}
}
return 1;
const char *s;
if (r < 0)
return r;
r = parse_boolean(s);
if (r > 0)
else if (r == 0)
else {
ps = protect_system_from_string(s);
if (ps < 0)
}
if (mode != UNIT_CHECK) {
c->protect_system = ps;
}
return 1;
const char *s;
if (r < 0)
return r;
r = parse_boolean(s);
if (r > 0)
else if (r == 0)
else {
ph = protect_home_from_string(s);
if (ph < 0)
}
if (mode != UNIT_CHECK) {
c->protect_home = ph;
}
return 1;
_cleanup_strv_free_ char **l = NULL;
char **p;
r = sd_bus_message_read_strv(message, &l);
if (r < 0)
return r;
STRV_FOREACH(p, l) {
if (!filename_is_valid(*p))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Runtime directory is not valid %s", *p);
}
if (mode != UNIT_CHECK) {
if (strv_isempty(l)) {
} else {
r = strv_extend_strv(&c->runtime_directory, l, true);
if (r < 0)
return -ENOMEM;
if (!joined)
return -ENOMEM;
}
}
return 1;
}
if (ri < 0) {
if (soft) {
const char *n;
ri = rlimit_from_string(n);
if (ri >= 0)
name = n;
}
}
if (ri >= 0) {
rlim_t x;
if (r < 0)
return r;
x = RLIM_INFINITY;
else {
return -ERANGE;
}
if (mode != UNIT_CHECK) {
_cleanup_free_ char *f = NULL;
if (soft)
else
} else
/* When the resource limit is not initialized yet, then assign the value to both fields */
.rlim_cur = x,
.rlim_max = x,
};
r = rlimit_format(&nl, &f);
if (r < 0)
return r;
else {
return -ENOMEM;
}
}
return 1;
}
return 0;
}