2 * Copyright (C) 2003-2011 Andre Noll <maan@tuebingen.mpg.de>
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"
23 * Spawn a new process using execvp().
25 * \param pid Will hold the pid of the created process upon return.
26 * \param file Path of the executable to execute.
27 * \param args The argument array for the command.
31 * \sa fork(2), exec(3).
33 void dss_exec(pid_t *pid, const char *file, char *const *const args)
35 if ((*pid = fork()) < 0) {
36 DSS_EMERG_LOG(("fork error: %s\n", strerror(errno)));
39 if (*pid) /* parent */
41 signal(SIGINT, SIG_DFL);
42 signal(SIGTERM, SIG_DFL);
43 signal(SIGCHLD, SIG_DFL);
45 DSS_EMERG_LOG(("execvp error: %s\n", strerror(errno)));
50 * Exec the command given as a command line.
52 * \param pid Will hold the pid of the created process upon return.
53 * \param cmdline Holds the command and its arguments, seperated by spaces.
55 * This function uses fork/exec to create a new process.
59 void dss_exec_cmdline_pid(pid_t *pid, const char *cmdline)
61 char **argv, *tmp = dss_strdup(cmdline);
63 split_args(tmp, &argv, " \t");
64 dss_exec(pid, argv[0], argv);