if (!retval) {
log_warn(LD_GENERAL,
- "Failed to create child process %s: %s", filename,
+ "Failed to create child process %s: %s", filename?filename:argv[0],
format_win32_error(GetLastError()));
} else {
// TODO: Close hProcess and hThread in process_handle.pid?
/* Assume tor-fw-helper will succeed, start it later*/
time_to_run_helper = now + TIME_TO_EXEC_FWHELPER_SUCCESS;
+#ifdef MS_WINDOWS
+ /* Passing NULL as lpApplicationName makes Windows search for the .exe */
+ child_handle = tor_spawn_background(NULL, argv);
+#else
child_handle = tor_spawn_background(filename, argv);
+#endif
if (child_handle.status < 0) {
log_warn(LD_GENERAL, "Failed to start port forwarding helper %s",
filename);
char stdout_buf[100], stderr_buf[100];
/* Start the program */
+#ifdef MS_WINDOWS
+ process_handle = tor_spawn_background(NULL, argv);
+#else
process_handle = tor_spawn_background(argv[0], argv);
+#endif
tt_int_op(process_handle.status, ==, expected_status);
;
}
-static char*
-get_windows_path(const char *process_name, const char **dest)
-{
-#ifdef MS_WINDOWS
- char fn[MAX_PATH];
- DWORD retval;
- char *new_fn = NULL;
- int i;
-
- /* Get the file name of the current module */
- retval = GetModuleFileName(NULL, fn, sizeof(fn));
- if (retval >= sizeof(fn)) {
- log_warn(LD_GENERAL, "Executable path name was longer than maximum (%d)", sizeof(fn));
- return NULL;
- }
-
- /* Remove the filename component */
- for (i = retval - 1; i >= 0; i--) {
- /* \0 terminate at first path separator from end */
- if ('\\' == fn[i] || '/' == fn[i]) {
- fn[i] = '\0';
- break;
- }
- }
-
- tor_asprintf(&new_fn, "%s\\%s", fn, process_name);
- *dest = new_fn;
- return new_fn;
-#else
- (void)process_name;
- (void)dest;
- return NULL;
-#endif
-}
-
/** Check that we can launch a process and read the output */
static void
test_util_spawn_background_ok(void *ptr)
{
#ifdef MS_WINDOWS
- const char *argv[] = {NULL, "--test", NULL};
+ const char *argv[] = {"test-child.exe", "--test", NULL};
const char *expected_out = "OUT\r\n--test\r\nSLEEPING\r\nDONE\r\n";
const char *expected_err = "ERR\r\n";
- char *filename;
-
- /* Find path to test-child.exe (same directory as this executable */
- filename = get_windows_path("test-child.exe", argv);
- tt_assert(filename != NULL);
- log_warn(LD_GENERAL, "Using %s as path", filename);
#else
const char *argv[] = {BUILDDIR "/src/test/test-child", "--test", NULL};
const char *expected_out = "OUT\n--test\nSLEEPING\nDONE\n";
(void)ptr;
run_util_spawn_background(argv, expected_out, expected_err, 0, 1);
- done:
-#ifdef MS_WINDOWS
- tor_free(filename);
-#else
- ;
-#endif
}
/** Check that failing to find the executable works as expected */
process_handle_t process_handle;
char stdout_buf[100], stderr_buf[100];
#ifdef MS_WINDOWS
- const char *argv[] = {NULL, "--test", NULL};
+ const char *argv[] = {"test-child.exe", "--test", NULL};
const char *expected_out[] = { "OUT\r\n--test\r\nSLEEPING\r\n",
"DONE\r\n",
NULL };
const char *expected_err = "ERR\r\n";
int expected_out_ctr;
- char *filename;
-
- /* Find path to test-child.exe (same directory as this executable */
- filename = get_windows_path("test-child.exe", argv);
- tt_assert(filename != NULL);
- log_warn(LD_GENERAL, "Using %s as path", filename);
#else
const char *argv[] = {BUILDDIR "/src/test/test-child", "--test", NULL};
const char *expected_out = "OUT\n--test\nSLEEPING\nDONE\n";
(void)ptr;
/* Start the program */
- process_handle = tor_spawn_background(argv[0], argv);
+ process_handle = tor_spawn_background(NULL, argv);
tt_int_op(process_handle.status, ==, expected_status);
- tor_free(filename);
/* Check stdout */
#ifdef MS_WINDOWS
tt_int_op(pos, ==, strlen(expected_err));
done:
-#ifdef MS_WINDOWS
- tor_free(filename);
-#else
;
-#endif
}
static void