execute.c revision f8b69d1dfc307562a353f6aa923b7c2b915aaddb
/*-*- 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>
#include <linux/seccomp-bpf.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"
#include "syscall-list.h"
#include "sd-id128.h"
#include "sd-messages.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, const char *unit_id, 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"
"%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,
(usec_t) -1)) < 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, const char *unit_id, 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, const char *unit_id, 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;
}
static int setup_confirm_stdio(int *_saved_stdin,
int *_saved_stdout) {
if (saved_stdin < 0)
return -errno;
if (saved_stdout < 0) {
r = errno;
goto fail;
}
false,
false,
false,
if (fd < 0) {
r = fd;
goto fail;
}
if (r < 0)
goto fail;
r = -errno;
goto fail;
}
r = -errno;
goto fail;
}
if (fd >= 2)
return 0;
fail:
if (saved_stdout >= 0)
if (saved_stdin >= 0)
if (fd >= 0)
return r;
}
static int write_confirm_message(const char *format, ...) {
int fd;
if (fd < 0)
return fd;
return 0;
}
static int restore_confirm_stdio(int *saved_stdin,
int *saved_stdout) {
int r = 0;
if (*saved_stdin >= 0)
r = -errno;
if (*saved_stdout >= 0)
r = -errno;
if (*saved_stdin >= 0)
if (*saved_stdout >= 0)
return r;
}
char *line;
if (r < 0)
return r;
if (!line)
return -ENOMEM;
return r;
}
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
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] = '(';
}
static const struct sock_filter header[] = {
};
static const struct sock_filter footer[] = {
};
int i;
unsigned n;
struct sock_filter *f;
struct sock_fprog prog;
/* First: count the syscalls to check for */
for (i = 0, n = 0; i < syscall_max(); i++)
n++;
/* Second: build the filter program from a header the syscall
* matches and the footer */
for (i = 0, n = 0; i < syscall_max(); i++)
struct sock_filter item[] = {
};
n++;
}
/* Third: install the filter */
return -errno;
return 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,
const char *unit_id,
int idle_pipe[2],
int r;
char *line;
int socket_fd;
if (n_fds != 1)
return -EINVAL;
n_fds = 0;
} else
socket_fd = -1;
if (r < 0) {
"UNIT=%s", unit_id,
"MESSAGE=Failed to load environment files: %s", strerror(-r),
"ERRNO=%d", -r,
NULL);
return r;
}
if (!argv)
if (!line)
return log_oom();
"UNIT=%s", unit_id,
"MESSAGE=About to execute %s", line,
NULL);
if (r < 0)
return r;
if (pid < 0)
return -errno;
if (pid == 0) {
int i, err;
unsigned n_env = 0;
bool set_access = false;
/* 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;
}
}
}
if (confirm_spawn) {
char response;
write_confirm_message("Confirmation question timed out, assuming positive response.\n");
else if (err < 0)
write_confirm_message("Couldn't ask confirmation question, assuming positive response: %s\n", strerror(-err));
else if (response == 's') {
write_confirm_message("Skipping execution.\n");
r = EXIT_CONFIRM;
goto fail_child;
} else if (response == 'n') {
write_confirm_message("Failing execution.\n");
err = r = 0;
goto fail_child;
}
}
* must sure to drop O_NONBLOCK */
if (socket_fd >= 0)
fd_nonblock(socket_fd, false);
if (err < 0) {
r = EXIT_STDIN;
goto fail_child;
}
err = setup_output(context, socket_fd, path_get_file_name(command->path), unit_id, apply_tty_stdin);
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) {
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;
}
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->mount_flags != 0 ||
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 _cleanup_free_ *d = NULL;
if (asprintf(&d, "%s/%s",
r = EXIT_MEMORY;
goto fail_child;
}
if (chdir(d) < 0) {
r = EXIT_CHDIR;
goto fail_child;
}
}
/* 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;
}
if (context->no_new_privileges)
goto fail_child;
}
if (context->syscall_filter) {
if (err < 0) {
r = EXIT_SECCOMP;
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();
"MESSAGE=Failed at step %s spawning %s: %s",
"ERRNO=%d", -err,
NULL);
log_close();
}
_exit(r);
}
"UNIT=%s", unit_id,
"MESSAGE=Forked %s as %lu",
NULL);
/* 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;
}
void exec_context_init(ExecContext *c) {
assert(c);
c->umask = 0022;
c->cpu_sched_policy = SCHED_OTHER;
c->syslog_level_prefix = 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)
free(c->syscall_filter);
c->syscall_filter = NULL;
}
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"
"%sIgnoreSIGPIPE: %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) {
char *class_str;
int r;
if (r < 0)
fprintf(f,
"%sIOSchedulingClass: %s\n"
"%sIOPriority: %i\n",
}
if (c->cpu_sched_set) {
char *policy_str;
int r;
if (r < 0)
policy_str = NULL;
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);
}
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) {
int r;
if (r < 0)
if (r < 0)
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);
}
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"
};