2 * Copyright (C) 2003-2011 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file exec.c Helper functions for spawning new processes. */
16 #include "gcc-compat.h"
22 * Spawn a new process using execvp().
24 * \param pid Will hold the pid of the created process upon return.
25 * \param file Path of the executable to execute.
26 * \param args The argument array for the command.
30 * \sa fork(2), exec(3).
32 void dss_exec(pid_t *pid, const char *file, char *const *const args)
34 if ((*pid = fork()) < 0) {
35 DSS_EMERG_LOG("fork error: %s\n", strerror(errno));
38 if (*pid) /* parent */
40 signal(SIGINT, SIG_DFL);
41 signal(SIGTERM, SIG_DFL);
42 signal(SIGCHLD, SIG_DFL);
44 DSS_EMERG_LOG("execvp error: %s\n", strerror(errno));
49 * Exec the command given as a command line.
51 * \param pid Will hold the pid of the created process upon return.
52 * \param cmdline Holds the command and its arguments, seperated by spaces.
54 * This function uses fork/exec to create a new process.
58 void dss_exec_cmdline_pid(pid_t *pid, const char *cmdline)
60 char **argv, *tmp = dss_strdup(cmdline);
62 split_args(tmp, &argv, " \t");
63 dss_exec(pid, argv[0], argv);