/* Stuff the pointer into the penultimate element of the array, which
is the one at the index specified by "*argc". */
- args[*argc] = arg;
-
+ args[*argc] = g_strdup(arg);
/* Now bump the count. */
(*argc)++;
int i;
guint j;
interface_options interface_opts;
- gboolean no_ifaces;
if (capture_opts->ifaces->len > 1)
capture_opts->use_pcapng = TRUE;
g_snprintf(sautostop_duration, ARGV_NUMBER_LEN, "duration:%d",capture_opts->autostop_duration);
argv = sync_pipe_add_arg(argv, &argc, sautostop_duration);
}
- if (capture_opts->ifaces->len == 0) {
- no_ifaces = TRUE;
- interface_opts.name = g_strdup(capture_opts->iface);
- if (capture_opts->iface_descr) {
- interface_opts.descr = g_strdup(capture_opts->iface_descr);
- } else {
- interface_opts.descr = NULL;
- }
- interface_opts.cfilter = g_strdup(capture_opts->cfilter);
- interface_opts.snaplen = capture_opts->snaplen;
- interface_opts.linktype = capture_opts->linktype;
- interface_opts.promisc_mode = capture_opts->promisc_mode;
-#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
- interface_opts.buffer_size = capture_opts->buffer_size;
-#endif
- interface_opts.monitor_mode = capture_opts->monitor_mode;
-#ifdef HAVE_PCAP_REMOTE
- interface_opts.src_type = capture_opts->src_type;
- if (capture_opts->remote_host) {
- interface_opts.remote_host = g_strdup(capture_opts->remote_host);
- } else {
- interface_opts.remote_host = NULL;
- }
- if (capture_opts->remote_port) {
- interface_opts.remote_port = g_strdup(capture_opts->remote_port);
- } else {
- interface_opts.remote_port = NULL;
- }
- interface_opts.auth_type = capture_opts->auth_type;
- if (capture_opts->auth_username) {
- interface_opts.auth_username = g_strdup(capture_opts->auth_username);
- } else {
- interface_opts.auth_username = NULL;
- }
- if (capture_opts->auth_password) {
- interface_opts.auth_password = g_strdup(capture_opts->auth_password);
- } else {
- interface_opts.auth_password = NULL;
- }
- interface_opts.datatx_udp = capture_opts->datatx_udp;
- interface_opts.nocap_rpcap = capture_opts->nocap_rpcap;
- interface_opts.nocap_local = capture_opts->nocap_local;
-#endif
-#ifdef HAVE_PCAP_SETSAMPLING
- interface_opts.sampling_method = capture_opts->sampling_method;
- interface_opts.sampling_param = capture_opts->sampling_param;
-#endif
- g_array_append_val(capture_opts->ifaces, interface_opts);
- } else {
- no_ifaces = FALSE;
- }
for (j = 0; j < capture_opts->ifaces->len; j++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, j);
argv = sync_pipe_add_arg(argv, &argc, "-f");
argv = sync_pipe_add_arg(argv, &argc, interface_opts.cfilter);
}
-
if (interface_opts.snaplen != WTAP_MAX_PACKET_SIZE) {
argv = sync_pipe_add_arg(argv, &argc, "-s");
g_snprintf(ssnap, ARGV_NUMBER_LEN, "%d", interface_opts.snaplen);
}
#endif
}
- if (no_ifaces) {
- capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, 0);
- }
/* dumpcap should be running in capture child mode (hidden feature) */
#ifndef DEBUG_CHILD
/* Couldn't create the pipe between parent and child. */
report_failure("Couldn't create sync pipe: %s",
win32strerror(GetLastError()));
- g_free( (gpointer) argv[0]);
+ for (i = 0; i < argc; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free( (gpointer) argv);
return FALSE;
}
/* Couldn't create the signal pipe between parent and child. */
report_failure("Couldn't create signal pipe: %s",
win32strerror(GetLastError()));
- g_free( (gpointer) argv[0]);
+ for (i = 0; i < argc; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free( (gpointer) argv);
return FALSE;
}
args->str, win32strerror(GetLastError()));
CloseHandle(sync_pipe_read);
CloseHandle(sync_pipe_write);
- g_free( (gpointer) argv[0]);
+ for (i = 0; i < argc; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free( (gpointer) argv);
return FALSE;
}
#else /* _WIN32 */
if (pipe(sync_pipe) < 0) {
/* Couldn't create the pipe between parent and child. */
- report_failure("Couldn't create sync pipe: %s", strerror(errno));
- g_free( (gpointer) argv[0]);
+ report_failure("Couldn't create sync pipe: %s", g_strerror(errno));
+ for (i = 0; i < argc; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free(argv);
return FALSE;
}
ws_close(sync_pipe[PIPE_READ]);
execv(argv[0], (gpointer)argv);
g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
- argv[0], strerror(errno));
+ argv[0], g_strerror(errno));
sync_pipe_errmsg_to_parent(2, errmsg, "");
/* Exit with "_exit()", so that we don't close the connection
sync_pipe_read_fd = sync_pipe[PIPE_READ];
#endif
- g_free( (gpointer) argv[0]); /* exename */
+ for (i = 0; i < argc; i++) {
+ g_free( (gpointer) argv[i]);
+ }
/* Parent process - read messages from the child process over the
sync pipe. */
if (capture_opts->fork_child == -1) {
/* We couldn't even create the child process. */
- report_failure("Couldn't create child process: %s", strerror(errno));
+ report_failure("Couldn't create child process: %s", g_strerror(errno));
ws_close(sync_pipe_read_fd);
#ifdef _WIN32
ws_close(capture_opts->signal_pipe_write_fd);
SECURITY_ATTRIBUTES sa;
STARTUPINFO si;
PROCESS_INFORMATION pi;
- int i;
#else
char errmsg[1024+1];
int sync_pipe[2]; /* pipe used to send messages from child to parent */
int data_pipe[2]; /* pipe used to send data from child to parent */
#endif
-
+ int i;
*fork_child = -1;
*data_read_fd = -1;
*message_read_fd = -1;
/* Couldn't create the message pipe between parent and child. */
*msg = g_strdup_printf("Couldn't create sync pipe: %s",
win32strerror(GetLastError()));
- g_free( (gpointer) argv[0]);
+ for (i = 0; argv[i] != NULL; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free( (gpointer) argv);
return -1;
}
win32strerror(GetLastError()));
CloseHandle(sync_pipe[PIPE_READ]);
CloseHandle(sync_pipe[PIPE_WRITE]);
- g_free( (gpointer) argv[0]);
+ for (i = 0; argv[i] != NULL; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free( (gpointer) argv);
return -1;
}
CloseHandle(data_pipe[PIPE_WRITE]);
CloseHandle(sync_pipe[PIPE_READ]);
CloseHandle(sync_pipe[PIPE_WRITE]);
- g_free( (gpointer) argv[0]);
+ for (i = 0; argv[i] != NULL; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free( (gpointer) argv);
return -1;
}
/* Create a pipe for the child process to send us messages */
if (pipe(sync_pipe) < 0) {
/* Couldn't create the message pipe between parent and child. */
- *msg = g_strdup_printf("Couldn't create sync pipe: %s", strerror(errno));
- g_free( (gpointer) argv[0]);
+ *msg = g_strdup_printf("Couldn't create sync pipe: %s", g_strerror(errno));
+ for (i = 0; argv[i] != NULL; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free(argv);
return -1;
}
/* Create a pipe for the child process to send us data */
if (pipe(data_pipe) < 0) {
/* Couldn't create the data pipe between parent and child. */
- *msg = g_strdup_printf("Couldn't create data pipe: %s", strerror(errno));
+ *msg = g_strdup_printf("Couldn't create data pipe: %s", g_strerror(errno));
ws_close(sync_pipe[PIPE_READ]);
ws_close(sync_pipe[PIPE_WRITE]);
- g_free( (gpointer) argv[0]);
+ for (i = 0; argv[i] != NULL; i++) {
+ g_free( (gpointer) argv[i]);
+ }
g_free(argv);
return -1;
}
ws_close(sync_pipe[PIPE_WRITE]);
execv(argv[0], (gpointer)argv);
g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
- argv[0], strerror(errno));
+ argv[0], g_strerror(errno));
sync_pipe_errmsg_to_parent(2, errmsg, "");
/* Exit with "_exit()", so that we don't close the connection
*message_read_fd = sync_pipe[PIPE_READ];
#endif
- g_free( (gpointer) argv[0]); /* exename */
+ for (i = 0; argv[i] != NULL; i++) {
+ g_free( (gpointer) argv[i]);
+ }
/* Parent process - read messages from the child process over the
sync pipe. */
if (*fork_child == -1) {
/* We couldn't even create the child process. */
- *msg = g_strdup_printf("Couldn't create child process: %s", strerror(errno));
+ *msg = g_strdup_printf("Couldn't create child process: %s", g_strerror(errno));
ws_close(*data_read_fd);
ws_close(*message_read_fd);
return -1;
error = errno;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
"read from pipe %d: error(%u): %s", pipe_fd, error,
- strerror(error));
+ g_strerror(error));
*msg = g_strdup_printf("Error reading from sync pipe: %s",
- strerror(error));
+ g_strerror(error));
return newly;
}
} else if (newly < 0) {
/* error */
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
- "read from pipe %d: error(%u): %s", pipe_fd, errno, strerror(errno));
+ "read from pipe %d: error(%u): %s", pipe_fd, errno, g_strerror(errno));
return newly;
} else if (bytes[offset] == '\n') {
break;
alerted. Close the sync pipe. */
ws_close(source);
- /* the child has send us a filename which we couldn't open.
- this probably means, the child is creating files faster than we can handle it.
- this should only be the case for very fast file switches
- we can't do much more than telling the child to stop
- (this is the "emergency brake" if user e.g. wants to switch files every second) */
+ /* The child has sent us a filename which we couldn't open.
+
+ This could mean that the child is creating files faster
+ than we can handle it. (XXX - why would that result in
+ a failure to open the file?)
+
+ That should only be the case for very fast file switches;
+ We can't do much more than telling the child to stop.
+ (This is the "emergency brake" if the user e.g. wants to
+ switch files every second).
+
+ This can also happen if the user specified "-", meaning
+ "standard output", as the capture file. */
sync_pipe_stop(capture_opts);
+ capture_input_closed(capture_opts, NULL);
+ return FALSE;
}
break;
case SP_PACKET_COUNT:
/* the capture child will close the sync_pipe, nothing to do for now */
/* (an error message doesn't mean we have to stop capturing) */
break;
- case SP_BAD_FILTER:
- capture_input_cfilter_error_message(capture_opts, buffer);
- /* the capture child will close the sync_pipe, nothing to do for now */
- break;
+ case SP_BAD_FILTER: {
+ char *ch;
+ int index;
+
+ ch = strtok(buffer, ":");
+ index = (int)strtol(ch, NULL, 10);
+ ch = strtok(NULL, ":");
+ capture_input_cfilter_error_message(capture_opts, index, ch);
+ /* the capture child will close the sync_pipe, nothing to do for now */
+ break;
+ }
case SP_DROPS:
capture_input_drops(capture_opts, (guint32)strtoul(buffer, NULL, 10));
break;
g_assert(fork_child != -1);
*msgp = NULL; /* assume no error */
- ret = 0;
#ifdef _WIN32
if (_cwait(&fork_child_status, fork_child, _WAIT_CHILD) == -1) {
- *msgp = g_strdup_printf("Error from cwait(): %s", strerror(errno));
+ *msgp = g_strdup_printf("Error from cwait(): %s", g_strerror(errno));
ret = -1;
} else {
/*
ret = -1;
}
} else {
- *msgp = g_strdup_printf("Error from waitpid(): %s", strerror(errno));
+ *msgp = g_strdup_printf("Error from waitpid(): %s", g_strerror(errno));
ret = -1;
}
#endif
ret = write(capture_opts->signal_pipe_write_fd, quit_msg, sizeof quit_msg);
if(ret == -1) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
- "signal_pipe_capquit_to_child: %d header: error %s", capture_opts->signal_pipe_write_fd, strerror(errno));
+ "signal_pipe_capquit_to_child: %d header: error %s", capture_opts->signal_pipe_write_fd, g_strerror(errno));
}
}
#endif
int sts = kill(capture_opts->fork_child, SIGINT);
if (sts != 0) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
- "Sending SIGINT to child failed: %s\n", strerror(errno));
+ "Sending SIGINT to child failed: %s\n", g_strerror(errno));
}
#else
#define STOP_SLEEP_TIME 500 /* ms */
int sts = kill(fork_child, SIGTERM); /* SIGTERM so it can clean up if necessary */
if (sts != 0) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
- "Sending SIGTERM to child failed: %s\n", strerror(errno));
+ "Sending SIGTERM to child failed: %s\n", g_strerror(errno));
}
#else
/* Remark: This is not the preferred method of closing a process!