dbus-execute.c revision ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602
/*-*- 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 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/>.
***/
#include "bus-util.h"
#include "missing.h"
#include "ioprio.h"
#include "strv.h"
#include "syscall-list.h"
#include "fileio.h"
#include "execute.h"
#include "dbus-execute.h"
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_rlimit(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
uint64_t u;
if (rl)
else {
int z;
z = rlimit_from_string(property);
assert(z >= 0);
}
}
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_atoi(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);
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);
/* We store this negated internally, to match the kernel, but
* we expose it normalized. */
}
static int property_get_capabilities(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
char *t = NULL;
const char *s;
int r;
assert(c);
if (c->capabilities)
else
s = "";
if (!s)
return -ENOMEM;
if (t)
cap_free(t);
return r;
}
static int property_get_syscall_filter(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
assert(c);
if (c->syscall_filter)
else
}
const sd_bus_vtable bus_exec_vtable[] = {
SD_BUS_PROPERTY("LimitCPU", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), 0),
SD_BUS_PROPERTY("LimitFSIZE", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), 0),
SD_BUS_PROPERTY("LimitDATA", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), 0),
SD_BUS_PROPERTY("LimitSTACK", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), 0),
SD_BUS_PROPERTY("LimitCORE", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), 0),
SD_BUS_PROPERTY("LimitRSS", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), 0),
SD_BUS_PROPERTY("LimitNOFILE", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), 0),
SD_BUS_PROPERTY("LimitNPROC", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), 0),
SD_BUS_PROPERTY("LimitMEMLOCK", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), 0),
SD_BUS_PROPERTY("LimitLOCKS", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), 0),
SD_BUS_PROPERTY("LimitSIGPENDING", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), 0),
SD_BUS_PROPERTY("LimitMSGQUEUE", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), 0),
SD_BUS_PROPERTY("LimitNICE", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), 0),
SD_BUS_PROPERTY("LimitRTPRIO", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), 0),
SD_BUS_PROPERTY("LimitRTTIME", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), 0),
SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), 0),
SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), 0),
SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), 0),
SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), 0),
SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), 0),
SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), 0),
SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), 0),
SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_dirs), 0),
SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), 0),
SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), 0),
SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), 0),
SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), 0),
};
const char *path,
const char *interface,
const char *property,
void *userdata,
int r;
if (r < 0)
return r;
LIST_FOREACH(command, c, c) {
if (!c->path)
continue;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
c->ignore,
if (r < 0)
return r;
if (r < 0)
return r;
}
return sd_bus_message_close_container(reply);
}