mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
Merge branch 'ticket28847'
This commit is contained in:
commit
ab4395d082
3
changes/ticket28847
Normal file
3
changes/ticket28847
Normal file
@ -0,0 +1,3 @@
|
||||
o Minor features (process):
|
||||
- Use the subsystem module to initialize and shut down the process module.
|
||||
Closes ticket 28847.
|
@ -74,7 +74,6 @@
|
||||
#include "lib/net/resolve.h"
|
||||
|
||||
#include "lib/process/waitpid.h"
|
||||
#include "lib/process/process.h"
|
||||
|
||||
#include "lib/meminfo/meminfo.h"
|
||||
#include "lib/osinfo/uname.h"
|
||||
@ -560,9 +559,6 @@ tor_init(int argc, char *argv[])
|
||||
addressmap_init(); /* Init the client dns cache. Do it always, since it's
|
||||
* cheap. */
|
||||
|
||||
/* Initialize Process subsystem. */
|
||||
process_init();
|
||||
|
||||
/* Initialize the HS subsystem. */
|
||||
hs_init();
|
||||
|
||||
@ -790,7 +786,6 @@ tor_free_all(int postfork)
|
||||
circuitmux_ewma_free_all();
|
||||
accounting_free_all();
|
||||
protover_summary_cache_free_all();
|
||||
process_free_all();
|
||||
|
||||
if (!postfork) {
|
||||
config_free_all();
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "lib/time/time_sys.h"
|
||||
#include "lib/tls/tortls_sys.h"
|
||||
#include "lib/wallclock/wallclock_sys.h"
|
||||
#include "lib/process/process_sys.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@ -32,6 +33,7 @@ const subsys_fns_t *tor_subsystems[] = {
|
||||
&sys_logging, /* -90 */
|
||||
&sys_time, /* -90 */
|
||||
&sys_network, /* -90 */
|
||||
&sys_process, /* -80 */
|
||||
&sys_compress, /* -70 */
|
||||
&sys_crypto, /* -60 */
|
||||
&sys_tortls, /* -50 */
|
||||
|
@ -10,6 +10,7 @@ src_lib_libtor_process_a_SOURCES = \
|
||||
src/lib/process/env.c \
|
||||
src/lib/process/pidfile.c \
|
||||
src/lib/process/process.c \
|
||||
src/lib/process/process_sys.c \
|
||||
src/lib/process/process_unix.c \
|
||||
src/lib/process/process_win32.c \
|
||||
src/lib/process/restrict.c \
|
||||
@ -27,6 +28,7 @@ noinst_HEADERS += \
|
||||
src/lib/process/env.h \
|
||||
src/lib/process/pidfile.h \
|
||||
src/lib/process/process.h \
|
||||
src/lib/process/process_sys.h \
|
||||
src/lib/process/process_unix.h \
|
||||
src/lib/process/process_win32.h \
|
||||
src/lib/process/restrict.h \
|
||||
|
@ -47,6 +47,8 @@ const char *process_protocol_to_string(process_protocol_t protocol);
|
||||
|
||||
void tor_disable_spawning_background_processes(void);
|
||||
|
||||
struct smartlist_t;
|
||||
|
||||
struct process_t;
|
||||
typedef struct process_t process_t;
|
||||
|
||||
@ -61,7 +63,7 @@ typedef bool
|
||||
|
||||
void process_init(void);
|
||||
void process_free_all(void);
|
||||
const smartlist_t *process_get_all_processes(void);
|
||||
const struct smartlist_t *process_get_all_processes(void);
|
||||
|
||||
process_t *process_new(const char *command);
|
||||
void process_free_(process_t *process);
|
||||
@ -82,10 +84,11 @@ void process_set_exit_callback(process_t *,
|
||||
const char *process_get_command(const process_t *process);
|
||||
|
||||
void process_append_argument(process_t *process, const char *argument);
|
||||
const smartlist_t *process_get_arguments(const process_t *process);
|
||||
const struct smartlist_t *process_get_arguments(const process_t *process);
|
||||
char **process_get_argv(const process_t *process);
|
||||
|
||||
void process_reset_environment(process_t *process, const smartlist_t *env);
|
||||
void process_reset_environment(process_t *process,
|
||||
const struct smartlist_t *env);
|
||||
void process_set_environment(process_t *process,
|
||||
const char *key,
|
||||
const char *value);
|
||||
|
33
src/lib/process/process_sys.c
Normal file
33
src/lib/process/process_sys.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright (c) 2018, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
/**
|
||||
* \file process_sys.c
|
||||
* \brief Subsystem object for process setup.
|
||||
**/
|
||||
|
||||
#include "orconfig.h"
|
||||
#include "lib/subsys/subsys.h"
|
||||
#include "lib/process/process_sys.h"
|
||||
#include "lib/process/process.h"
|
||||
|
||||
static int
|
||||
subsys_process_initialize(void)
|
||||
{
|
||||
process_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
subsys_process_shutdown(void)
|
||||
{
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
const subsys_fns_t sys_process = {
|
||||
.name = "process",
|
||||
.level = -80,
|
||||
.supported = true,
|
||||
.initialize = subsys_process_initialize,
|
||||
.shutdown = subsys_process_shutdown
|
||||
};
|
14
src/lib/process/process_sys.h
Normal file
14
src/lib/process/process_sys.h
Normal file
@ -0,0 +1,14 @@
|
||||
/* Copyright (c) 2018, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
/**
|
||||
* \file process_sys.h
|
||||
* \brief Declare subsystem object for the process module.
|
||||
**/
|
||||
|
||||
#ifndef TOR_PROCESS_SYS_H
|
||||
#define TOR_PROCESS_SYS_H
|
||||
|
||||
extern const struct subsys_fns_t sys_process;
|
||||
|
||||
#endif /* !defined(TOR_PROCESS_SYS_H) */
|
@ -2,7 +2,7 @@
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
/**
|
||||
* \file log_time.h
|
||||
* \file time_sys.h
|
||||
* \brief Declare subsystem object for the time module.
|
||||
**/
|
||||
|
||||
|
@ -142,8 +142,6 @@ static void
|
||||
test_default_values(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
process_init();
|
||||
|
||||
process_t *process = process_new("/path/to/nothing");
|
||||
|
||||
/* We are not running by default. */
|
||||
@ -171,14 +169,12 @@ test_default_values(void *arg)
|
||||
|
||||
done:
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
static void
|
||||
test_environment(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
process_init();
|
||||
|
||||
process_t *process = process_new("");
|
||||
process_environment_t *env = NULL;
|
||||
@ -221,7 +217,6 @@ test_environment(void *arg)
|
||||
done:
|
||||
process_environment_free(env);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -249,7 +244,6 @@ static void
|
||||
test_line_protocol_simple(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
process_init();
|
||||
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
@ -289,7 +283,6 @@ test_line_protocol_simple(void *arg)
|
||||
done:
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
|
||||
UNMOCK(process_read_stdout);
|
||||
UNMOCK(process_read_stderr);
|
||||
@ -299,7 +292,6 @@ static void
|
||||
test_line_protocol_multi(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
process_init();
|
||||
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
@ -349,7 +341,6 @@ test_line_protocol_multi(void *arg)
|
||||
done:
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
|
||||
UNMOCK(process_read_stdout);
|
||||
UNMOCK(process_read_stderr);
|
||||
@ -359,7 +350,6 @@ static void
|
||||
test_line_protocol_partial(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
process_init();
|
||||
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
@ -431,7 +421,6 @@ test_line_protocol_partial(void *arg)
|
||||
done:
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
|
||||
UNMOCK(process_read_stdout);
|
||||
UNMOCK(process_read_stderr);
|
||||
@ -441,7 +430,6 @@ static void
|
||||
test_raw_protocol_simple(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
process_init();
|
||||
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
@ -499,7 +487,6 @@ test_raw_protocol_simple(void *arg)
|
||||
done:
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
|
||||
UNMOCK(process_read_stdout);
|
||||
UNMOCK(process_read_stderr);
|
||||
@ -510,8 +497,6 @@ test_write_simple(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
process_init();
|
||||
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
process_t *process = process_new("");
|
||||
@ -530,7 +515,6 @@ test_write_simple(void *arg)
|
||||
done:
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
|
||||
UNMOCK(process_write_stdin);
|
||||
}
|
||||
@ -540,8 +524,6 @@ test_exit_simple(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
process_init();
|
||||
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
process_t *process = process_new("");
|
||||
@ -566,14 +548,12 @@ test_exit_simple(void *arg)
|
||||
process_set_data(process, process_data);
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
static void
|
||||
test_argv_simple(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
process_init();
|
||||
|
||||
process_t *process = process_new("/bin/cat");
|
||||
char **argv = NULL;
|
||||
@ -600,7 +580,6 @@ test_argv_simple(void *arg)
|
||||
done:
|
||||
tor_free(argv);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -608,8 +587,6 @@ test_unix(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
#ifndef _WIN32
|
||||
process_init();
|
||||
|
||||
process_t *process = process_new("");
|
||||
|
||||
/* On Unix all processes should have a Unix process handle. */
|
||||
@ -617,7 +594,6 @@ test_unix(void *arg)
|
||||
|
||||
done:
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -626,8 +602,6 @@ test_win32(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
#ifdef _WIN32
|
||||
process_init();
|
||||
|
||||
process_t *process = process_new("");
|
||||
char *joined_argv = NULL;
|
||||
|
||||
@ -675,7 +649,6 @@ test_win32(void *arg)
|
||||
done:
|
||||
tor_free(joined_argv);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -203,9 +203,6 @@ test_callbacks(void *arg)
|
||||
filename = TEST_PROCESS;
|
||||
#endif
|
||||
|
||||
/* Initialize Process subsystem. */
|
||||
process_init();
|
||||
|
||||
/* Process callback data. */
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
@ -286,7 +283,6 @@ test_callbacks(void *arg)
|
||||
done:
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -301,9 +297,6 @@ test_callbacks_terminate(void *arg)
|
||||
filename = TEST_PROCESS;
|
||||
#endif
|
||||
|
||||
/* Initialize Process subsystem. */
|
||||
process_init();
|
||||
|
||||
/* Process callback data. */
|
||||
process_data_t *process_data = process_data_new();
|
||||
|
||||
@ -333,7 +326,6 @@ test_callbacks_terminate(void *arg)
|
||||
done:
|
||||
process_data_free(process_data);
|
||||
process_free(process);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
struct testcase_t slow_process_tests[] = {
|
||||
|
@ -151,8 +151,6 @@ test_pt_get_transport_options(void *arg)
|
||||
config_line_t *cl = NULL;
|
||||
(void)arg;
|
||||
|
||||
process_init();
|
||||
|
||||
execve_args = tor_malloc(sizeof(char*)*2);
|
||||
execve_args[0] = tor_strdup("cheeseshop");
|
||||
execve_args[1] = NULL;
|
||||
@ -192,7 +190,6 @@ test_pt_get_transport_options(void *arg)
|
||||
config_free_lines(cl);
|
||||
managed_proxy_destroy(mp, 0);
|
||||
smartlist_free(transport_list);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -256,8 +253,6 @@ test_pt_get_extrainfo_string(void *arg)
|
||||
char *s = NULL;
|
||||
(void) arg;
|
||||
|
||||
process_init();
|
||||
|
||||
argv1 = tor_malloc_zero(sizeof(char*)*3);
|
||||
argv1[0] = tor_strdup("ewige");
|
||||
argv1[1] = tor_strdup("Blumenkraft");
|
||||
@ -291,7 +286,6 @@ test_pt_get_extrainfo_string(void *arg)
|
||||
smartlist_free(t1);
|
||||
smartlist_free(t2);
|
||||
tor_free(s);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
static int
|
||||
@ -355,8 +349,6 @@ test_pt_configure_proxy(void *arg)
|
||||
managed_proxy_t *mp = NULL;
|
||||
(void) arg;
|
||||
|
||||
process_init();
|
||||
|
||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
||||
|
||||
MOCK(process_read_stdout, process_read_stdout_replacement);
|
||||
@ -501,7 +493,6 @@ test_pt_configure_proxy(void *arg)
|
||||
tor_free(mp->argv[0]);
|
||||
tor_free(mp->argv);
|
||||
tor_free(mp);
|
||||
process_free_all();
|
||||
}
|
||||
|
||||
/* Test the get_pt_proxy_uri() function. */
|
||||
|
Loading…
Reference in New Issue
Block a user