diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-01-26 12:10:49 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-01-26 12:10:49 +0200 |
commit | 97bf0329e974ea391f5f119e7256bf648889775c (patch) | |
tree | e72e45cf60b6a38a9b0a5d5b6c44783b99f347be | |
parent | dba0361eb509d3c9a633e05945378a204a4a0f4e (diff) | |
download | jumper-97bf0329e974ea391f5f119e7256bf648889775c.tar.gz jumper-97bf0329e974ea391f5f119e7256bf648889775c.tar.bz2 |
New execution option: "shell"
* doc/jumper.8in: Document new option.
* src/config.c (value_to_options): Rewrite. Handle the "shell"
keyword.
* src/jumper.h (OPT_SHELL): New option.
* src/progman.c (progman_start): Handle OPT_SHELL.
-rw-r--r-- | doc/jumper.8in | 19 | ||||
-rw-r--r-- | src/config.c | 30 | ||||
-rw-r--r-- | src/jumper.h | 1 | ||||
-rw-r--r-- | src/progman.c | 17 |
4 files changed, 45 insertions, 22 deletions
diff --git a/doc/jumper.8in b/doc/jumper.8in index 77c8cdc..1383c64 100644 --- a/doc/jumper.8in +++ b/doc/jumper.8in @@ -16,3 +16,3 @@ .so config.so -.TH JUMPER 8 "January 25, 2020" "JUMPER" +.TH JUMPER 8 "January 26, 2020" "JUMPER" .SH NAME @@ -481,2 +481,12 @@ A list of additional options. Currently the following options are defined: .TP +.B nullin +Do not close standard input. Redirect it from +.B /dev/null +instead. Use this option with commands that require their standard +input to be open (e.g. +.BR "pppd nodetach" ). +.TP +.B shell +Run command as "/bin/sh -c '$command'". +.TP .B stdout @@ -488,9 +498,2 @@ Capture the standard error of the command and redirect it to the \fBsyslog\fR with the \fBLOG_ERR\fR priority. -.TP -.B nullin -Do not close standard input. Redirect it from -.B /dev/null -instead. Use this option with commands that require their standard -input to be open (e.g. -.BR "pppd nodetach" ). .RE diff --git a/src/config.c b/src/config.c index 53d757d..f42c408 100644 --- a/src/config.c +++ b/src/config.c @@ -271,14 +271,22 @@ value_to_options(grecs_value_t *val, int *options) { - if (strcmp(val->v.string, "nowait") == 0) - *options |= OPT_NOWAIT; - else if (strcmp(val->v.string, "wait") == 0) - *options &= ~OPT_NOWAIT; - else if (strcmp(val->v.string, "stdout") == 0) - *options |= OPT_STDOUT; - else if (strcmp(val->v.string, "stderr") == 0) - *options |= OPT_STDERR; - else if (strcmp(val->v.string, "nullin") == 0) - *options |= OPT_NULLIN; - else +#define NEGATE 0x8000 + static struct transtab opttab[] = { + { "nowait", OPT_NOWAIT }, + { "wait", NEGATE | OPT_NOWAIT }, + { "stdout", OPT_STDOUT }, + { "stderr", OPT_STDERR }, + { "nullin", OPT_NULLIN }, + { "shell", OPT_SHELL }, + { NULL } + }; + int t; + + if (trans_strtotok(opttab, val->v.string, &t)) { grecs_error(&val->locus, 0, "unrecognized option"); + return; + } + if (t & NEGATE) + *options &= ~(t & ~NEGATE); + else + *options |= t; } diff --git a/src/jumper.h b/src/jumper.h index 448e8ef..c69d515 100644 --- a/src/jumper.h +++ b/src/jumper.h @@ -205,2 +205,3 @@ enum process_type { #define OPT_NULLIN 0x08 +#define OPT_SHELL 0x10 diff --git a/src/progman.c b/src/progman.c index b9a0f5f..4474b38 100644 --- a/src/progman.c +++ b/src/progman.c @@ -481,4 +481,3 @@ progman_start(int type, listener_t *lp, struct grecs_locus *loc, struct wordsplit ws; - int flags = WRDSF_NOCMD | WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | - WRDSF_CESCAPES; + int flags = WRDSF_NOCMD; @@ -488,2 +487,10 @@ progman_start(int type, listener_t *lp, struct grecs_locus *loc, } + + if (options & OPT_SHELL) { + ws.ws_offs = 2; + flags |= WRDSF_NOSPLIT | WRDSF_DOOFFS; + } else { + flags |= WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | + WRDSF_CESCAPES; + } @@ -495,2 +502,6 @@ progman_start(int type, listener_t *lp, struct grecs_locus *loc, } + if (options & OPT_SHELL) { + ws.ws_wordv[0] = "/bin/sh"; + ws.ws_wordv[1] = "-c"; + } @@ -503,3 +514,3 @@ progman_start(int type, listener_t *lp, struct grecs_locus *loc, grecs_txtacc_grow_string(acc, ws.ws_wordv[0]); - for (i = 1; i < ws.ws_wordc; i++) { + for (i = 1; i < ws.ws_wordc + ws.ws_offs; i++) { grecs_txtacc_grow_char(acc, ' '); |