Commit Graph

139 Commits

Author SHA1 Message Date
Saúl Ibarra Corretgé
edcf04d5b1 test: spawn child replacing std{out,err} to stderr
Refs: https://github.com/libuv/libuv/pull/224

PR-URL: https://github.com/libuv/libuv/pull/309
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-04-10 15:11:14 +02:00
Ryan Phillips
3616e61439 unix: reap child on execvp() failure
Reap the forked process when execvp() fails.  Fixes leaking zombie child
processes.

PR-URL: https://github.com/libuv/libuv/pull/274
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-18 17:11:39 +01:00
cjihrig
e5bdea8ed6 test: use modified path in test
The Windows spawn_with_an_odd_path test builds a PATH variable that
starts with ";.;". However, the old path is then used to run the test.
This commit updates the test to use the new path.

PR: https://github.com/libuv/libuv/pull/184
Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-02-05 22:50:09 +01:00
Luis Martinez de Bartolome
60b581fb5a test: fix test-spawn on MinGW32
PR-URL: https://github.com/libuv/libuv/pull/161
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-27 11:35:53 +01:00
Ben Noordhuis
393c1c59a2 unix: set non-block mode in uv_{pipe,tcp,udp}_open
The contract specifies that the file descriptor should already be in
non-blocking mode before passing it to libuv.

However, node users don't really have an opportunity to do so, never
mind the fact that the call to uv_pipe_open() or uv_tcp_open() is an
implementation detail that most users won't be aware of.

Let's be nice and set the non-blocking flag explicitly.  It's a cheap
operation anyway.

Fixes: https://github.com/libuv/libuv/issues/124

PR: https://github.com/libuv/libuv/pull/134
Reviewed-by: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-14 19:46:54 +01:00
Ben Noordhuis
9141f48ea5 test: fix spawn test with autotools build
Fix spawn_reads_child_path when executed as `test/run-tests` or
`make check`:

1. `make check` builds a dynamic libuv.so or libuv.dyld by default.

2. spawn_reads_child_path spawns a new instance of the test runner
   by consulting uv_exepath() and executing the result.

3. `test/run-tests` is normally a shell script that sets up
   DYLD_LIBRARY_PATH or LD_LIBRARY_PATH before executing the
   real test runner in `test/.libs`.

4. uv_exepath() (corectly) returns the path of the binary in
   `test/.libs`.  The binary is linked against libuv.so but that
   library is not on any of the default linker paths; and if it is,
   it's almost certainly the wrong version.

5. Ergo, carry over the value of the (DY)LD_LIBRARY_PATH environment
   variable into the environment of the child process so that the
   dynamic linker knows where to find the library.

Alternatively, we could link the test runner statically against libuv.a
but that breaks `make check` when configured with `--disable-static`.

Fixes: https://github.com/libuv/libuv/issues/85
PR-URL: https://github.com/libuv/libuv/pull/91
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-28 22:51:05 +01:00
Saúl Ibarra Corretgé
9c8e971443 test: fix compilation warnings when building with Clang
warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]

PR-URL: https://github.com/libuv/libuv/pull/67
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-13 20:57:43 +01:00
Saúl Ibarra Corretgé
86fcc20f96 test: skip spawn_setuid_setgid if we get EACCES
More often than not, users run the test suite from /root, which means
the 'nobody' user won't be able to access the test runner and the test
will fail because we drop privileges to that user. Just skip it then.

PR-URL: https://github.com/libuv/libuv/pull/66
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-12 13:52:50 +01:00
Saúl Ibarra Corretgé
09cb5b534e test: fix spawn_reads_child_path when using autoconf
Don't hardcode the name of the executable, take it from the exepath.

Fixes #1407
2014-08-10 11:25:28 +02:00
Alex Crichton
c7e4b31444 windows: read the PATH env var of the child
The unix and windows process implementations diverge in their behavior
when dealing with subprocesses that are spawned with a relative path.
With unix the *child's* PATH environment variable is read, whereas
with windows the *parent's* environment variable is read.

This commit brings the two implementation in line with respect to
their behavior of reading PATH by having both read the *child's* PATH
environment variable. This involves looking into the user-provided
environment on windows and extracting the PATH variable specifically
so it can be inspected later on.
2014-08-06 02:12:44 +02:00
Jameson Nash
8db42383ad windows: sort environment variables before calling CreateProcess 2014-08-01 09:26:21 +02:00
Ryan Cole
907b55e4bf process: adjust quote_cmd_arg for empty arguments
adjust quote_cmd_arg so that empty command line
arguments are double quoted instead of skipped
2014-05-12 23:55:58 +02:00
Rasmus Pedersen
cd6e74dd80 test: fix compilation warnings with VC++
C6011 and C4244
2014-04-17 17:31:11 +02:00
Fedor Indutny
69f9f6ffef test: fix EPIPE race in spawn_closed_process_io
The just created stdin should not be closed by a child process before
writing to it, otherwise EPIPE happens.
2014-04-11 18:24:48 +02:00
Alex Crichton
deff0e3571 test: Close process handles when spawn fails
This should avoid assertions tripping in debug mode.
2014-04-10 07:29:31 -07:00
Alex Crichton
621c4a3929 windows: Fix an infinite loop in uv_spawn
The PATH-parsing code for windows erroneously contained an infinite
loop when the PATH started with a leading semicolon. Each iteration of
the loop usually bumped over the separator, but if the first character
was a semicolon then it would never skip it, causing the infinite
loop.

Closes #909
2014-04-10 07:29:24 -07:00
Saúl Ibarra Corretgé
d1ac594480 mingw: fix build with autotools 2014-04-03 09:56:16 +02:00
Fedor Indutny
c84796ecc2 Merge branch 'v0.10'
Conflicts:
	src/unix/process.c
2014-03-26 20:45:13 +04:00
Tonis Tiigi
fd77a5d6c6 process: don't close stdio fds during spawn
This is needed when closed stdio fd is reused for uv_spawn pipe.
Fixes #1211
2014-03-26 20:35:08 +04:00
Saúl Ibarra Corretgé
db2a9072bc unix, windows: removed unused status parameter
async, timer, prepare, idle and check handles don't need the status
parameter.
2014-03-17 21:42:36 +01:00
Geoffry Song
84f305915f linux: always deregister closing fds from epoll
If the same file description is open in two different processes, then
closing the file descriptor is not sufficient to deregister it from the
epoll instance (as described in epoll(7)), resulting in spurious events
that cause the event loop to spin repeatedly. So always explicitly
deregister it.

Fixes #1099.

Conflicts:
	test/test-spawn.c
2014-03-10 17:27:36 +04:00
Fedor Indutny
644337a337 test: fix compiler warning 2014-02-24 15:44:54 +04:00
Benjamin Saunders
13dd3502a7 fs: vectored IO API for filesystem read/write
This improves API consistency with uv_read and uv_write and may
improve efficiency for some uses. Vectored IO is emulated when the
requisite system calls are unavailable.
2014-02-23 17:24:05 +01:00
Lars Gierth
1ad61807ff test: fix spawn_stdout_and_stderr_to_file test
S_IREAD and S_IWRITE are obsolete in GNU libs and
not included in the Android NDK's libc. See
http://www.gnu.org/savannah-checkouts/gnu/libc
/manual/html_node/Permission-Bits.html
2014-02-21 18:54:52 +01:00
Geoffry Song
780d8ad8e5 linux: always deregister closing fds from epoll
If the same file description is open in two different processes, then
closing the file descriptor is not sufficient to deregister it from the
epoll instance (as described in epoll(7)), resulting in spurious events
that cause the event loop to spin repeatedly. So always explicitly
deregister it.

Fixes #1099.
2014-02-19 17:13:49 +04:00
Fedor Indutny
a03ea239db Revert "fs: vectored IO API for filesystem read/write"
This reverts commit 7df24583e5.
2014-02-18 21:48:13 +04:00
Benjamin Saunders
7df24583e5 fs: vectored IO API for filesystem read/write
This improves API consistency with uv_read and uv_write and may
improve efficiency for some uses. Vectored IO is emulated when the
requisite system calls are unavailable.
2014-02-18 12:30:20 +04:00
Fedor Indutny
6abe1e4b95 fs: uv__cloexec() opened fd
Every file descriptor opened using libuv should be automatically marked
as CLOEXEC to prevent it from leaking to a child process. Note that
since we are opening fds in a thread pool, there is a possible race
condition between `uv_spawn()` and the `open()` + `uv__cloexec()`. The
rwlock was added to avoid it.

see https://github.com/joyent/node/issues/6905
2014-02-01 01:02:37 +04:00
Fedor Indutny
3a4ec61d46 test: fix after merge 2014-01-22 23:00:49 +04:00
Bert Belder
53effc3dd8 Merge branch 'v0.10'
Conflicts:
	ChangeLog
	src/unix/process.c
	src/version.c
2014-01-22 19:49:24 +01:00
Fedor Indutny
e403a2c486 process: close stdio after dup2'ing it
Thus allow passing the same file descriptor as the source of multiple
stdios.

Committed with the help and code parts from:

  * Sam Roberts <sam@strongloop.com>

fix #1074
2014-01-22 22:39:08 +04:00
Joshua Neuheisel
b44edf313c test: allow UV_EACCES in spawn_fails
Allow UV_EACCES as a successful return value when uv_spawn fails.

When the PATH environment variable contains a directory which the
user cannot access, execvp may return EACCES instead of ENOENT.

fix #1045.
2013-12-18 14:02:51 +04:00
Alex Crichton
f764bff699 unix: return exec errors from uv_spawn, not async
If spawning a process fails due to an exec() failure (but it succeeded
in forking), then this should be considered a spawn failure instead of
an asynchronous termination of the process. This allows to check for
common exec() failure conditions such as a bad path quickly instead of
having to rely on keeping track of the async callback.

Additionally, the meaning of the two fields returned in the callback are
now exactly what they advertise to be. The process exit argument is not
one of two values depending on what happened to the child.

Fixes #978.
2013-11-07 22:10:38 +01:00
Ben Noordhuis
d7115f0677 unix, windows: make uv_is_*() always return 0 or 1
Ensure that the following API functions always return either 0 or 1:

  * uv_is_active()
  * uv_is_closing()
  * uv_is_readable()
  * uv_is_writable()
2013-09-12 13:30:06 +02:00
Ben Noordhuis
f5baf210df test: wrap long lines at 80 columns 2013-09-11 17:29:43 +02:00
Ben Noordhuis
8c6ea10502 include: uv_spawn takes const uv_process_options_t*
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
2013-09-01 08:25:00 +02:00
Ben Noordhuis
b7d027c3a8 include: uv_read{2}_cb now takes const uv_buf_t*
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
2013-09-01 08:01:34 +02:00
Ben Noordhuis
3fb6612233 include: uv_alloc_cb now takes uv_buf_t*
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
2013-09-01 07:57:31 +02:00
Bert Belder
66ae0ff562 process: make the 'status' parameter for exit_cb an int64_t
This means we no longer have to strip the high bit from the process exit
code on Windows, which is problematic because an unhandled SEH exception
can make a process exit with a status code that has the high bit set.
2013-08-23 18:35:09 +02:00
Ben Noordhuis
3ee4d3f183 unix, windows: return error codes directly
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.

A code snippet like this one:

    if (uv_foo(loop) < 0) {
      uv_err_t err = uv_last_error(loop);
      fprintf(stderr, "%s\n", uv_strerror(err));
    }

Should be rewritten like this:

    int err = uv_foo(loop);
    if (err < 0)
      fprintf(stderr, "%s\n", uv_strerror(err));

The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
2013-07-07 09:51:00 +02:00
Ben Noordhuis
5a3b8f9fce test: fix spawn_setgid_fails and spawn_setuid_fails
Don't try to set a bogus UID or GID and expect to get a meaningful
error. The test expected EPERM but SunOS returns EINVAL because the
id is outside of the range of valid user/group ids.

Try to switch to UID/GID 0. Give up privileges first if we're root,
else the setuid/setgid system call will succeed when it's expected
to fail.
2013-07-02 16:32:42 +02:00
Ben Noordhuis
ede83188f3 test: don't use S_IREAD and S_IWRITE
They're BSD-isms and obsolete ones at that. Replace with S_IRUSR and
S_IWUSR. Alias as _S_IREAD and _S_IWRITE on Windows because the '90s
never ended in Redmond, WA.
2013-05-31 12:50:19 +02:00
Ben Noordhuis
da0b84d4e8 unix: auto-unref spawn handle on process exit
Consistent, for better or worse, with uv-win.

Fixes #718.
2013-02-22 14:39:40 +01:00
Ben Noordhuis
4ba03ddd56 unix, windows: rename uv_run2 to uv_run
This changes the prototype of uv_run() from:

  int uv_run(uv_loop_t* loop);

To:

  int uv_run(uv_loop_t* loop, uv_run_mode mode);

Where `mode` is UV_RUN_DEFAULT, UV_RUN_ONCE or UV_RUN_NOWAIT.

Fixes #683.
2013-01-16 23:35:29 +01:00
Ben Noordhuis
847182cdf1 test, bench: make functions/variables static
Make functions and variables that are local to the compilation unit
static. Remove what turns out to be unused.
2013-01-06 22:31:48 +01:00
Ben Noordhuis
7759bd63cd test: remove unnecessary #ifdef _WIN32 2012-11-06 00:32:04 +01:00
Bert Belder
6620e614ac windows: un-break the build
It was broken in 1d85815.
2012-11-05 22:11:22 +01:00
Charlie McConnell
1d858156b4 unix: do not set environ unless one is provided
Currently, `uv_spawn` will set `environ` to the value of `options.env`, even if
`options.env` is `NULL`.  This results in child processes for whom `environ ==
NULL`, which can cause a variety of unexpected issues.
2012-11-03 01:37:22 +01:00
Bert Belder
47eb03490a test: move loop cleanup code to the individual tests 2012-10-17 01:24:49 +02:00
Shigeki Ohtsu
09faee40eb windows: fix environment_creation test
abc945bc04 fails environment_creation test
2012-08-29 04:31:25 +02:00
Bert Belder
7c3ba514e7 windows: use WCHAR consistently 2012-08-13 22:31:48 +02:00
Bert Belder
aa69f34d53 windows: report spawn errors to the exit callback
Formerly spawn errors would be reported as a message printed to the
process' stderr, to match unix behaviour. Unix has now been fixed to
be more sensible, so this hack can now be removed.

This also fixes a race condition that could occur when the user closes
a process handle before the exit callback has been made.
2012-08-13 22:31:47 +02:00
Bert Belder
80eae82104 test: spawn failures are reported by setting the exit code to -1 2012-08-13 22:31:47 +02:00
Ben Noordhuis
13467a40d4 unix: retrieve execve() errors in process.c
Make the forked child process send the errno to its parent process when it
fails to spawn a new process.
2012-08-08 23:19:50 +02:00
Ben Noordhuis
f90d428b29 test: fix unused function warning
exit_cb_unexpected() is only used on Windows.
2012-06-29 02:34:12 +02:00
Fedor Indutny
1cd9642cbb test: stdin/out/err should be set to /dev/null when ignored 2012-06-02 21:38:39 +02:00
Fedor Indutny
dc7a62d114 test: test for uv_spawn with stdio_count == 3 2012-06-01 17:32:34 +02:00
Fedor Indutny
f5b5127db0 change spawn() api to allow using existing streams for stdio
This commit also adds support for this api on Unix.
2012-06-01 17:32:27 +02:00
Bert Belder
04a7e5c274 test-spawn.c: remove unused variable 2012-06-01 02:26:25 +02:00
Charlie McConnell
69a923bf93 process: implement UV_PROCESS_DETACHED flag for uv_spawn 2012-06-01 02:24:05 +02:00
Fedor Indutny
c0081f0e66 unix: allow specifying FDs to be inherited by a child process
Previously the only option was to create a pipe or an ipc channel. This
patch makes it possible to inherit a handle that is already open in the
parent process. It also makes it possible to set more than just stdin,
stdout and stderr.
2012-05-29 00:05:12 +02:00
Igor Zinkovsky
5a34f19970 windows: allow specifying FDs to be inherited by a child process
Previously the only option was to create a pipe or an ipc channel. This
patch makes it possible to inherit a handle that is already open in the
parent process. There is also room for setting more than just stdin,
stdout and stderr, although this is not supported yet.
2012-05-28 23:59:58 +02:00
Erik Dubbelboer
623441685d test-spawn failed to build on linux
- added missing header file
- converted c++ style comment to c style comment
2012-04-28 23:57:59 +02:00
Bert Belder
bfd6d465c7 Test for the uv_spawn's setuid and setgid options 2012-04-28 02:39:18 +02:00
Bert Belder
76364c26de Fix spawn_and_kill_with_std test 2012-04-13 01:59:24 +02:00
Ben Noordhuis
ec0eff955e Revert b3e0ad4, 149d32c, e99fdf0 and ea9baef.
Detaching doesn't work yet, the setsid() call fails and leaves the child process
attached to the parent's session.

Revert "test: Add test case for spawning detached child processes."
Revert "win: Implement options.detached for uv_spawn() for Windows."
Revert "unix: Implement options.detached for uv_spawn() for unix."
Revert "Add "detached" member to uv_process_options_t to denote whether a child
        process should spawn detached from its parent."

This reverts commit ea9baef95c.
This reverts commit e99fdf0df6.
This reverts commit 149d32cb96.
This reverts commit b3e0ad4db8.
2012-02-28 15:29:05 +01:00
Charlie McConnell
ea9baef95c test: Add test case for spawning detached child processes. 2012-02-24 15:15:00 +01:00
seebees
59f9a736b1 test: process should not wait for stdio before terminating 2011-11-23 17:34:18 +01:00
Tj Holowaychuk
a378110f9e Add UV_ESRCH
Fixes #239.
2011-11-08 16:36:20 -08:00
Igor Zinkovsky
74b49e821b uv_kill 2011-11-02 14:34:07 -07:00
Ben Noordhuis
acc98ca922 test: uv_process_kill(proc, 0) should not kill the process 2011-10-11 21:36:54 +02:00
Ryan Dahl
bb6b629e6a make test-ipc accept the pending tcp server 2011-10-06 10:17:18 -07:00
Ryan Dahl
6921d2fc07 Add argument to uv_pipe_init for IPC, unix impl 2011-10-06 10:17:07 -07:00
Bert Belder
0dc564a2aa Remove uv_init calls from tests and benchmarks 2011-09-12 11:32:41 -07:00
Ben Noordhuis
90ea007f61 test: fix compiler warnings for test-spawn.c 2011-09-08 00:15:47 +02:00
Bert Belder
8e3a8602ad update tests for multiplicity 2011-08-31 04:19:26 +02:00
Bert Belder
3aec77f9d4 bring back uv_init 2011-08-31 04:19:07 +02:00
Ryan Dahl
56dcaf9b06 unix: multiplicity 2011-08-31 04:18:55 +02:00
Ben Noordhuis
36ce74f2ca Add UDP support to libuv. 2011-08-24 04:55:01 +02:00
Peter Bright
3409c9b383 Include important Windows environmental variables even when a blank/custom environment is specified. 2011-08-09 14:29:51 -07:00
Peter Bright
d84b249616 Support for unescaped arguments, suitable for use with cmd /c.
Robust argument escaping that hopefully matches Windows' algorithm for unescaping.
2011-08-04 18:22:47 -07:00
Igor Zinkovsky
6d940a3afc windows: remove dependency on rpcrt4 and ole32 libs. fixes https://github.com/joyent/libuv/issues/118 2011-08-01 20:10:55 -07:00
Igor Zinkovsky
c35548a69e fix spawn_and_kill test on windows 2011-08-01 16:50:59 -07:00
Ben Noordhuis
aa37c698ee test: add platform-specific checks for kill-after-spawn test 2011-08-02 00:46:44 +02:00
Igor Zinkovsky
3e6611a693 more output 2011-07-29 23:54:52 -07:00
Igor Zinkovsky
d272a2183d Windows: spawn child processes 2011-07-29 19:02:51 -07:00
Ryan Dahl
7108ca8853 uv_spawn requires stdio pipes to be initialized 2011-07-29 15:37:00 -07:00
Ryan Dahl
ddee1821fa Add spawn_stdout test 2011-07-25 17:11:23 -07:00
Ryan Dahl
92bc7b4959 Start uv_spawn()
Unix only at the moment. Lacks test for stdio
2011-07-25 16:19:27 -04:00