-
- /* Parent process - read messages from the child process over the
- sync pipe. */
- g_free(argv); /* free up arg array */
-
- /* 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[WRITE]);
-
- /* 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(cfile.save_file_fd);
-
- if (fork_child == -1) {
- /* We couldn't even create the child process. */
- error = errno;
- close(sync_pipe[READ]);
- unlink(cfile.save_file);
- g_free(cfile.save_file);
- cfile.save_file = NULL;
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "Couldn't create child process: %s", strerror(error));
- return FALSE;
- }
-
- /* Read a byte count from "sync_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.
- Close the read side of the sync pipe, remove the capture file,
- and report the failure. */
- close(sync_pipe[READ]);
- unlink(cfile.save_file);
- g_free(cfile.save_file);
- cfile.save_file = NULL;
- sync_pipe_wait_for_child(TRUE);
- return FALSE;
- }
- if (c == SP_CAPSTART || c == SP_ERROR_MSG)
- break;
- if (!isdigit(c)) {
- /* Child process handed us crap.
- Close the read side of the sync pipe, remove the capture file,
- and report the failure. */
- close(sync_pipe[READ]);
- unlink(cfile.save_file);
- g_free(cfile.save_file);
- cfile.save_file = NULL;
- 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(FALSE);
- } else
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, msg);
- g_free(msg);
- }
-
- /* Close the sync pipe. */
- close(sync_pipe[READ]);
-
- /* Get rid of the save file - the capture never started. */
- unlink(cfile.save_file);
- g_free(cfile.save_file);
- cfile.save_file = NULL;
- }
- return FALSE;
- }
-
- /* The child process started a capture.
- Attempt to open the capture file and set up to read it. */
- err = cf_start_tail(cfile.save_file, is_tempfile, &cfile);
- if (err != 0) {
- /* We weren't able to open the capture file; user has been
- alerted. Close the sync pipe. */
-
- close(sync_pipe[READ]);
-
- /* Don't unlink the save file - leave it around, for debugging
- purposes. */
- g_free(cfile.save_file);
- cfile.save_file = NULL;
- return FALSE;
- }
- /* We were able to open and set up to read the capture file;
- arrange that our callback be called whenever it's possible
- to read from the sync pipe, so that it's called when
- the child process wants to tell us something. */
- pipe_input_set_handler(sync_pipe[READ], (gpointer) &cfile, &fork_child, sync_pipe_input_cb);
-
- return TRUE;