1 /* SPDX-License-Identifier: GPL-2.0 */
3 /** \file exec.c Helper functions for spawning new processes. */
12 #include "gcc-compat.h"
19 * Spawn a new process using execvp().
21 * \param pid Will hold the pid of the created process upon return.
22 * \param file Path of the executable to execute.
23 * \param args The argument array for the command.
27 * \sa fork(2), exec(3).
29 void dss_exec(pid_t
*pid
, const char *file
, char *const *const args
)
31 if ((*pid
= fork()) < 0) {
32 DSS_EMERG_LOG(("fork error: %s\n", strerror(errno
)));
35 if (*pid
) /* parent */
37 signal(SIGINT
, SIG_DFL
);
38 signal(SIGTERM
, SIG_DFL
);
39 signal(SIGCHLD
, SIG_DFL
);
41 DSS_EMERG_LOG(("execvp error: %s\n", strerror(errno
)));
46 * Exec the command given as a command line.
48 * \param pid Will hold the pid of the created process upon return.
49 * \param cmdline Holds the command and its arguments, separated by spaces.
51 * This function uses fork/exec to create a new process.
55 void dss_exec_cmdline_pid(pid_t
*pid
, const char *cmdline
)
57 char **argv
, *tmp
= dss_strdup(cmdline
);
59 split_args(tmp
, &argv
);
60 dss_exec(pid
, argv
[0], argv
);