Allow pipe + redirect in task/run stanzas, exec() in /bin/sh

This patch extends the capabilities of task and run .conf stanzas by
enabling pipes and redirects.

Example:

    task [s] echo "foo" | cat >/tmp/bar
    run  [s] echo "$HOME" >/tmp/secret

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-09-04 16:00:49 +02:00
parent 442598282f
commit 684314db0f
4 changed files with 26 additions and 1 deletions
+21
View File
@@ -213,6 +213,27 @@ int run_interactive(char *cmd, char *fmt, ...)
return status;
}
int exec_runtask(char *cmd, char *args[])
{
size_t i;
char buf[1024] = "";
char *argv[4] = {
"sh",
"-c",
buf,
NULL
};
for (i = 0; args[i]; i++) {
strlcat(buf, args[i], sizeof(buf));
if (args[i + 1])
strlcat(buf, " ", sizeof(buf));
}
logit(LOG_DEBUG, "Calling %s %s", _PATH_BSHELL, buf);
return execve(_PATH_BSHELL, argv, __environ);
}
static void prepare_tty(char *tty, char *procname, int console)
{
/* Reset signal handlers that were set by the parent process */
+1
View File
@@ -63,6 +63,7 @@ void set_hostname (char **hostname);
int complete (char *cmd, int pid);
int run (char *cmd);
int run_interactive (char *cmd, char *fmt, ...);
int exec_runtask (char *cmd, char *args[]);
pid_t run_getty (char *tty, char *speed, char *term, int noclear, int nowait, int console);
pid_t run_getty2 (char *tty, char *cmd, char *args[], int noclear, int nowait, int console);
int run_parts (char *dir, char *cmd);
+3 -1
View File
@@ -270,8 +270,10 @@ static int service_start(svc_t *svc)
if (svc->inetd.cmd)
status = svc->inetd.cmd(svc->inetd.type);
else if (svc->type & SVC_TYPE_RUNTASK)
status = exec_runtask(svc->cmd, args);
else
status = execv(svc->cmd, args); /* XXX: Maybe use execve() to be able to launch scripts? */
status = execv(svc->cmd, args);
#ifdef INETD_ENABLED
if (svc_is_inetd_conn(svc)) {
+1
View File
@@ -45,6 +45,7 @@ typedef enum {
} svc_type_t;
#define SVC_TYPE_ANY (-1)
#define SVC_TYPE_RUNTASK (6)
typedef enum {
SVC_HALTED_STATE = 0, /* Not allowed in runlevel, or not enabled. */