Commit Graph

97 Commits

Author SHA1 Message Date
Bartosz Sosnowski
890eedaf59 win, process: uv_kill improvements
Maps pid 0 to the current process, simulating Linux kill sending signal
to the process group.

Adds detection of invalid signals. If the signum is invalid - below 0
or NSIG or above – UV_EINVAL will be returned instead of UV_ENOSYS.

PR-URL: https://github.com/libuv/libuv/pull/1642
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-12-07 14:00:05 +01:00
cjihrig
b21c1f900c
win: let UV_PROCESS_WINDOWS_HIDE hide consoles
The existing UV_PROCESS_WINDOWS_HIDE flag only applies to
executables linked to the WINDOWS subsystem. This allows
CONSOLE subsystem applications to pop up a console
window. This commit sets the CREATE_NO_WINDOW process
flag when UV_PROCESS_WINDOWS_HIDE to prevent this behavior.

Refs: https://github.com/nodejs/node/pull/15380
Refs: https://github.com/joyent/libuv/pull/627
Refs: https://github.com/libuv/libuv/issues/965
PR-URL: https://github.com/libuv/libuv/pull/1558
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2017-09-25 19:55:59 -04:00
Bartosz Sosnowski
cbcf13af6a win, process: support semicolons in PATH variable
Fixes a bug that would cause libuv to crash when PATH environment
variable contained paths with semicolon in it

Refs: https://github.com/nodejs/help/issues/728
Fixes: https://github.com/libuv/libuv/issues/1422
PR-URL: https://github.com/libuv/libuv/pull/1438
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-07-27 12:34:31 +02:00
Ben Noordhuis
87df1448a4 unix,windows: refactor request init logic
Fixes a TODO in src/threadpool.c.  Updates the Windows code to drop the
unused `loop` parameter in calls to uv_req_init().

PR-URL: https://github.com/libuv/libuv/pull/1091
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-21 16:14:09 +01:00
Eric Sciple
8658ef06c2 win: fix comment in quote_cmd_arg
PR-URL: https://github.com/libuv/libuv/pull/1113
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-by: Bert Belder <bertbelder@gmail.com>
2016-12-01 22:30:05 +01:00
Saúl Ibarra Corretgé
d110a1b6c5 win: fix compilation
Yours truly broke compilation on bddd6a8489
2015-06-03 00:22:19 +02:00
Saúl Ibarra Corretgé
bddd6a8489 core: add ability to customize memory allocator
This patch is composed by the work done in
https://github.com/libuv/libuv/pull/231 and
https://github.com/libuv/libuv/pull/287 plus some changes by yours
truly.

Thanks @beevik and @mattsta for their work on this!

PR-URL: https://github.com/libuv/libuv/pull/368
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-02 12:05:20 +02:00
Saúl Ibarra Corretgé
1f711e4d6d Revert "memory: add uv_replace_allocator"
This reverts commit c272f1f1bc.

The concept will come back to libuv, but it needs some more work.
2015-04-29 09:37:02 +02:00
Brett Vickers
c272f1f1bc memory: add uv_replace_allocator
With uv_replace_allocator, it's possible to override the default
memory allocator's malloc and free calls with functions of the user's
choosing. This allows libuv to interoperate with projects requiring a
custom memory allocator.

Internally, all calls to malloc and free have been replaced with
uv__malloc and uv__free, respectively. The uv__malloc and uv__free
functions call malloc and free unless they have been overridden by a
previous call to uv_replace_allocator.

As part of this change, the special aligned memory allocations
performed in src/win/fs-event.c have been replaced with standard
allocations. The 4-byte alignment being requested in this file was
unnecessary, since standard allocators already guarantee at least an
8-byte alignment.

PR-URL: https://github.com/libuv/libuv/pull/231
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-05 20:02:16 +01:00
TomCrypto
073323baca win: name all anonymous structs and unions
All the public structs and unions in the private fields in uv-win.h have
been named and all code accessing them updated, to comply to the C89
spec (which were previously causing warnings with the -pedantic flag).

PR-URL: https://github.com/libuv/libuv/pull/239
Reviewed-By: Andrius Bentkus <andrius.bentkus@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-04 09:35:10 +01:00
Joey Geralnik
3aeca36a1b unix, windows: fix typos in comments
Fix various typos and spelling mistakes in comments.
Does not affect any code, just changes comments.

PR-URL: https://github.com/libuv/libuv/pull/17
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-11-29 04:23:19 +01:00
huxingyi
ca4741b4a5 windows: fix build on MinGW 2014-08-10 12:09:04 +02:00
Paul Goldsmith
ac879ed8f8 windows: add support for UNC paths on uv_spawn 2014-08-10 10:14:42 +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
Jameson Nash
2ce14cfab4 windows: add more required environment variables
Adds more of the undocumented-but-required environment variables for uv_spawn
2014-08-01 09:26:21 +02:00
Andrius Bentkus
36b38cbdba style: remove trailing whitespace
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-24 20:18:10 +04: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
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
StarWing
1ec4c23438 windows: fix warnings of MinGW -Wall -O3 2014-03-07 17:21:00 +08:00
Alex Crichton
6f62d62c90 windows: always initialize uv_process_t
The unix implementation of uv_spawn always starts out with a
uv__handle_init, but the windows implementation sometimes bails out
early before calling uv__handle_init. This means that uv_close on a
failed uv_spawn will always succeed on unix but sometimes fail on
windows.

This commit lifts the initialization of the uv_process_t above all of
the error checking to ensure that uv_close will always work when
uv_spawn returns an error.
2014-02-16 13:09:54 +01:00
Alexis Campailla
b83caf8624 windows: uv_spawn code refactor 2013-12-12 09:53:14 -08:00
Alexis Campailla
b65b74741e windows: translate system errors in uv_spawn
We weren't always translating system errors for in uv_spawn.

This is half a fix for node's unit test
 test-child-process-cwd.js on win.
 The rest will go into node lib.
 It also fixes test-child-process-exec-error
2013-12-12 09:53:10 -08: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
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
Bert Belder
d667653f77 windows: report uv_process_t exit code correctly
A stupid oversight in 66ae0ff would cause a random value to be reported
as the exit code for a 'normally exited' child process.
2013-08-24 16:45:30 +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
Bert Belder
ed82eae13a windows: make uv_spawn() failure more predictable
* It will now report some types of errors synchronously, to bring it on
  par with uv-unix. Fixes #865.

* Failure to find the target executable will now set up stdio pipes
  correctly, so the user can assume that when uv_spawn() returns 0 these
  pipes will never trigger asserts in libuv's guts.
2013-08-23 18:34:14 +02:00
Yasuhiro Matsumoto
d7a1ba85f2 windows: fix mingw32 build, include limits.h
src/win/process uses INT_MAX so include limits.h.
2013-08-01 15:21:35 +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
Bert Belder
495d1a09fb windows: uv_spawn shouldn't reject reparse points
This fixes an issue where uv_spawn would not try to run a reparse point,
and continue to scan the PATH instead. Effectively, it was impossible to
spawn a symlinked binary. This commit fixes that.

Also see #748
2013-06-19 00:15:20 +02:00
Bert Belder
4f61ab2058 windows: make uv_spawn not fail under job control
* Fix a potential issue introduced with 415f4d3, namely that uv_spawn
  can fail when the current process is under job control. This would
  happen on Windows versions that don't support nested jobs (versions
  prior to Windows 8 / Server 2012).

* Change the `uv__init_global_job_handle` function signature to match
  what `uv_once` expects.

* Add a bunch of comments that clarify how we're using job control,
  and how we're dealing with job control that might be established by
  our parent process.
2013-05-16 21:29:40 +02:00
Bert Belder
415f4d3e4c windows: kill child processes when the parent dies
This makes Windows behave just like Unix. This does not affect
processes that are spawned with the UV_PROCESS_DETACHED flag set.
2013-05-14 16:48:03 -07:00
Shane Holloway
5d92ccce94 windows: add flag for hiding windows created by a spawned process
Closes GH-627
2012-11-27 16:48:46 +01:00
Bert Belder
9aead82537 windows: rename UV_HANDLE_CLOSING to UV__HANDLE_CLOSING 2012-09-13 23:42:07 +02:00
Bert Belder
abc945bc04 windows: make spawn with custom environment work again 2012-08-28 22:33:52 +02:00
Bert Belder
5c674b2889 windows: squelch some warnings related to int64 to int32 conversion 2012-08-28 22:33:52 +02:00
Bert Belder
637be161b3 windows: make active and closing handle state independent 2012-08-27 23:56:35 +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
Ben Noordhuis
837edf4c0f unix, windows: remove handle init counters
Remove the handle init counters, no one uses them.
2012-08-10 02:00:11 +02:00
Bert Belder
67090653df windows: set the child_pid property for all IPC pipes in uv_spawn 2012-06-19 19:22:49 +02:00
Bert Belder
07c6ac2b55 windows: move child stdio buffer ops to a separate file 2012-06-13 19:17:13 +02:00
Bert Belder
9f44b0e393 windows: fix serious typo in init_child_stdio 2012-06-13 01:30:43 +02:00
Ben Noordhuis
95e89c6a0e unix, windows: share uv__handle_init() 2012-06-13 01:28:58 +02:00
Bert Belder
b7e150ee91 windows: uv_kill() should report UV_ESRC when the victim is already dead 2012-06-12 17:00:16 +02:00
Bert Belder
be9d1ce909 windows: cast STARTUP_INFO.cbReserved2 to WORD to avoid warnings 2012-06-05 00:58:51 +02:00
Bert Belder
d8b95eaffb windows: inline a couple of handle functions 2012-06-02 23:38:16 +02:00
Bert Belder
d402604118 windows: inline a couple of inline request functions 2012-06-02 23:08:22 +02:00
Bert Belder
bdb8b3a1f2 windows: always set FDs 0-2 for spawned child processes 2012-06-02 21:17:03 +02:00