aboutsummaryrefslogtreecommitdiff
path: root/jim-exec.c
AgeCommit message (Collapse)AuthorFilesLines
2016-03-27exec: Fix a warning on mingwSteve Bennett1-1/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-03-27exec: Avoid lstrcpyn on windows and just use snprintf()Steve Bennett1-2/+1
2016-03-27exec: read output from pipe before waiting for childrenSteve Bennett1-10/+9
It is necessary to read output from the pipe before waiting for children to exit to avoid the output filling up and blocking. The error results still needs to be read after the children have exited, since it is read from a temp file, not a pipe. Increase the length of the input to test exec-8.1 to catch the problem. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-01-29exec: Fix race condition in collecting err outputSteve Bennett1-20/+38
Fix a race condition in [exec] where stdout and stderr are read without waiting until all child processes have exited. This meant that the following may capture no stderr output. exec >@stdout command-with-stderr Signed-off-by: Steve Bennett <steveb@workware.net.au>
2015-03-12exec: better handling of pipeline abnormal terminationSteve Bennett1-50/+75
Consider the command pipeline: exec a | b | c Previously, if any of the subcommands terminated abnormally (with a signal), the stdout of the pipeline would be lost. Now the output consists of: 1. standard output from the last command in the pipeline 2. standard error from all commands in the pipeline 3. all abnormal error terminations, if any - but suppressed if any standard error output In addition, $::errorCode previously always contained the termination status of the last subcommand, even if it succeeded. Now it contains the termination status of the last subcommand that failed, or "NONE" if all succeeded. Additionally, the order of $::errorCode was previously wrong, with pid after the signal id rather than vice versa. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-09-18exec: simplify tempfile error msg handlingSteve Bennett1-11/+9
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-08-03Temporary file creation should respect $TMPDIRSteve Bennett1-5/+3
This applies to [exec] and [file tempfile] Reported-by: Jakub Wilk Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-04-28exec, file: set umask before mkstempSteve Bennett1-1/+3
Set umask so that temp files are created with permissions 0600. Courtesy of coverity. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-21many comment changes, some small code changesSteve Bennett1-30/+17
Sweep through and clean up all (most) of the comments in the code. While there, adjust some variable and function names to be more consistent, and make a few small code changes - again, mostly for consistency. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-15exec: better handling of SIGPIPESteve Bennett1-12/+19
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-15exec: fix reaping of detached processesSteve Bennett1-5/+11
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-15exec: remove duplicate codeSteve Bennett1-18/+5
Two versions of the "trim trailing space" function Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-15exec: respect $::env even without tclcompatSteve Bennett1-6/+0
Otherwise there is no way to affect the environment for exec Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-03Remove tabs from source filesSteve Bennett1-1/+1
Tabs accidentally crept into source files in violaton of the style guide Signed-off-by: Steve Bennett <steveb@workware.net.au>
2013-11-07Fix jim-exec.c compiler warnings on mingwSteve Bennett1-7/+5
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2013-08-19Support nulls in [exec] immediate redirectionSteve Bennett1-9/+10
e.g. exec prog <<$data Signed-off-by: Steve Bennett <steveb@workware.net.au>
2012-10-10Fix bug that was causing the system "environ" variable to be freed, which ↵Evan Hunter1-1/+1
caused mayhem in stdio etc.
2012-01-29Space allocated for exec env may be one byte shortSteve Bennett1-3/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au> Reported-by: af123 <jimdevel@hummypkg.org.uk>
2011-12-16use execvpe if available in [exec]Steve Bennett1-1/+5
On cygwin, setting environ before execvp() doesn't work, but execvpe() does exist and works, so use that in preference Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-12-01Ref count fix in execSteve Bennett1-11/+16
Passing a zero refcount object to Jim_AioFilename() is a bad idea. If the implementation changes, the object may be freed twice. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-11-24Create build-jim-ext for building extensionsSteve Bennett1-1/+1
Simplifies the process of building loadable extensions Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-11-07Allow building with MSVC on windowsSteve Bennett1-3/+6
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-09-13exec was not removing temp filesSteve Bennett1-1/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-09-12Implement full [exec] on mingw/msysSteve Bennett1-253/+750
This also involves some restructuring of the existing implementation to allow for as much reuse as possible. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-07-22Fix an instance of declaration after codeSteve Bennett1-3/+3
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-07-07Minor code cleanupsSteve Bennett1-9/+10
Some unused variables Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-06-09Better handling of environ on Mac OS XSteve Bennett1-8/+6
Shared libraries can't access environ directly, so use _NSGetEnviron() on Mac OS X Also, load modules with (RTLD_NOW | RTLD_LOCAL) instead of RTLD_LAZY Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-06-09Provide a fallback basic [exec] for (e.g.) mingw32Steve Bennett1-5/+68
Use system() to implement [exec] if vfork() and waitpid() are not available. This is just functional enough for simple tasks. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-06-03Fix some clang warningsSteve Bennett1-1/+7
And also a potentially undefined integer left shift Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-06-01Add Jim_String() macroSteve Bennett1-4/+4
It is very common to get the string value without the length. Jim_String() is a macro which does that. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-05-27Ensure detached child processes are reapedSteve Bennett1-131/+57
Like Tcl, reap zombies on each exec invocation. This commit also simplifies the implementation of exec by using waitpid(). Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-05-18Fix memory leak on exec argument errorSteve Bennett1-8/+7
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-12-15Use vfork() instead of fork() in [exec]Steve Bennett1-232/+87
This allows systems with vfork() but not fork() to have a full exec implementation, including constructs such as 2>@1 and background exec with & Also remove the --disable-fork option. It doesn't really make sense now since exec uses vfork Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-11-17Add attributions to jim-exec.c from Tcl 6.7Steve Bennett1-1/+6
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-11-09Allow jim to be used as an autoconf subdirSteve Bennett1-0/+1
Ensure that no public headers include the autoconf header, jimautoconf.h, as it leads to problems with redefined symbols. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-30Add 'info channels'Steve Bennett1-9/+0
Like 'chan names' from Tcl Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Add stubs in case of compiled-out package, aioSteve Bennett1-0/+9
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Make jim more reentrantSteve Bennett1-61/+87
Make the exec wait table allocated and per-interpeter Use reentrant variants of some libc calls Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Ensure that Tcl extensions can be built-in or externalSteve Bennett1-0/+3
All C extensions must call Jim_PackageProvide() make-c-ext ensures that Tcl extensions call Jim_PackageProvide() if compiled in. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Use $::env to build environment for execSteve Bennett1-12/+137
Also, switch to using 'sh -c' for the vfork() implementation because it then allows command line redirection, pipes and setting the environment. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Clean up some debuggingSteve Bennett1-1/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Reduce excessive stack usageSteve Bennett1-1/+0
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Set $::errorCode from execSteve Bennett1-11/+38
This allows the return code from a failed 'exec' command to be retrieved. Also support -errorcode in catch and return. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Clean up the indentation messSteve Bennett1-105/+114
Use 'indent'. Not perfect, but at least consistent. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Fix exec with vfork()Steve Bennett1-59/+66
Including the --disable-fork case And fix some compiler warnings Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Improvements to jim configureSteve Bennett1-3/+4
Create and use config.h Check for backtrace, fork, vfork, syslog, regcomp and others Disable extensions which require missing functions/features Check for one arg vs. two arg mkdir() Distinguish between mingw and native windows The aio extension has reduced functionality for ANSI C only Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Improvements to catch, return, signal, trySteve Bennett1-1/+6
Improve the ability to rethrow errors * Allow return to rethrow an error by accepting '-errorinfo stacktrace' * Also, 'catch ... opts' now also stores opts(-errorinfo) on error * Use these to provide better stack traces from 'case' and 'try' * Implement 'return -level' Make try/on/finally more Tcl 8.6 compatible * With support for 'on' handlers and docs Add support for catch options to try * Otherwise it's hard to use try to catch signals Improvements to signal handling * catch -signal now sets a list of the handled signals as the result * catch -signal won't execute the body at all if a handled signal is pending * up to 64 (jim_wide) signals can now be handled * if catch -signal is nested, the innermost catch will catch the error * new 'signal catch' allows ignored/blocked signals to be examined and cleared. * update docs on signal handling exec should indicate which signal killed the child Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Fix some build problems and add lost featuresSteve Bennett1-2/+2
Add some missing files needed for autoconf Make jim build standalone and without host jimsh Use (FILE *) for eventloop file handle Don't expect to support dynlib if no mmu Re-add nvp and win32 support (untested) Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Add exec support for 2>@1Steve Bennett1-7/+19
See TIP #202: http://www.tcl.tk/cgi-bin/tct/tip/202.html
2010-10-15Add Jim_SetResultFormatted() for simplied messagesSteve Bennett1-10/+5
Makes creating error messages much simpler Also convert a couple of long if/else to switch Also some error message improvements Also fix some memory leaks