diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2005-04-11 18:57:19 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2005-04-11 18:57:19 +0000 |
commit | 61ccc8baf1f786dc42c7f3e86a564d151974cbb3 (patch) | |
tree | 0a8d003ec4d6e27e1abf45174002438216cbaa0e /capture_sync.c | |
parent | fbace0592cbe08ed1d8f5b199a58b1cde9a61535 (diff) | |
download | wireshark-61ccc8baf1f786dc42c7f3e86a564d151974cbb3.tar.gz wireshark-61ccc8baf1f786dc42c7f3e86a564d151974cbb3.tar.bz2 wireshark-61ccc8baf1f786dc42c7f3e86a564d151974cbb3.zip |
various capture code cleanup and fixes:
display filename in statusbar while capturing
print_usage banner fixed
cf_cb_live_capture_prepare no longer needed
rename sync_pipe_do_capture -> sync_pipe_start
bugfix: sync_pipe_input_wait_for_start replaced by former implementation
fix cleanup of old file in capture_input_new_file
fix a tempfile detection bug (named file showed up as tempfile after capture)
svn path=/trunk/; revision=14053
Diffstat (limited to 'capture_sync.c')
-rw-r--r-- | capture_sync.c | 115 |
1 files changed, 54 insertions, 61 deletions
diff --git a/capture_sync.c b/capture_sync.c index 4ce506621f..ab77f3352b 100644 --- a/capture_sync.c +++ b/capture_sync.c @@ -230,7 +230,7 @@ sync_pipe_quote_encapsulate(const char *string) #define ARGV_NUMBER_LEN 24 gboolean -sync_pipe_do_capture(capture_options *capture_opts, gboolean is_tempfile) { +sync_pipe_start(capture_options *capture_opts, gboolean is_tempfile) { char ssnap[ARGV_NUMBER_LEN]; char scount[ARGV_NUMBER_LEN]; char sfilesize[ARGV_NUMBER_LEN]; @@ -254,7 +254,7 @@ sync_pipe_do_capture(capture_options *capture_opts, gboolean is_tempfile) { int sync_pipe[2]; /* pipe used to send messages from child to parent */ - /*g_warning("sync_pipe_do_capture"); + /*g_warning("sync_pipe_start"); capture_opts_info(capture_opts);*/ capture_opts->fork_child = -1; @@ -502,76 +502,63 @@ sync_pipe_input_wait_for_start(capture_options *capture_opts, int sync_pipe_read char *msg; - /* Read a byte count from "sync_pipe_read", terminated with a + /* Read a byte count from "sync_pipe[PIPE_READ]", terminated with a colon; if the count is 0, the child process created the capture file and we should start reading from it, otherwise the capture couldn't start and the count is a count of bytes of error message, and we should display the message. */ byte_count = 0; for (;;) { - i = read(sync_pipe_read, &c, 1); - if (i == 0) { - /* EOF - the child process died, report the failure. */ - sync_pipe_wait_for_child(capture_opts, TRUE); - return FALSE; - } - - /* the first message should be the capture start or an error message */ - if (c == SP_CAPSTART || c == SP_ERROR_MSG) { - return TRUE; - } + i = read(sync_pipe_read, &c, 1); + if (i == 0) { + /* EOF - the child process died, report the failure. */ + sync_pipe_wait_for_child(capture_opts, TRUE); + return FALSE; + } - if (!isdigit(c)) { + /* the first message should be the capture start or an error message */ + if (c == SP_CAPSTART || c == SP_ERROR_MSG) + break; + if (!isdigit(c)) { /* Child process handed us crap, report the failure. */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Capture child process sent us a bad message"); - return FALSE; - } - - byte_count = byte_count*10 + c - '0'; - - if (c != SP_CAPSTART) { - /* Failure - the child process sent us a message indicating - what the problem was. */ - if (byte_count == 0) { - /* Zero-length message? */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Capture child process failed, but its error message was empty."); - return FALSE; - } - - msg = g_malloc(byte_count + 1); - if (msg == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Capture child process failed, but its error message was too big."); - return FALSE; - } - - i = read(sync_pipe_read, msg, byte_count); - msg[byte_count] = '\0'; - if (i < 0) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Capture child process failed: Error %s reading its error message.", - strerror(errno)); - g_free(msg); - return FALSE; - } - - if (i == 0) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Capture child process failed: EOF reading its error message."); - sync_pipe_wait_for_child(capture_opts, FALSE); - g_free(msg); - return FALSE; - } + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Capture child process sent us a bad message"); + return FALSE; + } + byte_count = byte_count*10 + c - '0'; + } + if (c != SP_CAPSTART) { + /* Failure - the child process sent us a message indicating + what the problem was. */ + if (byte_count == 0) { + /* Zero-length message? */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Capture child process failed, but its error message was empty."); + } else { + msg = g_malloc(byte_count + 1); + if (msg == NULL) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Capture child process failed, but its error message was too big."); + } else { + i = read(sync_pipe_read, msg, byte_count); + msg[byte_count] = '\0'; + if (i < 0) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Capture child process failed: Error %s reading its error message.", + strerror(errno)); + } else if (i == 0) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Capture child process failed: EOF reading its error message."); + sync_pipe_wait_for_child(capture_opts, FALSE); + } else + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, msg); + g_free(msg); + } - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, msg); - g_free(msg); - return FALSE; - } + } + return FALSE; } - g_assert_not_reached(); return TRUE; } @@ -756,6 +743,7 @@ sync_pipe_wait_for_child(capture_options *capture_opts, gboolean always_report) #ifndef _WIN32 +/* convert signal to corresponding name */ static char * sync_pipe_signame(int sig) { @@ -850,20 +838,25 @@ sync_pipe_signame(int sig) #endif +/* user wants to stop the capture run */ void sync_pipe_stop(capture_options *capture_opts) { /* XXX - in which cases this will be 0? */ if (capture_opts->fork_child != -1 && capture_opts->fork_child != 0) { #ifndef _WIN32 + /* send the SIGUSR1 signal to close the capture child gracefully. */ kill(capture_opts->fork_child, SIGUSR1); #else + /* Win32 doesn't have the kill() system call, use the special signal pipe + instead to close the capture child gracefully. */ signal_pipe_capend_to_child(capture_opts); #endif } } +/* Ethereal has to exit, force the capture child to close */ void sync_pipe_kill(capture_options *capture_opts) { |