aboutsummaryrefslogtreecommitdiff
path: root/src/app/main/ntmain.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-01-14 12:42:41 -0500
committerNick Mathewson <nickm@torproject.org>2020-01-14 12:42:41 -0500
commitc2dc94d8ebcd5fdd1076abb41ff0ecee6c092f4f (patch)
tree8806c17bfc9af54185570382ea629853dd801c15 /src/app/main/ntmain.c
parentdec11793ba2fdaeb975e1566b68846431fb85110 (diff)
parentb6f099672b90cb606d89bfcb0cae01ea49e46b9c (diff)
downloadtor-c2dc94d8ebcd5fdd1076abb41ff0ecee6c092f4f.tar.gz
tor-c2dc94d8ebcd5fdd1076abb41ff0ecee6c092f4f.zip
Merge branch 'ticket32883'
Diffstat (limited to 'src/app/main/ntmain.c')
-rw-r--r--src/app/main/ntmain.c52
1 files changed, 17 insertions, 35 deletions
diff --git a/src/app/main/ntmain.c b/src/app/main/ntmain.c
index ced158e686..96da1690f2 100644
--- a/src/app/main/ntmain.c
+++ b/src/app/main/ntmain.c
@@ -29,6 +29,8 @@
#include "lib/evloop/compat_libevent.h"
#include "lib/fs/winlib.h"
#include "lib/log/win32err.h"
+#include "feature/api/tor_api.h"
+#include "feature/api/tor_api_internal.h"
#include <windows.h>
#define GENSRV_SERVICENAME "tor"
@@ -263,7 +265,6 @@ nt_service_control(DWORD request)
static void
nt_service_body(int argc, char **argv)
{
- int r;
(void) argc; /* unused */
(void) argv; /* unused */
nt_service_loadlibrary();
@@ -283,24 +284,20 @@ nt_service_body(int argc, char **argv)
return;
}
- r = tor_init(backup_argc, backup_argv);
- if (r) {
- /* Failed to start the Tor service */
- r = NT_SERVICE_ERROR_TORINIT_FAILED;
- service_status.dwCurrentState = SERVICE_STOPPED;
- service_status.dwWin32ExitCode = r;
- service_status.dwServiceSpecificExitCode = r;
- service_fns.SetServiceStatus_fn(hStatus, &service_status);
+ tor_main_configuration_t *cfg = tor_main_configuration_new();
+ cfg->run_tor_only = 1;
+ if (tor_main_configuration_set_command_line(cfg, backup_argc,
+ backup_argv) < 0)
return;
- }
/* Set the service's status to SERVICE_RUNNING and start the main
* event loop */
service_status.dwCurrentState = SERVICE_RUNNING;
service_fns.SetServiceStatus_fn(hStatus, &service_status);
- set_main_thread();
- run_tor_main_loop();
- tor_cleanup();
+
+ tor_run_main(cfg);
+
+ tor_main_configuration_free(cfg);
}
/** Main service entry point. Starts the service control dispatcher and waits
@@ -323,29 +320,14 @@ nt_service_main(void)
printf("Service error %d : %s\n", (int) result, errmsg);
tor_free(errmsg);
if (result == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
- if (tor_init(backup_argc, backup_argv))
+ tor_main_configuration_t *cfg = tor_main_configuration_new();
+ cfg->run_tor_only = 1;
+ if (tor_main_configuration_set_command_line(cfg, backup_argc,
+ backup_argv) < 0)
return;
- switch (get_options()->command) {
- case CMD_RUN_TOR:
- run_tor_main_loop();
- break;
- case CMD_LIST_FINGERPRINT:
- case CMD_HASH_PASSWORD:
- case CMD_VERIFY_CONFIG:
- case CMD_DUMP_CONFIG:
- case CMD_KEYGEN:
- case CMD_KEY_EXPIRATION:
- log_err(LD_CONFIG, "Unsupported command (--list-fingerprint, "
- "--hash-password, --keygen, --dump-config, --verify-config, "
- "or --key-expiration) in NT service.");
- break;
- case CMD_RUN_UNITTESTS:
- case CMD_IMMEDIATE:
- default:
- log_err(LD_CONFIG, "Illegal command number %d: internal error.",
- get_options()->command);
- }
- tor_cleanup();
+
+ tor_run_main(cfg);
+ tor_main_configuration_free(cfg);
}
}
}