aboutsummaryrefslogtreecommitdiffstats
path: root/capture_loop.c
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2005-04-11 18:39:31 +0000
committerUlf Lamping <ulf.lamping@web.de>2005-04-11 18:39:31 +0000
commitfbace0592cbe08ed1d8f5b199a58b1cde9a61535 (patch)
tree2cf06247798b6cdd11fed0ff7b6fb27934317ba5 /capture_loop.c
parent2bc81b2a48e33a3106da06712e0c3fe8393d83a7 (diff)
fix some error handling
fflush new output file (to have at least the pcap header on disk) before sending the corresponding message to the capture parent svn path=/trunk/; revision=14052
Diffstat (limited to 'capture_loop.c')
-rw-r--r--capture_loop.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/capture_loop.c b/capture_loop.c
index 2188dd7074..b1b5a7e94d 100644
--- a/capture_loop.c
+++ b/capture_loop.c
@@ -959,7 +959,9 @@ capture_loop_dispatch(capture_options *capture_opts, loop_data *ld,
/* open the output file (temporary/specified name/ringbuffer) */
/* Returns TRUE if the file opened successfully, FALSE otherwise. */
static gboolean
-capture_loop_open_output(capture_options *capture_opts, int *save_file_fd) {
+capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
+ char *errmsg, int errmsg_len) {
+
char tmpname[128+1];
gchar *capfile_name;
gboolean is_tempfile;
@@ -977,8 +979,10 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd) {
(capture_opts->has_ring_num_files) ? capture_opts->ring_num_files : 0);
/* we need the ringbuf name */
- g_free(capfile_name);
- capfile_name = g_strdup(ringbuf_current_filename());
+ if(*save_file_fd != -1) {
+ g_free(capfile_name);
+ capfile_name = g_strdup(ringbuf_current_filename());
+ }
} else {
/* Try to open/create the specified file for use as a capture buffer. */
*save_file_fd = open(capfile_name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT,
@@ -1002,7 +1006,13 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd) {
if (capture_opts->multi_files_on) {
ringbuf_error_cleanup();
}
- open_failure_alert_box(capfile_name, errno, TRUE);
+
+ g_snprintf(errmsg, errmsg_len,
+ "The file to which the capture would be saved (\"%s\") "
+ "could not be opened: %s.", capfile_name,
+ strerror(errno));
+
+ /*open_failure_alert_box(capfile_name, errno, TRUE);*/
}
g_free(capfile_name);
return FALSE;
@@ -1101,7 +1111,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
/* open the output file (temporary/specified name/ringbuffer) */
- if (!capture_loop_open_output(capture_opts, &save_file_fd)) {
+ if (!capture_loop_open_output(capture_opts, &save_file_fd, errmsg, sizeof(errmsg))) {
goto error;
}
@@ -1197,6 +1207,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
if (cnd_file_duration) {
cnd_reset(cnd_file_duration);
}
+ fflush(wtap_dump_file(ld.wtap_pdh));
sync_pipe_filename_to_parent(capture_opts->save_file);
} else {
/* File switch failed: stop here */
@@ -1280,6 +1291,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
cnd_reset(cnd_file_duration);
if(cnd_autostop_size)
cnd_reset(cnd_autostop_size);
+ fflush(wtap_dump_file(ld.wtap_pdh));
sync_pipe_filename_to_parent(capture_opts->save_file);
} else {
/* File switch failed: stop here */