mirror of
https://github.com/troglobit/finit.git
synced 2026-10-11 17:02:42 +07:00
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:
+21
@@ -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 */
|
||||
|
||||
@@ -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
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user