diff options
author | Guy Harris <guy@alum.mit.edu> | 2000-05-19 22:37:57 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2000-05-19 22:37:57 +0000 |
commit | 586e1b6fca8da9b031bb99b7010c3c77fbd85045 (patch) | |
tree | b83841220dca20b75c6677d43d40353ab51ca5dc /capture.c | |
parent | cd1952d2ecdb3604545458074f7575b64f93e5ee (diff) | |
download | wireshark-586e1b6fca8da9b031bb99b7010c3c77fbd85045.tar.gz wireshark-586e1b6fca8da9b031bb99b7010c3c77fbd85045.tar.bz2 wireshark-586e1b6fca8da9b031bb99b7010c3c77fbd85045.zip |
Move the closes of the save file FD around:
"capture()" should ensure that it's closed before returning, but
it was only getting closed by "wtap_dump_close()" on success, so
close the raw FD on failure (no "wtap_dump" stream is opened on
failure, so we just close the raw FD);
in a "update the display as packets arrive" capture, we should
close the FD in the parent as soon as the fork is done, before
even testing whether the fork succeeded (and we might as well do
the same with the write side of the sync pipe).
svn path=/trunk/; revision=1988
Diffstat (limited to 'capture.c')
-rw-r--r-- | capture.c | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.103 2000/05/19 19:53:48 gram Exp $ + * $Id: capture.c,v 1.104 2000/05/19 22:37:57 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -223,12 +223,23 @@ do_capture(char *capfile_name) _exit(2); } + /* Parent process - read messages from the child process over the + sync pipe. */ + + /* Close the write side of the pipe, so that only the child has it + open, and thus it completely closes, and thus returns to us + an EOF indication, if the child closes it (either deliberately + or by exiting abnormally). */ + close(sync_pipe[1]); + + /* Close the save file FD, as we won't be using it - we'll be opening + it and reading the save file through Wiretap. */ + close(cf.save_file_fd); + if (fork_child == -1) { /* We couldn't even create the child process. */ error = errno; - close(sync_pipe[1]); close(sync_pipe[0]); - close(cf.save_file_fd); unlink(cf.save_file); g_free(cf.save_file); cf.save_file = NULL; @@ -237,12 +248,6 @@ do_capture(char *capfile_name) return; } - close(cf.save_file_fd); - - /* Parent process - read messages from the child process over the - sync pipe. */ - close(sync_pipe[1]); - /* Read a byte count from "sync_pipe[0]", terminated with a colon; if the count is 0, the child process created the capture file and we should start reading from it, otherwise @@ -340,7 +345,6 @@ do_capture(char *capfile_name) } else { /* Not sync mode. */ capture_succeeded = capture(); - close(cf.save_file_fd); if (quit_after_cap) { /* DON'T unlink the save file. Presumably someone wants it. */ gtk_exit(0); @@ -880,6 +884,10 @@ capture(void) return TRUE; error: + /* We can't use the save file, and we have no wtap_dump stream + to close in order to close it, so close the FD directly. */ + close(cf.save_file_fd); + /* We couldn't even start the capture, so get rid of the capture file. */ unlink(cf.save_file); /* silently ignore error */ |