From 72b5e4a2db4282002fe50e11c2b8a79e108d30f8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 18 Oct 2017 13:49:35 -0400 Subject: [PATCH 1/6] Move tor_git_revision into a new module. At first, we put the tor_git_revision constant in tor_main.c, so that we wouldn't have to recompile config.o every time the git revision changed. But putting it there had unintended side effect of forcing every program that wanted to link libor.a (including test, test-slow, the fuzzers, the benchmarks, etc) to declare their own tor_git_revision instance. That's not very nice, especially since we want to start supporting others who want to link against Tor (see 23846). So, create a new git_revision.c file that only contains this constant, and remove the duplicated boilerplate from everywhere else. Part of implementing ticket 23845. --- changes/ticket23845 | 4 ++++ src/or/config.c | 3 +-- src/or/git_revision.c | 17 +++++++++++++++++ src/or/git_revision.h | 12 ++++++++++++ src/or/include.am | 2 ++ src/or/tor_main.c | 12 ------------ src/test/bench.c | 5 ----- src/test/fuzz/fuzzing_common.c | 3 --- src/test/testing_common.c | 6 ------ 9 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 changes/ticket23845 create mode 100644 src/or/git_revision.c create mode 100644 src/or/git_revision.h diff --git a/changes/ticket23845 b/changes/ticket23845 new file mode 100644 index 0000000000..01f57374b4 --- /dev/null +++ b/changes/ticket23845 @@ -0,0 +1,4 @@ + o Code simplification and refactoring: + - The tor_git_revision[] constant no longer needs to be redeclared + by everything that links against the rest of Tor. Done as part + of ticket 23845, to simplify our external API. diff --git a/src/or/config.c b/src/or/config.c index 832a7c9674..57d919e720 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -82,6 +82,7 @@ #include "dirvote.h" #include "dns.h" #include "entrynodes.h" +#include "git_revision.h" #include "geoip.h" #include "hibernate.h" #include "main.h" @@ -879,8 +880,6 @@ set_options(or_options_t *new_val, char **msg) return 0; } -extern const char tor_git_revision[]; /* from tor_main.c */ - /** The version of this Tor process, as parsed. */ static char *the_tor_version = NULL; /** A shorter version of this Tor process's version, for export in our router diff --git a/src/or/git_revision.c b/src/or/git_revision.c new file mode 100644 index 0000000000..8f326b8751 --- /dev/null +++ b/src/or/git_revision.c @@ -0,0 +1,17 @@ +/* Copyright 2001-2004 Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "git_revision.h" + +/** String describing which Tor Git repository version the source was + * built from. This string is generated by a bit of shell kludging in + * src/or/include.am, and is usually right. + */ +const char tor_git_revision[] = +#ifndef _MSC_VER +#include "micro-revision.i" +#endif + ""; + diff --git a/src/or/git_revision.h b/src/or/git_revision.h new file mode 100644 index 0000000000..1ceaeedf16 --- /dev/null +++ b/src/or/git_revision.h @@ -0,0 +1,12 @@ +/* Copyright 2001-2004 Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#ifndef TOR_GIT_REVISION_H +#define TOR_GIT_REVISION_H + +extern const char tor_git_revision[]; + +#endif + diff --git a/src/or/include.am b/src/or/include.am index 7216aba9af..662bd4807c 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -51,6 +51,7 @@ LIBTOR_A_SOURCES = \ src/or/geoip.c \ src/or/entrynodes.c \ src/or/ext_orport.c \ + src/or/git_revision.c \ src/or/hibernate.c \ src/or/hs_cache.c \ src/or/hs_cell.c \ @@ -189,6 +190,7 @@ ORHEADERS = \ src/or/fp_pair.h \ src/or/geoip.h \ src/or/entrynodes.h \ + src/or/git_revision.h \ src/or/hibernate.h \ src/or/hs_cache.h \ src/or/hs_cell.h \ diff --git a/src/or/tor_main.c b/src/or/tor_main.c index a3a8838602..9f57f516ee 100644 --- a/src/or/tor_main.c +++ b/src/or/tor_main.c @@ -3,18 +3,6 @@ * Copyright (c) 2007-2017, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -extern const char tor_git_revision[]; - -/** String describing which Tor Git repository version the source was - * built from. This string is generated by a bit of shell kludging in - * src/or/include.am, and is usually right. - */ -const char tor_git_revision[] = -#ifndef _MSC_VER -#include "micro-revision.i" -#endif - ""; - /** * \file tor_main.c * \brief Stub module containing a main() function. diff --git a/src/test/bench.c b/src/test/bench.c index b7b123eee2..f30b609900 100644 --- a/src/test/bench.c +++ b/src/test/bench.c @@ -3,11 +3,6 @@ * Copyright (c) 2007-2017, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -extern const char tor_git_revision[]; -/* Ordinarily defined in tor_main.c; this bit is just here to provide one - * since we're not linking to tor_main.c */ -const char tor_git_revision[] = ""; - /** * \file bench.c * \brief Benchmarks for lower level Tor modules. diff --git a/src/test/fuzz/fuzzing_common.c b/src/test/fuzz/fuzzing_common.c index 7aee92df63..cd88ce560f 100644 --- a/src/test/fuzz/fuzzing_common.c +++ b/src/test/fuzz/fuzzing_common.c @@ -9,9 +9,6 @@ #include "crypto.h" #include "crypto_ed25519.h" -extern const char tor_git_revision[]; -const char tor_git_revision[] = ""; - static or_options_t *mock_options = NULL; static const or_options_t * mock_get_options(void) diff --git a/src/test/testing_common.c b/src/test/testing_common.c index 7e9c47b48d..e43fa46c84 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -3,12 +3,6 @@ * Copyright (c) 2007-2017, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -extern const char tor_git_revision[]; - -/* Ordinarily defined in tor_main.c; this bit is just here to provide one - * since we're not linking to tor_main.c */ -const char tor_git_revision[] = ""; - /** * \file test_common.c * \brief Common pieces to implement unit tests. From fa02ea102e3ccc946d269788e88c6818e84ad6f8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 18 Oct 2017 14:26:29 -0400 Subject: [PATCH 2/6] Add a public tor_api.h with an implementation in tor_api.c The main effect of this change is to commit to an extensible long-term API. Closes ticket 23684. --- changes/ticket23845 | 5 +++ src/or/include.am | 9 +++- src/or/main.c | 12 ++++-- src/or/main.h | 2 - src/or/tor_api.c | 88 +++++++++++++++++++++++++++++++++++++++ src/or/tor_api.h | 82 ++++++++++++++++++++++++++++++++++++ src/or/tor_api_internal.h | 20 +++++++++ 7 files changed, 210 insertions(+), 8 deletions(-) create mode 100644 src/or/tor_api.c create mode 100644 src/or/tor_api.h create mode 100644 src/or/tor_api_internal.h diff --git a/changes/ticket23845 b/changes/ticket23845 index 01f57374b4..93c150bdb0 100644 --- a/changes/ticket23845 +++ b/changes/ticket23845 @@ -1,3 +1,8 @@ + o Major features (embedding): + - There is now a documented stable API for programs that need to + embed Tor. See tor_api.h for full documentation and known bugs. + Closes ticket 23684. + o Code simplification and refactoring: - The tor_git_revision[] constant no longer needs to be redeclared by everything that links against the rest of Tor. Done as part diff --git a/src/or/include.am b/src/or/include.am index 662bd4807c..bc7327064f 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -105,6 +105,7 @@ LIBTOR_A_SOURCES = \ src/or/statefile.c \ src/or/status.c \ src/or/torcert.c \ + src/or/tor_api.c \ src/or/onion_ntor.c \ $(tor_platform_source) @@ -245,9 +246,13 @@ ORHEADERS = \ src/or/scheduler.h \ src/or/statefile.h \ src/or/status.h \ - src/or/torcert.h + src/or/torcert.h \ + src/or/tor_api_internal.h -noinst_HEADERS+= $(ORHEADERS) micro-revision.i +# This may someday want to be an installed file? +noinst_HEADERS += src/or/tor_api.h + +noinst_HEADERS += $(ORHEADERS) micro-revision.i micro-revision.i: FORCE $(AM_V_at)rm -f micro-revision.tmp; \ diff --git a/src/or/main.c b/src/or/main.c index 65b0b8f4df..5152ec10be 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -106,6 +106,8 @@ #include "shared_random.h" #include "statefile.h" #include "status.h" +#include "tor_api.h" +#include "tor_api_internal.h" #include "util_process.h" #include "ext_orport.h" #ifdef USE_DMALLOC @@ -3703,14 +3705,16 @@ sandbox_init_filter(void) return cfg; } -/** Main entry point for the Tor process. Called from main(). */ -/* This function is distinct from main() only so we can link main.c into - * the unittest binary without conflicting with the unittests' main. */ +/* Main entry point for the Tor process. Called from tor_main(), and by + * anybody embedding Tor. */ int -tor_main(int argc, char *argv[]) +tor_run_main(const tor_main_configuration_t *tor_cfg) { int result = 0; + int argc = tor_cfg->argc; + char **argv = tor_cfg->argv; + #ifdef _WIN32 #ifndef HeapEnableTerminationOnCorruption #define HeapEnableTerminationOnCorruption 1 diff --git a/src/or/main.h b/src/or/main.h index 132ab12bbb..3868519c85 100644 --- a/src/or/main.h +++ b/src/or/main.h @@ -74,8 +74,6 @@ void release_lockfile(void); void tor_cleanup(void); void tor_free_all(int postfork); -int tor_main(int argc, char *argv[]); - int do_main_loop(void); int tor_init(int argc, char **argv); diff --git a/src/or/tor_api.c b/src/or/tor_api.c new file mode 100644 index 0000000000..4260cc88f4 --- /dev/null +++ b/src/or/tor_api.c @@ -0,0 +1,88 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file tor_api.c + **/ + +#include "tor_api.h" +#include "tor_api_internal.h" + +// Include this after the above headers, to insure that they don't +// depend on anything else. +#include "orconfig.h" + +#include +#include +#include + +// We don't want to use tor_malloc and tor_free here, since this needs +// to run before anything is initialized at all, and ought to run when +// we're not linked to anything at all. + +#define raw_malloc malloc +#define raw_free free + +tor_main_configuration_t * +tor_main_configuration_new(void) +{ + static const char *fake_argv[] = { "tor" }; + tor_main_configuration_t *cfg = raw_malloc(sizeof(*cfg)); + if (cfg == NULL) + return NULL; + + memset(cfg, 0, sizeof(*cfg)); + + cfg->argc = 1; + cfg->argv = (char **) fake_argv; + + return cfg; +} + +int +tor_main_configuration_set_command_line(tor_main_configuration_t *cfg, + int argc, char *argv[]) +{ + if (cfg == NULL) + return -1; + cfg->argc = argc; + cfg->argv = argv; + return 0; +} + +void +tor_main_configuration_free(tor_main_configuration_t *cfg) +{ + if (cfg == NULL) + return; + raw_free(cfg); +} + +/* Main entry point for the Tor process. Called from main(). + * + * This function is distinct from main() only so we can link main.c into + * the unittest binary without conflicting with the unittests' main. + * + * Some embedders have historically called this function; but that usage is + * deprecated: they should use tor_run_main() instead. + */ +int +tor_main(int argc, char *argv[]) +{ + tor_main_configuration_t *cfg = tor_main_configuration_new(); + if (!cfg) { + puts("INTERNAL ERROR: Allocation failure. Cannot proceed"); + return 1; + } + if (tor_main_configuration_set_command_line(cfg, argc, argv) < 0) { + puts("INTERNAL ERROR: Can't set command line. Cannot proceed."); + return 1; + } + int rv = tor_run_main(cfg); + tor_main_configuration_free(cfg); + return rv; +} + diff --git a/src/or/tor_api.h b/src/or/tor_api.h new file mode 100644 index 0000000000..1699d5c68c --- /dev/null +++ b/src/or/tor_api.h @@ -0,0 +1,82 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file tor_api.h + * \brief Public C API for the Tor network service. + * + * This interface is intended for use by programs that need to link Tor as + * a library, and launch it in a separate thread. If you have the ability + * to run Tor as a separate executable, you should probably do that instead + * of embedding it as a library. + **/ + +#ifndef TOR_API_H +#define TOR_API_H + +typedef struct tor_main_configuration_t tor_main_configuration_t; + +/** + * Create and return a new tor_main_configuration(). + */ +tor_main_configuration_t *tor_main_configuration_new(void); + +/** + * Set the command-line arguments in cfg. + * + * The argc and argv values here are as for main(). The + * contents of the argv pointer must remain unchanged until tor_run_main() has + * finished and you call tor_main_configuration_free(). + * + * Return 0 on success, -1 on failure. + */ +int tor_main_configuration_set_command_line(tor_main_configuration_t *cfg, + int argc, char *argv[]); +/** + * Release all storage held in cfg. + * + * Once you have passed a tor_main_configuration_t to tor_run_main(), you + * must not free it until tor_run_main() has finished. + */ +void tor_main_configuration_free(tor_main_configuration_t *cfg); + +/** + * Run the tor process, as if from the command line. + * + * The command line arguments from tor_main_configuration_set_command_line() + * are taken as if they had been passed to main(). + * + * This function will not return until Tor is done running. It returns zero + * on success, and nonzero on failure. + * + * BUG 23848: In many cases, tor_main will call exit() or abort() instead of + * returning. This is not the intended long-term behavior; we are trying to + * fix it. + * + * BUG 23847: You can only call tor_main() once in a single process; if it + * returns and you call it again, you may crash. This is not intended + * long-term behavior; we are trying to fix it. + * + * LIMITATION: You cannot run more than one instance of Tor in the same + * process at the same time. Concurrent calls will cause undefined behavior. + * We do not currently have plans to change this. + */ +int tor_run_main(const tor_main_configuration_t *); + +/** + * Run the tor process, as if from the command line. + * + * @deprecated Using this function from outside Tor is deprecated; you should + * use use tor_run_main() instead. + * + * BUGS: This function has all the same bugs as tor_run_main(). + * + * LIMITATIONS: This function has all the limitations of tor_run_main(). + */ +int tor_main(int argc, char **argv); + +#endif /* !defined(TOR_API_H) */ + diff --git a/src/or/tor_api_internal.h b/src/or/tor_api_internal.h new file mode 100644 index 0000000000..a69ba76420 --- /dev/null +++ b/src/or/tor_api_internal.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#ifndef TOR_API_INTERNAL_H +#define TOR_API_INTERNAL_H + +/* The contents of this type are private; don't mess with them from outside + * Tor. */ +struct tor_main_configuration_t { + /** As in main() */ + int argc; + /** As in main(). This pointer is owned by the caller */ + char **argv; +}; + +#endif + From e8682c85945b3283adb113f29f9fbd7977a052aa Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 18 Oct 2017 19:34:19 -0400 Subject: [PATCH 3/6] Add a small library to emulate tor_run_main() with exec() --- .gitignore | 1 + configure.ac | 1 + src/tools/include.am | 5 +++ src/tools/tor_runner.c | 78 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 src/tools/tor_runner.c diff --git a/.gitignore b/.gitignore index 671288d418..b8642ee76e 100644 --- a/.gitignore +++ b/.gitignore @@ -211,6 +211,7 @@ uptime-*.json /src/test/fuzz/lf-fuzz-* # /src/tools/ +/src/tools/libtorrunner.a /src/tools/tor-checkkey /src/tools/tor-resolve /src/tools/tor-cov-resolve diff --git a/configure.ac b/configure.ac index c026464269..b9e737cf4c 100644 --- a/configure.ac +++ b/configure.ac @@ -375,6 +375,7 @@ AH_BOTTOM([ AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue") +AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue") dnl Enable C99 when compiling with MIPSpro AC_MSG_CHECKING([for MIPSpro compiler]) diff --git a/src/tools/include.am b/src/tools/include.am index 37936c742f..92cc3f10a2 100644 --- a/src/tools/include.am +++ b/src/tools/include.am @@ -45,3 +45,8 @@ src_tools_tor_cov_gencert_LDADD = src/common/libor-testing.a \ endif EXTRA_DIST += src/tools/tor-fw-helper/README + +if BUILD_LIBTORRUNNER +noinst_LIBRARIES += src/tools/libtorrunner.a +src_tools_libtorrunner_a_SOURCES = src/tools/tor_runner.c src/or/tor_api.c +endif diff --git a/src/tools/tor_runner.c b/src/tools/tor_runner.c new file mode 100644 index 0000000000..ee35b72df3 --- /dev/null +++ b/src/tools/tor_runner.c @@ -0,0 +1,78 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "tor_api.h" +#include "tor_api_internal.h" + +#include "orconfig.h" +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_WAIT_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#include +#include + +#ifndef __GNUC__ +#define __attribute__(x) +#endif + +static void child(const tor_main_configuration_t *cfg) + __attribute__((noreturn)); + +int +tor_run_main(const tor_main_configuration_t *cfg) +{ + pid_t pid = fork(); + if (pid == 0) { + child(cfg); + exit(0); /* Unreachable */ + } + + pid_t stopped_pid; + int status = 0; + do { + stopped_pid = waitpid(pid, &status, 0); + } while (stopped_pid == -1); + + /* Note: these return values are not documented. No return value is + * documented! */ + + if (stopped_pid != pid) { + return -99999; + } + if (WIFSTOPPED(status)) { + return WEXITSTATUS(status); + } + if (WIFSIGNALED(status)) { + return -WTERMSIG(status); + } + + return -999988; +} + +static void +child(const tor_main_configuration_t *cfg) +{ + /* XXXX Close unused file descriptors. */ + + char **args = calloc(cfg->argc+1, sizeof(char *)); + memcpy(args, cfg->argv, cfg->argc * sizeof(char *)); + args[cfg->argc] = NULL; + + int rv = execv(BINDIR "/tor", args); + + if (rv < 0) { + exit(254); + } else { + abort(); /* Unreachable */ + } +} + From 8b313bd4adac122bb01c52af3e616c5c69fd9414 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 1 Nov 2017 13:11:45 -0400 Subject: [PATCH 4/6] Explain purpose, usage, and status of tor_runner.c --- src/tools/tor_runner.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tools/tor_runner.c b/src/tools/tor_runner.c index ee35b72df3..ac398742dc 100644 --- a/src/tools/tor_runner.c +++ b/src/tools/tor_runner.c @@ -4,6 +4,21 @@ * Copyright (c) 2007-2017, The Tor Project, Inc. */ /* See LICENSE for licensing information */ +/** + * @file tor_runner.c + * @brief Experimental module to emulate tor_run_main() API with fork+exec + * + * The functions here are meant to allow the application developer to + * use the tor_run_main() API without having to care whether Tor is + * running in-process or out-of-process. For in-process usage, the + * developer can link Tor as a library and call tor_run_main(); for + * out-of-process usage, the developer can link this library instead. + * + * This interface is EXPERIMENTAL; please let us know if you would like + * to depend on it. We don't know yet whether it will be reliable in + * practice. + */ + #include "tor_api.h" #include "tor_api_internal.h" From 8c491945057fae9b22823ace92acdf997ff28a28 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 1 Nov 2017 13:19:12 -0400 Subject: [PATCH 5/6] Add more usage notes on tor_api.h --- src/or/tor_api.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/or/tor_api.h b/src/or/tor_api.h index 1699d5c68c..1abe6d1145 100644 --- a/src/or/tor_api.h +++ b/src/or/tor_api.h @@ -12,6 +12,19 @@ * a library, and launch it in a separate thread. If you have the ability * to run Tor as a separate executable, you should probably do that instead * of embedding it as a library. + * + * To use this API, first construct a tor_main_configuration_t object using + * tor_main_configuration_new(). Then, you use one or more other function + * calls (such as tor_main_configuration_set_command_line() to configure how + * Tor should be run. Finally, you pass the configuration object to + * tor_run_main(). + * + * At this point, tor_run_main() will block its thread to run a Tor daemon; + * when the Tor daemon exits, it will return. See notes on bugs and + * limitations below. + * + * There is no other public C API to Tor: calling any C Tor function not + * documented in this file is not guaranteed to be stable. **/ #ifndef TOR_API_H @@ -35,6 +48,7 @@ tor_main_configuration_t *tor_main_configuration_new(void); */ int tor_main_configuration_set_command_line(tor_main_configuration_t *cfg, int argc, char *argv[]); + /** * Release all storage held in cfg. * @@ -63,6 +77,12 @@ void tor_main_configuration_free(tor_main_configuration_t *cfg); * LIMITATION: You cannot run more than one instance of Tor in the same * process at the same time. Concurrent calls will cause undefined behavior. * We do not currently have plans to change this. + * + * LIMITATION: While we will try to fix any problems found here, you + * should be aware that Tor was originally written to run as its own + * process, and that the functionality of this file was added later. If + * you find any bugs or strange behavior, please report them, and we'll + * try to straighten them out. */ int tor_run_main(const tor_main_configuration_t *); From 221f5238aed47f4436916a1da5c6f0423c7fe3e1 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 1 Nov 2017 13:21:11 -0400 Subject: [PATCH 6/6] tor_runner.c: Add a circumlocution and a caveat. --- src/tools/tor_runner.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tools/tor_runner.c b/src/tools/tor_runner.c index ac398742dc..9ed2ee5775 100644 --- a/src/tools/tor_runner.c +++ b/src/tools/tor_runner.c @@ -19,6 +19,10 @@ * practice. */ +/* NOTE: This module is supposed to work without the standard Tor utility + * functions. Don't add more dependencies! + */ + #include "tor_api.h" #include "tor_api_internal.h" @@ -73,12 +77,16 @@ tor_run_main(const tor_main_configuration_t *cfg) return -999988; } +/* circumlocution to avoid getting warned about calling calloc instead of + * tor_calloc. */ +#define real_calloc calloc + static void child(const tor_main_configuration_t *cfg) { /* XXXX Close unused file descriptors. */ - char **args = calloc(cfg->argc+1, sizeof(char *)); + char **args = real_calloc(cfg->argc+1, sizeof(char *)); memcpy(args, cfg->argv, cfg->argc * sizeof(char *)); args[cfg->argc] = NULL;