2016-02-27 18:48:19 +01:00
|
|
|
/* Copyright (c) 2010-2016, The Tor Project, Inc. */
|
2015-09-15 17:37:25 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
#define UTIL_PROCESS_PRIVATE
|
|
|
|
#include "orconfig.h"
|
|
|
|
#include "or.h"
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include "util_process.h"
|
|
|
|
|
|
|
|
#include "log_test_helpers.h"
|
|
|
|
|
2015-10-22 16:01:05 +02:00
|
|
|
#ifndef _WIN32
|
2015-09-15 17:37:25 +02:00
|
|
|
#define NS_MODULE util_process
|
|
|
|
|
2015-10-05 21:07:55 +02:00
|
|
|
static void
|
|
|
|
temp_callback(int r, void *s)
|
2015-09-15 17:37:25 +02:00
|
|
|
{
|
|
|
|
(void)r;
|
|
|
|
(void)s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_util_process_set_waitpid_callback(void *ignored)
|
|
|
|
{
|
|
|
|
(void)ignored;
|
2015-10-21 22:51:21 +02:00
|
|
|
waitpid_callback_t *res1 = NULL, *res2 = NULL;
|
2015-09-15 17:37:25 +02:00
|
|
|
int previous_log = setup_capture_of_logs(LOG_WARN);
|
|
|
|
pid_t pid = (pid_t)42;
|
|
|
|
|
2015-10-21 22:51:21 +02:00
|
|
|
res1 = set_waitpid_callback(pid, temp_callback, NULL);
|
|
|
|
tt_assert(res1);
|
2015-09-15 17:37:25 +02:00
|
|
|
|
2015-10-21 22:51:21 +02:00
|
|
|
res2 = set_waitpid_callback(pid, temp_callback, NULL);
|
|
|
|
tt_assert(res2);
|
2016-02-01 00:02:04 +01:00
|
|
|
expect_log_msg("Replaced a waitpid monitor on pid 42. That should be "
|
2015-10-05 21:07:55 +02:00
|
|
|
"impossible.\n");
|
2015-09-15 17:37:25 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
teardown_capture_of_logs(previous_log);
|
2015-10-21 22:51:21 +02:00
|
|
|
clear_waitpid_callback(res1);
|
|
|
|
clear_waitpid_callback(res2);
|
2015-09-15 17:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-02-01 00:02:04 +01:00
|
|
|
expect_no_log_entry();
|
2015-10-05 21:07:55 +02:00
|
|
|
|
2015-10-21 22:51:21 +02:00
|
|
|
#if 0
|
|
|
|
/* No. This is use-after-free. We don't _do_ that. XXXX */
|
2015-09-15 17:37:25 +02:00
|
|
|
clear_waitpid_callback(res);
|
2016-02-01 00:02:04 +01:00
|
|
|
expect_log_msg("Couldn't remove waitpid monitor for pid 43.\n");
|
2015-10-21 22:51:21 +02:00
|
|
|
#endif
|
2015-09-15 17:37:25 +02:00
|
|
|
|
2015-10-05 21:07:55 +02:00
|
|
|
done:
|
2015-09-15 17:37:25 +02:00
|
|
|
teardown_capture_of_logs(previous_log);
|
|
|
|
}
|
2015-10-22 16:01:05 +02:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2015-10-23 00:47:26 +02:00
|
|
|
#ifndef _WIN32
|
2015-10-22 16:01:05 +02:00
|
|
|
#define TEST(name) { #name, test_util_process_##name, 0, NULL, NULL }
|
|
|
|
#else
|
|
|
|
#define TEST(name) { #name, NULL, TT_SKIP, NULL, NULL }
|
|
|
|
#endif
|
2015-09-15 17:37:25 +02:00
|
|
|
|
|
|
|
struct testcase_t util_process_tests[] = {
|
2015-10-22 16:01:05 +02:00
|
|
|
TEST(set_waitpid_callback),
|
|
|
|
TEST(clear_waitpid_callback),
|
2015-09-15 17:37:25 +02:00
|
|
|
END_OF_TESTCASES
|
|
|
|
};
|
2015-10-21 22:46:28 +02:00
|
|
|
|