execute.c revision e056b01d8acea7fc06d52ef91d227d744faf5259
/*-*- 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 <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <grp.h>
#include <pwd.h>
#ifdef HAVE_PAM
#include <security/pam_appl.h>
#endif
#include "execute.h"
#include "strv.h"
#include "macro.h"
#include "capability.h"
#include "util.h"
#include "log.h"
#include "ioprio.h"
#include "securebits.h"
#include "cgroup.h"
#include "namespace.h"
#include "tcpwrap.h"
#include "exit-status.h"
#include "missing.h"
#include "utmp-wtmp.h"
#include "def.h"
#include "loopback-setup.h"
#include "path-util.h"
/* This assumes there is a 'tty' group */
#define TTY_MODE 0620
int start, restart_from;
if (n_fds <= 0)
return 0;
/* Modifies the fds array! (sorts it) */
start = 0;
for (;;) {
int i;
restart_from = -1;
int nfd;
/* Already at right index? */
if (fds[i] == i+3)
continue;
return -errno;
close_nointr_nofail(fds[i]);
/* Hmm, the fd we wanted isn't free? Then
* let's remember that and try again from here*/
restart_from = i;
}
if (restart_from < 0)
break;
}
return 0;
}
unsigned i;
int r;
if (n_fds <= 0)
return 0;
for (i = 0; i < n_fds; i++) {
return r;
/* We unconditionally drop FD_CLOEXEC from the fds,
* since after all we want to pass these fds to our
* children */
if ((r = fd_cloexec(fds[i], false)) < 0)
return r;
}
return 0;
}
}
if (context->tty_vhangup)
}
int fd, r;
return -errno;
} else
r = nfd;
return r;
}
static int connect_logger_as(const ExecContext *context, ExecOutput output, const char *ident, int nfd) {
int fd, r;
union sockaddr_union sa;
assert(ident);
if (fd < 0)
return -errno;
if (r < 0) {
return -errno;
}
return -errno;
}
"%s\n"
"%i\n"
"%i\n"
"%i\n"
"%i\n"
"%i\n",
output == EXEC_OUTPUT_SYSLOG_AND_CONSOLE || output == EXEC_OUTPUT_KMSG_AND_CONSOLE || output == EXEC_OUTPUT_JOURNAL_AND_CONSOLE);
} else
r = nfd;
return r;
}
int fd, r;
return fd;
} else
r = nfd;
return r;
}
static bool is_terminal_input(ExecInput i) {
return
i == EXEC_INPUT_TTY ||
i == EXEC_INPUT_TTY_FORCE ||
i == EXEC_INPUT_TTY_FAIL;
}
return EXEC_INPUT_NULL;
return EXEC_INPUT_NULL;
return std_input;
}
return EXEC_OUTPUT_INHERIT;
return std_output;
}
ExecInput i;
switch (i) {
case EXEC_INPUT_NULL:
case EXEC_INPUT_TTY:
case EXEC_INPUT_TTY_FORCE:
case EXEC_INPUT_TTY_FAIL: {
int fd, r;
if ((fd = acquire_terminal(
i == EXEC_INPUT_TTY_FAIL,
i == EXEC_INPUT_TTY_FORCE,
false)) < 0)
return fd;
if (fd != STDIN_FILENO) {
} else
r = STDIN_FILENO;
return r;
}
case EXEC_INPUT_SOCKET:
default:
assert_not_reached("Unknown input type");
}
}
static int setup_output(const ExecContext *context, int socket_fd, const char *ident, bool apply_tty_stdin) {
ExecOutput o;
ExecInput i;
assert(ident);
/* This expects the input is already set up */
switch (o) {
case EXEC_OUTPUT_INHERIT:
/* If input got downgraded, inherit the original value */
if (i != EXEC_INPUT_NULL)
/* If we are not started from PID 1 we just inherit STDOUT from our parent process. */
if (getppid() != 1)
return STDOUT_FILENO;
* right access mode. So we fall through */
case EXEC_OUTPUT_NULL:
case EXEC_OUTPUT_TTY:
if (is_terminal_input(i))
/* We don't reset the terminal if this is just about output */
case EXEC_OUTPUT_SYSLOG:
case EXEC_OUTPUT_KMSG:
case EXEC_OUTPUT_JOURNAL:
case EXEC_OUTPUT_SOCKET:
default:
assert_not_reached("Unknown output type");
}
}
static int setup_error(const ExecContext *context, int socket_fd, const char *ident, bool apply_tty_stdin) {
ExecOutput o, e;
ExecInput i;
assert(ident);
/* This expects the input and output are already set up */
/* Don't change the stderr file descriptor if we inherit all
* the way and are not on a tty */
if (e == EXEC_OUTPUT_INHERIT &&
o == EXEC_OUTPUT_INHERIT &&
i == EXEC_INPUT_NULL &&
getppid () != 1)
return STDERR_FILENO;
/* Duplicate from stdout if possible */
if (e == o || e == EXEC_OUTPUT_INHERIT)
switch (e) {
case EXEC_OUTPUT_NULL:
case EXEC_OUTPUT_TTY:
if (is_terminal_input(i))
/* We don't reset the terminal if this is just about output */
case EXEC_OUTPUT_SYSLOG:
case EXEC_OUTPUT_KMSG:
case EXEC_OUTPUT_JOURNAL:
case EXEC_OUTPUT_SOCKET:
default:
assert_not_reached("Unknown error type");
}
}
/* This might fail. What matters are the results. */
return -errno;
return -EPERM;
return 0;
}
int *_saved_stdin,
int *_saved_stdout) {
/* This returns positive EXIT_xxx return values instead of
* negative errno style values! */
return EXIT_STDIN;
r = EXIT_STDOUT;
goto fail;
}
if ((fd = acquire_terminal(
false)) < 0) {
r = EXIT_STDIN;
goto fail;
}
r = EXIT_STDIN;
goto fail;
}
r = EXIT_STDIN;
goto fail;
}
r = EXIT_STDOUT;
goto fail;
}
if (fd >= 2)
return 0;
fail:
if (saved_stdout >= 0)
if (saved_stdin >= 0)
if (fd >= 0)
return r;
}
int *saved_stdin,
int *saved_stdout,
bool *keep_stdin,
bool *keep_stdout) {
assert(*saved_stdin >= 0);
assert(*saved_stdout >= 0);
/* This returns positive EXIT_xxx return values instead of
* negative errno style values! */
/* The service wants terminal input. */
*keep_stdin = true;
*keep_stdout =
} else {
/* If the service doesn't want a controlling terminal,
* then we need to get rid entirely of what we have
* already. */
if (release_terminal() < 0)
return EXIT_STDIN;
return EXIT_STDIN;
return EXIT_STDOUT;
*keep_stdout = *keep_stdin = false;
}
return 0;
}
bool keep_groups = false;
int r;
/* Lookup and set GID and supplementary group list. Here too
* we avoid NSS lookups for gid=0. */
if ((r = get_group_creds(&g, &gid)) < 0)
return r;
}
return -errno;
keep_groups = true;
}
/* Second step, set our gids */
return -errno;
}
if (context->supplementary_groups) {
int ngroups_max, k;
char **i;
/* Final step, initialize any manually set supplementary groups */
return -ENOMEM;
if (keep_groups) {
return -errno;
}
} else
k = 0;
const char *g;
if (k >= ngroups_max) {
return -E2BIG;
}
g = *i;
r = get_group_creds(&g, gids+k);
if (r < 0) {
return r;
}
k++;
}
return -errno;
}
}
return 0;
}
int r;
/* Sets (but doesn't lookup) the uid and make sure we keep the
* capabilities while doing so. */
if (context->capabilities) {
cap_t d;
static const cap_value_t bits[] = {
CAP_SETUID, /* Necessary so that we can run setresuid() below */
CAP_SETPCAP /* Necessary so that we can set PR_SET_SECUREBITS later on */
};
/* First step: If we need to keep capabilities but
* drop privileges we need to make sure we keep our
* caps, whiel we drop privileges. */
if (uid != 0) {
return -errno;
}
/* Second step: set the capabilities. This will reduce
* the capabilities to the minimum we need. */
return -errno;
r = -errno;
cap_free(d);
return r;
}
if (cap_set_proc(d) < 0) {
r = -errno;
cap_free(d);
return r;
}
cap_free(d);
}
/* Third step: actually set the uids */
return -errno;
/* At this point we should have all necessary capabilities but
are otherwise a normal user. However, the caps might got
corrupted due to the setresuid() so we need clean them up
later. This is done outside of this call. */
return 0;
}
#ifdef HAVE_PAM
static int null_conv(
int num_msg,
const struct pam_message **msg,
struct pam_response **resp,
void *appdata_ptr) {
/* We don't support conversations */
return PAM_CONV_ERR;
}
static int setup_pam(
const char *name,
const char *user,
const char *tty,
char ***pam_env,
.appdata_ptr = NULL
};
int pam_code = PAM_SUCCESS;
int err;
char **e = NULL;
bool close_session = false;
/* We set up PAM in the parent process, then fork. The child
* will then stay around until killed via PR_GET_PDEATHSIG or
* systemd via the cgroup logic. It will then remove the PAM
* session again. The parent process will exec() the actual
* daemon. We do things this way to ensure that the main PID
* of the daemon is the one we initially fork()ed. */
goto fail;
}
if (tty)
goto fail;
goto fail;
goto fail;
close_session = true;
if ((!(e = pam_getenvlist(handle)))) {
goto fail;
}
/* Block SIGTERM, so that we know that it won't get lost in
* the child */
if (sigemptyset(&ss) < 0 ||
goto fail;
parent_pid = getpid();
goto fail;
if (pam_pid == 0) {
int sig;
int r = EXIT_PAM;
/* The child's job is to reset the PAM session on
* termination */
/* This string must fit in 10 chars (i.e. the length
rename_process("(sd-pam)");
/* Make sure we don't keep open the passed fds in this
child. We assume that otherwise only those fds are
open here that have been opened by PAM. */
/* Drop privileges - we don't need any to pam_close_session
* and this will make PR_SET_PDEATHSIG work in most cases.
* If this fails, ignore the error - but expect sd-pam threads
* to fail to exit normally */
/* Wait until our parent died. This will only work if
* the above setresuid() succeeds, otherwise the kernel
* will not allow unprivileged parents kill their privileged
* children this way. We rely on the control groups kill logic
* to do the rest for us. */
goto child_finish;
/* Check if our parent process might already have
* died? */
if (getppid() == parent_pid) {
for (;;) {
continue;
goto child_finish;
}
break;
}
}
/* If our parent died we'll end the session */
if (getppid() != parent_pid)
goto child_finish;
r = 0;
_exit(r);
}
/* If the child was forked off successfully it will do all the
* cleanups, so forget about the handle here. */
/* Unblock SIGTERM again in the parent */
goto fail;
/* We close the log explicitly here, since the PAM modules
* might have opened it, but we don't want this fd around. */
closelog();
*pam_env = e;
e = NULL;
return 0;
fail:
if (pam_code != PAM_SUCCESS)
else
if (handle) {
if (close_session)
}
strv_free(e);
closelog();
if (pam_pid > 1) {
}
return err;
}
#endif
unsigned long i;
int r;
/* If we are run as PID 1 we will lack CAP_SETPCAP by default
* in the effective set (yes, the kernel drops that when
* executing init!), so get it back temporarily so that we can
* call PR_CAPBSET_DROP. */
old_cap = cap_get_proc();
if (!old_cap)
return -errno;
r = -errno;
goto finish;
}
static const cap_value_t v = CAP_SETPCAP;
if (!new_cap) {
r = -errno;
goto finish;
}
r = -errno;
goto finish;
}
if (cap_set_proc(new_cap) < 0) {
r = -errno;
goto finish;
}
}
for (i = 0; i <= cap_last_cap(); i++)
if (prctl(PR_CAPBSET_DROP, i) < 0) {
r = -errno;
goto finish;
}
}
r = 0;
if (new_cap)
if (old_cap) {
}
return r;
}
static void rename_process_from_path(const char *path) {
char process_name[11];
const char *p;
size_t l;
/* This resulting string must fit in 10 chars (i.e. the length
p = path_get_file_name(path);
if (isempty(p)) {
rename_process("(...)");
return;
}
l = strlen(p);
if (l > 8) {
/* The end of the process name is usually more
* interesting, since the first bit might just be
* "systemd-" */
p = p + l - 8;
l = 8;
}
process_name[0] = '(';
}
char **argv,
const ExecContext *context,
char **environment,
bool apply_permissions,
bool apply_chroot,
bool apply_tty_stdin,
bool confirm_spawn,
const char *cgroup_suffix,
int idle_pipe[2],
int r;
char *line;
int socket_fd;
if (n_fds != 1)
return -EINVAL;
n_fds = 0;
} else
socket_fd = -1;
return r;
}
if (!argv)
r = -ENOMEM;
goto fail_parent;
}
if (r < 0)
goto fail_parent;
r = -errno;
goto fail_parent;
}
if (pid == 0) {
int i, err;
unsigned n_env = 0;
/* child */
/* We reset exactly these signals, since they are the
* only ones we set to SIG_IGN in the main daemon. All
* others we leave untouched because we set them to
* SIG_DFL or a valid handler initially, both of which
* will be demoted to SIG_DFL. */
SIGNALS_IGNORE, -1);
if (context->ignore_sigpipe)
r = EXIT_SIGNAL_MASK;
goto fail_child;
}
if (idle_pipe) {
if (idle_pipe[1] >= 0)
if (idle_pipe[0] >= 0) {
}
}
/* Close sockets very early to make sure we don't
* block init reexecution because it cannot bind its
* sockets */
if (err < 0) {
r = EXIT_FDS;
goto fail_child;
}
if (setsid() < 0) {
r = EXIT_SETSID;
goto fail_child;
}
if (context->tcpwrap_name) {
if (socket_fd >= 0)
r = EXIT_TCPWRAP;
goto fail_child;
}
for (i = 0; i < (int) n_fds; i++) {
r = EXIT_TCPWRAP;
goto fail_child;
}
}
}
/* We skip the confirmation step if we shall not apply the TTY */
if (confirm_spawn &&
char response;
/* Set up terminal for the question */
if ((r = setup_confirm_stdio(context,
&saved_stdin, &saved_stdout))) {
goto fail_child;
}
/* Now ask the question. */
r = EXIT_MEMORY;
goto fail_child;
}
if (r < 0 || response == 'n') {
r = EXIT_CONFIRM;
goto fail_child;
} else if (response == 's') {
err = r = 0;
goto fail_child;
}
/* Release terminal for the question */
if ((r = restore_confirm_stdio(context,
&keep_stdin, &keep_stdout))) {
goto fail_child;
}
}
* must sure to drop O_NONBLOCK */
if (socket_fd >= 0)
fd_nonblock(socket_fd, false);
if (!keep_stdin) {
if (err < 0) {
r = EXIT_STDIN;
goto fail_child;
}
}
if (!keep_stdout) {
if (err < 0) {
r = EXIT_STDOUT;
goto fail_child;
}
}
if (err < 0) {
r = EXIT_STDERR;
goto fail_child;
}
if (cgroup_bondings) {
if (err < 0) {
r = EXIT_CGROUP;
goto fail_child;
}
}
if (context->oom_score_adjust_set) {
char t[16];
char_array_0(t);
if (write_one_line_file("/proc/self/oom_score_adj", t) < 0) {
/* Compatibility with Linux <= 2.6.35 */
int adj;
char_array_0(t);
if (write_one_line_file("/proc/self/oom_adj", t) < 0
r = EXIT_OOM_ADJUST;
goto fail_child;
}
}
}
r = EXIT_NICE;
goto fail_child;
}
if (context->cpu_sched_set) {
struct sched_param param;
r = EXIT_SETSCHEDULER;
goto fail_child;
}
}
r = EXIT_CPUAFFINITY;
goto fail_child;
}
if (context->ioprio_set)
r = EXIT_IOPRIO;
goto fail_child;
}
if (context->timer_slack_nsec_set)
r = EXIT_TIMERSLACK;
goto fail_child;
}
if (err < 0) {
r = EXIT_USER;
goto fail_child;
}
if (err < 0) {
r = EXIT_STDIN;
goto fail_child;
}
}
if (err >= 0)
err = cgroup_bonding_set_task_access_list(cgroup_bondings, 0644, uid, gid, context->control_group_persistent);
if (err < 0) {
r = EXIT_CGROUP;
goto fail_child;
}
set_access = true;
}
}
err = cgroup_bonding_set_task_access_list(cgroup_bondings, (mode_t) -1, (uid_t) -1, (uid_t) -1, context->control_group_persistent);
if (err < 0) {
r = EXIT_CGROUP;
goto fail_child;
}
}
if (apply_permissions) {
if (err < 0) {
r = EXIT_GROUP;
goto fail_child;
}
}
#ifdef HAVE_PAM
if (err < 0) {
r = EXIT_PAM;
goto fail_child;
}
}
#endif
if (context->private_network) {
if (unshare(CLONE_NEWNET) < 0) {
r = EXIT_NETWORK;
goto fail_child;
}
}
context->private_tmp) {
if (err < 0) {
r = EXIT_NAMESPACE;
goto fail_child;
}
}
if (apply_chroot) {
if (context->root_directory)
r = EXIT_CHROOT;
goto fail_child;
}
r = EXIT_CHDIR;
goto fail_child;
}
} else {
char *d;
if (asprintf(&d, "%s/%s",
r = EXIT_MEMORY;
goto fail_child;
}
if (chdir(d) < 0) {
free(d);
r = EXIT_CHDIR;
goto fail_child;
}
free(d);
}
/* We repeat the fd closing here, to make sure that
* nothing is leaked from the PAM modules */
if (err >= 0)
if (err >= 0)
if (err < 0) {
r = EXIT_FDS;
goto fail_child;
}
if (apply_permissions) {
for (i = 0; i < RLIMIT_NLIMITS; i++) {
continue;
r = EXIT_LIMITS;
goto fail_child;
}
}
if (context->capability_bounding_set_drop) {
if (err < 0) {
r = EXIT_CAPABILITIES;
goto fail_child;
}
}
if (err < 0) {
r = EXIT_USER;
goto fail_child;
}
}
/* PR_GET_SECUREBITS is not privileged, while
* PR_SET_SECUREBITS is. So to suppress
* potential EPERMs we'll try not to call
* PR_SET_SECUREBITS unless necessary. */
r = EXIT_SECUREBITS;
goto fail_child;
}
if (context->capabilities)
r = EXIT_CAPABILITIES;
goto fail_child;
}
}
r = EXIT_MEMORY;
goto fail_child;
}
if (n_fds > 0)
r = EXIT_MEMORY;
goto fail_child;
}
if (home)
r = EXIT_MEMORY;
goto fail_child;
}
if (username)
r = EXIT_MEMORY;
goto fail_child;
}
r = EXIT_MEMORY;
goto fail_child;
}
if (!(final_env = strv_env_merge(
5,
NULL))) {
r = EXIT_MEMORY;
goto fail_child;
}
r = EXIT_MEMORY;
goto fail_child;
}
r = EXIT_EXEC;
if (r != 0) {
log_open();
log_warning("Failed at step %s spawning %s: %s",
}
if (saved_stdin >= 0)
if (saved_stdout >= 0)
_exit(r);
}
/* We add the new process to the cgroup both in the child (so
* that we can be sure that no user code is ever executed
* outside of the cgroup) and in the parent (so that we can be
* sure that when we kill the cgroup the process will be
* killed too). */
if (cgroup_bondings)
return 0;
return r;
}
void exec_context_init(ExecContext *c) {
assert(c);
c->umask = 0022;
c->cpu_sched_policy = SCHED_OTHER;
c->syslog_level_prefix = true;
c->mount_flags = MS_SHARED;
c->kill_signal = SIGTERM;
c->send_sigkill = true;
c->control_group_persistent = -1;
c->ignore_sigpipe = true;
}
void exec_context_done(ExecContext *c) {
unsigned l;
assert(c);
strv_free(c->environment);
c->environment = NULL;
c->environment_files = NULL;
for (l = 0; l < ELEMENTSOF(c->rlimit); l++) {
}
free(c->working_directory);
c->working_directory = NULL;
free(c->root_directory);
c->root_directory = NULL;
free(c->tcpwrap_name);
c->tcpwrap_name = NULL;
free(c->syslog_identifier);
c->syslog_identifier = NULL;
c->supplementary_groups = NULL;
if (c->capabilities) {
cap_free(c->capabilities);
c->capabilities = NULL;
}
strv_free(c->read_only_dirs);
c->read_only_dirs = NULL;
strv_free(c->read_write_dirs);
c->read_write_dirs = NULL;
c->inaccessible_dirs = NULL;
if (c->cpuset)
}
void exec_command_done(ExecCommand *c) {
assert(c);
}
void exec_command_done_array(ExecCommand *c, unsigned n) {
unsigned i;
for (i = 0; i < n; i++)
exec_command_done(c+i);
}
void exec_command_free_list(ExecCommand *c) {
ExecCommand *i;
while ((i = c)) {
free(i);
}
}
void exec_command_free_array(ExecCommand **c, unsigned n) {
unsigned i;
for (i = 0; i < n; i++) {
exec_command_free_list(c[i]);
c[i] = NULL;
}
}
int exec_context_load_environment(const ExecContext *c, char ***l) {
char **i, **r = NULL;
assert(c);
assert(l);
STRV_FOREACH(i, c->environment_files) {
char *fn;
int k;
bool ignore = false;
char **p;
fn = *i;
if (fn[0] == '-') {
ignore = true;
fn ++;
}
if (!path_is_absolute(fn)) {
if (ignore)
continue;
strv_free(r);
return -EINVAL;
}
if ((k = load_env_file(fn, &p)) < 0) {
if (ignore)
continue;
strv_free(r);
return k;
}
if (r == NULL)
r = p;
else {
char **m;
m = strv_env_merge(2, r, p);
strv_free(r);
strv_free(p);
if (!m)
return -ENOMEM;
r = m;
}
}
*l = r;
return 0;
}
static void strv_fprintf(FILE *f, char **l) {
char **g;
assert(f);
STRV_FOREACH(g, l)
fprintf(f, " %s", *g);
}
char ** e;
unsigned i;
assert(c);
assert(f);
if (!prefix)
prefix = "";
fprintf(f,
"%sUMask: %04o\n"
"%sWorkingDirectory: %s\n"
"%sRootDirectory: %s\n"
"%sNonBlocking: %s\n"
"%sPrivateTmp: %s\n"
"%sControlGroupModify: %s\n"
"%sControlGroupPersistent: %s\n"
"%sPrivateNetwork: %s\n",
STRV_FOREACH(e, c->environment)
STRV_FOREACH(e, c->environment_files)
if (c->tcpwrap_name)
fprintf(f,
"%sTCPWrapName: %s\n",
prefix, c->tcpwrap_name);
if (c->nice_set)
fprintf(f,
"%sNice: %i\n",
if (c->oom_score_adjust_set)
fprintf(f,
"%sOOMScoreAdjust: %i\n",
prefix, c->oom_score_adjust);
for (i = 0; i < RLIM_NLIMITS; i++)
if (c->rlimit[i])
fprintf(f, "%s%s: %llu\n", prefix, rlimit_to_string(i), (unsigned long long) c->rlimit[i]->rlim_max);
if (c->ioprio_set)
fprintf(f,
"%sIOSchedulingClass: %s\n"
"%sIOPriority: %i\n",
if (c->cpu_sched_set)
fprintf(f,
"%sCPUSchedulingPolicy: %s\n"
"%sCPUSchedulingPriority: %i\n"
"%sCPUSchedulingResetOnFork: %s\n",
prefix, c->cpu_sched_priority,
if (c->cpuset) {
for (i = 0; i < c->cpuset_ncpus; i++)
fprintf(f, " %i", i);
fputs("\n", f);
}
if (c->timer_slack_nsec_set)
fprintf(f,
"%sStandardInput: %s\n"
"%sStandardOutput: %s\n"
"%sStandardError: %s\n",
if (c->tty_path)
fprintf(f,
"%sTTYPath: %s\n"
"%sTTYReset: %s\n"
"%sTTYVHangup: %s\n"
"%sTTYVTDisallocate: %s\n",
if (c->std_output == EXEC_OUTPUT_SYSLOG || c->std_output == EXEC_OUTPUT_KMSG || c->std_output == EXEC_OUTPUT_JOURNAL ||
c->std_output == EXEC_OUTPUT_SYSLOG_AND_CONSOLE || c->std_output == EXEC_OUTPUT_KMSG_AND_CONSOLE || c->std_output == EXEC_OUTPUT_JOURNAL_AND_CONSOLE ||
c->std_error == EXEC_OUTPUT_SYSLOG || c->std_error == EXEC_OUTPUT_KMSG || c->std_error == EXEC_OUTPUT_JOURNAL ||
c->std_error == EXEC_OUTPUT_SYSLOG_AND_CONSOLE || c->std_error == EXEC_OUTPUT_KMSG_AND_CONSOLE || c->std_error == EXEC_OUTPUT_JOURNAL_AND_CONSOLE)
fprintf(f,
"%sSyslogFacility: %s\n"
"%sSyslogLevel: %s\n",
if (c->capabilities) {
char *t;
fprintf(f, "%sCapabilities: %s\n",
prefix, t);
cap_free(t);
}
}
if (c->secure_bits)
fprintf(f, "%sSecure Bits:%s%s%s%s%s%s\n",
if (c->capability_bounding_set_drop) {
unsigned long l;
for (l = 0; l <= cap_last_cap(); l++)
char *t;
if ((t = cap_to_name(l))) {
fprintf(f, " %s", t);
cap_free(t);
}
}
fputs("\n", f);
}
if (c->user)
if (c->group)
if (strv_length(c->supplementary_groups) > 0) {
strv_fprintf(f, c->supplementary_groups);
fputs("\n", f);
}
if (c->pam_name)
if (strv_length(c->read_write_dirs) > 0) {
strv_fprintf(f, c->read_write_dirs);
fputs("\n", f);
}
if (strv_length(c->read_only_dirs) > 0) {
strv_fprintf(f, c->read_only_dirs);
fputs("\n", f);
}
if (strv_length(c->inaccessible_dirs) > 0) {
strv_fprintf(f, c->inaccessible_dirs);
fputs("\n", f);
}
fprintf(f,
"%sKillMode: %s\n"
"%sKillSignal: SIG%s\n"
"%sSendSIGKILL: %s\n"
"%sIgnoreSIGPIPE: %s\n",
if (c->utmp_id)
fprintf(f,
"%sUtmpIdentifier: %s\n",
}
assert(s);
zero(*s);
}
assert(s);
zero(*s);
if (context) {
}
}
char buf[FORMAT_TIMESTAMP_MAX];
assert(s);
assert(f);
if (!prefix)
prefix = "";
if (s->pid <= 0)
return;
fprintf(f,
"%sPID: %lu\n",
if (s->start_timestamp.realtime > 0)
fprintf(f,
"%sStart Timestamp: %s\n",
if (s->exit_timestamp.realtime > 0)
fprintf(f,
"%sExit Timestamp: %s\n"
"%sExit Code: %s\n"
"%sExit Status: %i\n",
}
char *exec_command_line(char **argv) {
size_t k;
char *n, *p, **a;
bool first = true;
k = 1;
STRV_FOREACH(a, argv)
k += strlen(*a)+3;
if (!(n = new(char, k)))
return NULL;
p = n;
STRV_FOREACH(a, argv) {
if (!first)
*(p++) = ' ';
else
first = false;
if (strpbrk(*a, WHITESPACE)) {
*(p++) = '\'';
p = stpcpy(p, *a);
*(p++) = '\'';
} else
p = stpcpy(p, *a);
}
*p = 0;
/* FIXME: this doesn't really handle arguments that have
* spaces and ticks in them */
return n;
}
char *p2;
const char *prefix2;
char *cmd;
assert(c);
assert(f);
if (!prefix)
prefix = "";
fprintf(f,
"%sCommand Line: %s\n",
}
assert(f);
if (!prefix)
prefix = "";
LIST_FOREACH(command, c, c)
exec_command_dump(c, f, prefix);
}
assert(l);
assert(e);
if (*l) {
/* It's kind of important, that we keep the order here */
} else
*l = e;
}
char **l, *p;
assert(c);
if (!l)
return -ENOMEM;
strv_free(l);
return -ENOMEM;
}
c->path = p;
c->argv = l;
return 0;
}
static const char* const exec_input_table[_EXEC_INPUT_MAX] = {
[EXEC_INPUT_NULL] = "null",
[EXEC_INPUT_TTY] = "tty",
[EXEC_INPUT_TTY_FORCE] = "tty-force",
[EXEC_INPUT_TTY_FAIL] = "tty-fail",
[EXEC_INPUT_SOCKET] = "socket"
};
static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = {
[EXEC_OUTPUT_INHERIT] = "inherit",
[EXEC_OUTPUT_NULL] = "null",
[EXEC_OUTPUT_TTY] = "tty",
[EXEC_OUTPUT_SYSLOG] = "syslog",
[EXEC_OUTPUT_SYSLOG_AND_CONSOLE] = "syslog+console",
[EXEC_OUTPUT_KMSG] = "kmsg",
[EXEC_OUTPUT_KMSG_AND_CONSOLE] = "kmsg+console",
[EXEC_OUTPUT_JOURNAL] = "journal",
[EXEC_OUTPUT_JOURNAL_AND_CONSOLE] = "journal+console",
[EXEC_OUTPUT_SOCKET] = "socket"
};
static const char* const kill_mode_table[_KILL_MODE_MAX] = {
[KILL_CONTROL_GROUP] = "control-group",
[KILL_PROCESS] = "process",
[KILL_NONE] = "none"
};
static const char* const kill_who_table[_KILL_WHO_MAX] = {
[KILL_MAIN] = "main",
[KILL_CONTROL] = "control",
[KILL_ALL] = "all"
};