static void test_util_process_clear_waitpid_callback(void *ignored) { (void)ignored; waitpid_callback_t *res; int previous_log = setup_capture_of_logs(LOG_WARN); pid_t pid = (pid_t)43; clear_waitpid_callback(NULL); res = set_waitpid_callback(pid, temp_callback, NULL); clear_waitpid_callback(res); clear_waitpid_callback(res); // done: teardown_capture_of_logs(previous_log); }
static void test_util_process_set_waitpid_callback(void *ignored) { (void)ignored; waitpid_callback_t *res1 = NULL, *res2 = NULL; int previous_log = setup_capture_of_logs(LOG_WARN); pid_t pid = (pid_t)42; res1 = set_waitpid_callback(pid, temp_callback, NULL); tt_assert(res1); res2 = set_waitpid_callback(pid, temp_callback, NULL); tt_assert(res2); expect_log_msg("Replaced a waitpid monitor on pid 42. That should be " "impossible.\n"); done: teardown_capture_of_logs(previous_log); clear_waitpid_callback(res1); clear_waitpid_callback(res2); }
static void test_util_process_clear_waitpid_callback(void *ignored) { (void)ignored; waitpid_callback_t *res; int previous_log = setup_capture_of_logs(LOG_WARN); pid_t pid = (pid_t)43; clear_waitpid_callback(NULL); res = set_waitpid_callback(pid, temp_callback, NULL); clear_waitpid_callback(res); expect_no_log_entry(); #if 0 /* No. This is use-after-free. We don't _do_ that. XXXX */ clear_waitpid_callback(res); expect_log_msg("Couldn't remove waitpid monitor for pid 43.\n"); #endif done: teardown_capture_of_logs(previous_log); }
/** This function is called when the waitpid system have detected that our * process have terminated. We disable the waitpid system and notify the * Process subsystem that we have terminated. */ STATIC void process_unix_waitpid_callback(int status, void *data) { tor_assert(data); process_t *process = data; process_unix_t *unix_process = process_get_unix_process(process); /* Remove our waitpid callback. */ clear_waitpid_callback(unix_process->waitpid); unix_process->waitpid = NULL; /* Notify our process. */ process_notify_event_exit(process, status); /* Make sure you don't modify the process after we have called * process_notify_event_exit() on it, to allow users to process_free() it in * the exit callback. */ }
/** Deallocates the given <b>unix_process</b>. */ void process_unix_free_(process_unix_t *unix_process) { if (! unix_process) return; /* Clean up our waitpid callback. */ clear_waitpid_callback(unix_process->waitpid); /* FIXME(ahf): Refactor waitpid code? */ unix_process->waitpid = NULL; /* Close all our file descriptors. */ process_unix_close_file_descriptors(unix_process); tor_event_free(unix_process->stdout_handle.event); tor_event_free(unix_process->stderr_handle.event); tor_event_free(unix_process->stdin_handle.event); tor_free(unix_process); }