mirror of
https://github.com/troglobit/finit.git
synced 2026-11-09 16:21:24 +00: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:
1 parent
442598282f
commit
684314db0f
4 files changed
+26
-1
No files matched your search
+21
@@ -213,6 +213,27 @@ int run_interactive(char *cmd, char *fmt, ...)
|
|||||||
return status;
|
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)
|
static void prepare_tty(char *tty, char *procname, int console)
|
||||||
{
|
{
|
||||||
/* Reset signal handlers that were set by the parent process */
|
/* 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 complete (char *cmd, int pid);
|
||||||
int run (char *cmd);
|
int run (char *cmd);
|
||||||
int run_interactive (char *cmd, char *fmt, ...);
|
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_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);
|
pid_t run_getty2 (char *tty, char *cmd, char *args[], int noclear, int nowait, int console);
|
||||||
int run_parts (char *dir, char *cmd);
|
int run_parts (char *dir, char *cmd);
|
||||||
|
|||||||
+3
-1
@@ -270,8 +270,10 @@ static int service_start(svc_t *svc)
|
|||||||
|
|
||||||
if (svc->inetd.cmd)
|
if (svc->inetd.cmd)
|
||||||
status = svc->inetd.cmd(svc->inetd.type);
|
status = svc->inetd.cmd(svc->inetd.type);
|
||||||
|
else if (svc->type & SVC_TYPE_RUNTASK)
|
||||||
|
status = exec_runtask(svc->cmd, args);
|
||||||
else
|
else
|
||||||
status = execv(svc->cmd, args); /* XXX: Maybe use execve() to be able to launch scripts? */
|
status = execv(svc->cmd, args);
|
||||||
|
|
||||||
#ifdef INETD_ENABLED
|
#ifdef INETD_ENABLED
|
||||||
if (svc_is_inetd_conn(svc)) {
|
if (svc_is_inetd_conn(svc)) {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ typedef enum {
|
|||||||
} svc_type_t;
|
} svc_type_t;
|
||||||
|
|
||||||
#define SVC_TYPE_ANY (-1)
|
#define SVC_TYPE_ANY (-1)
|
||||||
|
#define SVC_TYPE_RUNTASK (6)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SVC_HALTED_STATE = 0, /* Not allowed in runlevel, or not enabled. */
|
SVC_HALTED_STATE = 0, /* Not allowed in runlevel, or not enabled. */
|
||||||
|
|||||||
Reference in new issue
Block a user