Revert "Restore feature where nt-services detect non-"run_tor" modes."

This reverts commit 5c240db0bf.
This commit is contained in:
Nick Mathewson 2020-01-17 08:39:49 -05:00
parent 7f03ba06d8
commit d7a22160f5
3 changed files with 35 additions and 29 deletions

View file

@ -1274,13 +1274,6 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
#endif
}
if (tor_cfg->run_tor_only && get_options()->command != CMD_RUN_TOR) {
log_err(LD_CONFIG, "Unsupported command when running as an NT service.");
result = -1;
tor_cleanup();
goto done;
}
switch (get_options()->command) {
case CMD_RUN_TOR:
nt_service_set_state(SERVICE_RUNNING);

View file

@ -29,8 +29,6 @@
#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"
@ -265,6 +263,7 @@ 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();
@ -284,20 +283,24 @@ nt_service_body(int argc, char **argv)
return;
}
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)
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);
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);
tor_run_main(cfg);
tor_main_configuration_free(cfg);
set_main_thread();
run_tor_main_loop();
tor_cleanup();
}
/** Main service entry point. Starts the service control dispatcher and waits
@ -320,14 +323,29 @@ nt_service_main(void)
printf("Service error %d : %s\n", (int) result, errmsg);
tor_free(errmsg);
if (result == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
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)
if (tor_init(backup_argc, backup_argv))
return;
tor_run_main(cfg);
tor_main_configuration_free(cfg);
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();
}
}
}

View file

@ -29,11 +29,6 @@ struct tor_main_configuration_t {
/** Socket that Tor will use as an owning control socket. Owned. */
tor_socket_t owning_controller_socket;
/** Disable commands other than "run tor". Not for use from outside Tor
* itself; if you need to use this for embedding, please contact the tor
* developers. */
int run_tor_only;
};
#endif /* !defined(TOR_API_INTERNAL_H) */