aboutsummaryrefslogtreecommitdiffstats
path: root/capchild
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-03-12 08:49:12 -0700
committerAnders Broman <a.broman58@gmail.com>2018-03-13 17:18:30 +0000
commita2f926761525ac67feeda742a796917a1f043b33 (patch)
treecf79825b1d983633dc7d7f6d1a28ec2fe70dfa1e /capchild
parent0874b8bac6ca89f1d91d30d66d54f425e4e7c81e (diff)
Windows: Always assign newly-created processes to our job.
Move ws_pipe_kill_child_on_exit to win32-utils. Add win32_create_process, which calls CreateProcess + AssignProcessToJobObject. Use win32_create_process instead of CreateProcess everywhere. Bug: 1419 Change-Id: I7a1f17dddf6a73f6973d54621f271b69311400d1 Reviewed-on: https://code.wireshark.org/review/26448 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'capchild')
-rw-r--r--capchild/capture_sync.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c
index e0c7e330e8..1dc12b35d0 100644
--- a/capchild/capture_sync.c
+++ b/capchild/capture_sync.c
@@ -23,6 +23,7 @@
#ifdef _WIN32
#include <wsutil/unicode-utils.h>
#include <wsutil/win32-utils.h>
+#include <wsutil/ws_pipe.h>
#endif
#ifdef HAVE_SYS_WAIT_H
@@ -219,7 +220,6 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
HANDLE signal_pipe; /* named pipe used to send messages from parent to child (currently only stop) */
GString *args = g_string_sized_new(200);
gchar *quoted_arg;
- gunichar2 *wcommandline;
SECURITY_ATTRIBUTES sa;
STARTUPINFO si;
PROCESS_INFORMATION pi;
@@ -519,11 +519,10 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
g_string_append(args, quoted_arg);
g_free(quoted_arg);
}
- wcommandline = g_utf8_to_utf16(args->str, (glong)args->len, NULL, NULL, NULL);
/* call dumpcap */
- if(!CreateProcess(utf_8to16(argv[0]), wcommandline, NULL, NULL, TRUE,
- CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
+ if(!win32_create_process(argv[0], args->str, NULL, NULL, TRUE,
+ CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
report_failure("Couldn't run %s in child process: %s",
args->str, win32strerror(GetLastError()));
ws_close(sync_pipe_read_fd); /* Should close sync_pipe_read */
@@ -531,14 +530,12 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
CloseHandle(signal_pipe);
free_argv(argv, argc);
g_string_free(args, TRUE);
- g_free(wcommandline);
return FALSE;
}
cap_session->fork_child = pi.hProcess;
/* We may need to store this and close it later */
CloseHandle(pi.hThread);
g_string_free(args, TRUE);
- g_free(wcommandline);
cap_session->signal_pipe_write_fd = signal_pipe_write_fd;
@@ -646,7 +643,6 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
HANDLE data_pipe[2]; /* pipe used to send data from child to parent */
GString *args = g_string_sized_new(200);
gchar *quoted_arg;
- gunichar2 *wcommandline;
SECURITY_ATTRIBUTES sa;
STARTUPINFO si;
PROCESS_INFORMATION pi;
@@ -752,11 +748,10 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
g_string_append(args, quoted_arg);
g_free(quoted_arg);
}
- wcommandline = g_utf8_to_utf16(args->str, (glong)args->len, NULL, NULL, NULL);
/* call dumpcap */
- if(!CreateProcess(utf_8to16(argv[0]), wcommandline, NULL, NULL, TRUE,
- CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
+ if(!win32_create_process(argv[0], args->str, NULL, NULL, TRUE,
+ CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
*msg = g_strdup_printf("Couldn't run %s in child process: %s",
args->str, win32strerror(GetLastError()));
ws_close(*data_read_fd); /* Should close data_pipe[PIPE_READ] */
@@ -764,14 +759,12 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
ws_close(*message_read_fd); /* Should close sync_pipe[PIPE_READ] */
CloseHandle(sync_pipe[PIPE_WRITE]);
g_string_free(args, TRUE);
- g_free(wcommandline);
return -1;
}
*fork_child = pi.hProcess;
/* We may need to store this and close it later */
CloseHandle(pi.hThread);
g_string_free(args, TRUE);
- g_free(wcommandline);
#else /* _WIN32 */
/* Create a pipe for the child process to send us messages */
if (pipe(sync_pipe) < 0) {