unix: auto-unref spawn handle on process exit

Consistent, for better or worse, with uv-win.

Fixes #718.
This commit is contained in:
Ben Noordhuis 2013-02-22 14:39:39 +01:00
parent 3348cd7407
commit da0b84d4e8
3 changed files with 17 additions and 0 deletions

View File

@ -89,6 +89,8 @@ static void uv__chld(uv_signal_t* handle, int signum) {
if (process == NULL)
continue; /* XXX bug? abort? */
uv__handle_stop(process);
if (process->exit_cb == NULL)
continue;

View File

@ -152,6 +152,7 @@ TEST_DECLARE (spawn_preserve_env)
TEST_DECLARE (spawn_setuid_fails)
TEST_DECLARE (spawn_setgid_fails)
TEST_DECLARE (spawn_stdout_to_file)
TEST_DECLARE (spawn_auto_unref)
TEST_DECLARE (fs_poll)
TEST_DECLARE (kill)
TEST_DECLARE (fs_file_noent)
@ -413,6 +414,7 @@ TASK_LIST_START
TEST_ENTRY (spawn_setuid_fails)
TEST_ENTRY (spawn_setgid_fails)
TEST_ENTRY (spawn_stdout_to_file)
TEST_ENTRY (spawn_auto_unref)
TEST_ENTRY (fs_poll)
TEST_ENTRY (kill)

View File

@ -923,3 +923,16 @@ TEST_IMPL(spawn_setgid_fails) {
return 0;
}
#endif
TEST_IMPL(spawn_auto_unref) {
init_process_options("spawn_helper1", NULL);
ASSERT(0 == uv_spawn(uv_default_loop(), &process, options));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(0 == uv_is_closing((uv_handle_t*) &process));
uv_close((uv_handle_t*) &process, NULL);
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(0 != uv_is_closing((uv_handle_t*) &process));
MAKE_VALGRIND_HAPPY();
return 0;
}