In the capture_loop.c code, open the capture device for input before
doing anything with the output file, so that 1) if the attempt to open the capture device fails, we don't bother creating any output files; 2) we could relinquish privileges permanently as soon as we finish opening the capture device, so we don't have to give them up temporarily when opening the output file, reclaim them to open the input device, and then give them up permanently; (we already do that in Tethereal). While we're at it, set the capture filter immediately after opening the capture device, so we quit before opening capture devices if that fails. svn path=/trunk/; revision=17468
This commit is contained in:
parent
0881211a12
commit
6f5916eb36
|
@ -608,8 +608,8 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
|
|||
g_snprintf(errmsg, errmsg_len,
|
||||
"The capture session could not be initiated (%s).", open_err_str);
|
||||
g_snprintf(secondary_errmsg, secondary_errmsg_len,
|
||||
"Please check to make sure you have sufficient permissions, and that\n"
|
||||
"you have the proper interface or pipe specified.%s", libpcap_warn);
|
||||
"Please check to make sure you have sufficient permissions, and that you have\n"
|
||||
"the proper interface or pipe specified.%s", libpcap_warn);
|
||||
}
|
||||
/*
|
||||
* Else pipe (or file) does exist and cap_pipe_open_live() has
|
||||
|
@ -1121,12 +1121,6 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
|
|||
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop starting ...");
|
||||
capture_opts_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, capture_opts);
|
||||
|
||||
/* open the output file (temporary/specified name/ringbuffer) */
|
||||
if (!capture_loop_open_output(capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) {
|
||||
*secondary_errmsg = '\0';
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* open the "input file" from network interface or capture pipe */
|
||||
if (!capture_loop_open_input(capture_opts, &ld, errmsg, sizeof(errmsg),
|
||||
secondary_errmsg, sizeof(secondary_errmsg))) {
|
||||
|
@ -1152,6 +1146,12 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
|
|||
goto error;
|
||||
}
|
||||
|
||||
/* open the output file (temporary/specified name/ringbuffer) */
|
||||
if (!capture_loop_open_output(capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) {
|
||||
*secondary_errmsg = '\0';
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* set up to write to the already-opened capture output file/files */
|
||||
if (!capture_loop_init_output(capture_opts, save_file_fd, &ld, errmsg, sizeof(errmsg))) {
|
||||
*secondary_errmsg = '\0';
|
||||
|
|
12
tethereal.c
12
tethereal.c
|
@ -1548,12 +1548,6 @@ capture(void)
|
|||
*/
|
||||
relinquish_special_privs_perm();
|
||||
|
||||
/* open the output file (temporary/specified name/ringbuffer/named pipe/stdout) */
|
||||
if (!capture_loop_open_output(&capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) {
|
||||
*secondary_errmsg = '\0';
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* init the input filter from the network interface (capture pipe will do nothing) */
|
||||
switch (capture_loop_init_filter(ld.pcap_h, ld.from_cap_pipe, capture_opts.iface, capture_opts.cfilter)) {
|
||||
|
||||
|
@ -1573,6 +1567,12 @@ capture(void)
|
|||
goto error;
|
||||
}
|
||||
|
||||
/* open the output file (temporary/specified name/ringbuffer/named pipe/stdout) */
|
||||
if (!capture_loop_open_output(&capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) {
|
||||
*secondary_errmsg = '\0';
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* set up to write to the already-opened capture output file/files */
|
||||
if(!capture_loop_init_output(&capture_opts, save_file_fd, &ld, errmsg, sizeof errmsg)) {
|
||||
*secondary_errmsg = '\0';
|
||||
|
|
Loading…
Reference in New Issue