diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-10-16 07:12:00 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-10-16 07:12:00 -0700 |
commit | adeabf115e33a3a2efdf04c6a33fdebccb876ce9 (patch) | |
tree | b7209384dcd22d915d9010cce40a851625dfb249 | |
parent | 7fa76b06632628882ca214b4cf1fb4c2106f2c7b (diff) | |
download | txr-adeabf115e33a3a2efdf04c6a33fdebccb876ce9.tar.gz txr-adeabf115e33a3a2efdf04c6a33fdebccb876ce9.tar.bz2 txr-adeabf115e33a3a2efdf04c6a33fdebccb876ce9.zip |
Remove use of the system function.
System depends on environment variables, and also causes
SIGINT and SIGQUIT to be ignored.
* stream.c (sh): Function rewritten in terms of sh,
in two platform variants.
* txr.1: Documented that sh doesn't use system as of TXR 120.
-rw-r--r-- | stream.c | 29 | ||||
-rw-r--r-- | txr.1 | 25 |
2 files changed, 35 insertions, 19 deletions
@@ -3037,21 +3037,6 @@ val open_process(val name, val mode_str, val args) } #endif -static val sh(val command) -{ - char *cmd = utf8_dup_to(c_str(command)); - int status = system(cmd); - if (status < 0) - return nil; -#if HAVE_SYS_WAIT - if (WIFEXITED(status)) { - int exitstatus = WEXITSTATUS(status); - return num(exitstatus); - } -#endif - return status == 0 ? zero : nil; -} - #if HAVE_FORK_STUFF static val run(val name, val args) { @@ -3102,6 +3087,11 @@ static val run(val name, val args) return status == 0 ? zero : nil; } } + +static val sh(val command) +{ + return run(lit("/bin/sh"), list(lit("-c"), command, nao)); +} #elif HAVE_WSPAWN static val run(val command, val args) { @@ -3126,12 +3116,13 @@ static val run(val command, val args) return (status < 0) ? nil : num(status); } -#else -static val run(val command, val args) + +static val sh(val command) { - val win_cmdline = win_make_cmdline(cons(command, default_bool_arg(args))); - return sh(win_cmdline); + return run(lit("cmd.exe"), list(lit("/C"), command, nao)); } +#else +#error port me! #endif val remove_path(val path) @@ -32561,6 +32561,31 @@ value from the failed .code exec attempt. +Note: as of \*(TX 120, the +.code sh +function is implemented using +.code run +and not by means of the +.code system +C library function, as previously. The +.code run +function is used to invoke the system interpreter by name. On Unix-like +systems, the string +.code /bin/sh +is assumed to denote the system interpreter, which is expected to +support a pair of arguments +.cblk +.meti -c < command +.cble +to specify the command to be executed. On MS Windows, the interpreter +is assumed to be the relative path name +.code cmd.exe +and expected to support +.cblk +.meti /C < command +.cble +as a way of specifying a command to execute. + .SS* Unix Filesystem Manipulation .coNP Structure @ stat |