aboutsummaryrefslogtreecommitdiff
path: root/jim-exec.c
AgeCommit message (Collapse)AuthorFilesLines
2023-07-04aio: change to use unix io, not stdioSteve Bennett1-10/+5
This changes especially makes buffered I/O work with non-blocking channels. - separate read and write buffering - support for timeout on blocking read - read/write on same channel in event loop with buffering - read buffer is the same across read, gets, copyto - autoflush non-blocking writes via event loop - copyto can now copy to any filehandle-like command - add some copyto tests Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-03-20build: define _GNU_SOURCE only on the command lineSteve Bennett1-3/+0
Not in source files See https://ariadne.space/2021/12/21/stop-defining-feature-test-macros-in-your-code/ Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-13build: fix warning on WindowsSteve Bennett1-1/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-03Convert some errant malloc/free to Jim_Alloc()/Jim_Free()Steve Bennett1-1/+1
Go through the Jim versions where it makes sense so we can add debugging or other features as required. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-01build: fix a minor warning on macosxSteve Bennett1-1/+3
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-08-21build: minor windows build fixesSteve Bennett1-0/+2
ifdef out some unix-only code so that we don't get compiler complaints on Windows. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-08-20build: macos has deprecated vfork()Steve Bennett1-1/+5
On platforms where using vfork emits a warning, use fork instead Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-05-08wait: fix support for wait -1Steve Bennett1-0/+6
Only on unix systems. Does waitpid(-1, ...) to wait for any child process to exit. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-04-14win32: Fix process handle vs pid distinctionSteve Bennett1-52/+56
On win32, a process is identified by a HANDLE, but for identifying a running process we should use GetProcessId() to return a meaningful integer. This means we need to be able to back and forth between a pid and a process handle (phandle). We also need to be careful to get the pid before the process handle closes since it isn't available afterwards. Also call the handle to intptr_t for open_osfhandle() to avoid a compiler warning. Fixes #217 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-07-02exec: support stdin fd being closedSteve Bennett1-3/+3
Don't try to dup2() a file descriptor that is already correct. This can happen if, for example, stdin is closed and exec redirects stdin from a file, thus opening the input as file descriptor 0. Fixes #201 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-10package: add ABI version checkingSteve Bennett1-5/+3
jim.h now includes JIM_ABI_VERSION that should be incremented whenever the ABI changes. Then all loadable modules should call Jim_CheckAbiVersion() to make sure they are loaded against the correct version. Add Jim_PackageProvideCheck() that does both Jim_CheckAbiVersion() and Jim_PackageProvide() to simplify the implementation of loadable extensions. Also rename the "big" sqlite3 extension to just sqlite to avoid a naming conflict with the smaller jim-sqlite3 extension. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04exec: remove useless initialisationSteve Bennett1-3/+0
numPids is always zero here so the code does nothing Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-02-18exec: fix valgrind warning on close(-1)Antonio Borneo1-2/+2
When executing "exec.test" under valgrind, it reports several warning messages Warning: invalid file descriptor -1 in syscall close() Add proper check around close() Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
2019-09-06exec: Don't force SIGPIPE to be enabledSteve Bennett1-17/+0
Previously SIGPIPE was set to SIG_DFL before vfork so that child processes always had SIGPIPE enabled. This makes it impossible to disable SIGPIPE for child processes. So don't do this. Instead allow the disposition of SIGPIPE to be handled by the 'signal' command. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-09exec: Finally get the environ rightSteve Bennett1-3/+7
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-08exec: Fix environment for windowsSteve Bennett1-4/+3
The incorrect environment was used in 8f7471a0f Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-08exec: Better adhere to possible vfork restrictionsSteve Bennett1-11/+40
Avoid modification of any variables on the parents stack. Avoid use of stdio in the event that execve fails. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-08remove some unused variable assignmentsSteve Bennett1-1/+0
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-10-21doc: Update remaining references to os.waitSteve Bennett1-1/+1
Now simply 'wait' Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-10-17signal, exec, wait, pid: improvements, especially to execSteve Bennett1-523/+316
- fix popen [open "|pipeline ..."] to return meaningful status in close (but note that stderr is not captured) - popen pipelines can now be used as the target of exec redirection - overally improvements to exec on windows. Now crt file descriptors are used throughout - add support for [pid], [wait] and popen on windows - os.wait is now wait, and integrates with [exec ... &] to be able to wait for running background tasks - [socket pipe] is now also [pipe] and is supported on windows - [file tempfile] is supported on windows - move duplicated code between jim-aio.c and jim-exec.c to jimiocompat.c - Fix [exec] on windows to match unix semantics wrt sharing the parent stream unless redirected rather than using /dev/null - On windows redirect to or from /dev/null is automatically converted to NUL: - If signal support is disabled, implement a minimal Jim_SignalId() for exec and wait - aio now supports getfd, to return the underlying file descriptor. This is used by exec to support redirection, and allows popen channels to support exec redirection. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-12exec: Fix check for | and |&Steve Bennett1-4/+5
These are only allowed as separate args. One check was allowing them as a prefix which could lead to an invalid memory access Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-12exec: Validate that a command is givenSteve Bennett1-0/+6
Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-10-09exec: Fix windows exec with empty or unset envSteve Bennett1-5/+32
Reported-by: Evan Hunter <evan@ozhiker.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-10-09Avoid re-defining _GNU_SOURCEEvan Hunter1-0/+2
pkgconfig for SDL causes _GNU_SOURCE to be defined on the commandline, hence causing an error when these source files re-define it.
2016-10-06jim-exec: use exec false on failed exec in --maintainer modeSteve Bennett1-0/+7
Keeps valgrind happy Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-10-02exec: ensure closed fd is -1Steve Bennett1-0/+1
Reported-by: Evan Hunter <evan@ozhiker.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-08-29jim-exec.c: Seek with SetFilePointer for appendingDanyil Bohdan1-1/+5
The credit goes to @msteveb for finding this difference between [exec] in Tcl 8.6 and Jim.
2016-08-29exec: On win32, use FILE_ATTRIBUTE_NORMAL with CreateFile()Steve Bennett1-2/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-08-17Don't unconditionally define _GNU_SOURCESteve Bennett1-0/+1
Also, fix build if JIM_OPTIMIZATION is disabled Signed-off-by: Steve Bennett <steveb@workware.net.au>
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>