- break;
- case SP_PACKET_COUNT:
- nread = atoi(buffer);
- g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", nread);
- capture_input_new_packets(capture_opts, nread);
- break;
- case SP_ERROR_MSG:
- /* convert primary message */
- pipe_convert_header(buffer, 4, &indicator, &primary_len);
- primary_msg = buffer+4;
- /* convert secondary message */
- pipe_convert_header(primary_msg + primary_len, 4, &indicator, &secondary_len);
- secondary_msg = primary_msg + primary_len + 4;
- /* message output */
- capture_input_error_message(capture_opts, primary_msg, secondary_msg);
- /* the capture child will close the sync_pipe, nothing to do for now */
- /* (an error message doesn't mean we have to stop capturing) */
- break;
- case SP_BAD_FILTER:
- capture_input_cfilter_error_message(capture_opts, buffer);
- /* the capture child will close the sync_pipe, nothing to do for now */
- break;
- case SP_DROPS:
- capture_input_drops(capture_opts, (guint32)strtoul(buffer, NULL, 10));
- break;
- default:
- g_assert_not_reached();
- }
-
- return TRUE;
+
+ /* we got a valid message block from the child, process it */
+ switch(indicator) {
+ case SP_FILE:
+ if(!capture_input_new_file(capture_opts, buffer)) {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: file failed, closing capture");
+
+ /* We weren't able to open the new capture file; user has been
+ alerted. Close the sync pipe. */
+ ws_close(source);
+
+ /* The child has sent us a filename which we couldn't open.
+
+ This could mean that the child is creating files faster
+ than we can handle it. (XXX - why would that result in
+ a failure to open the file?)
+
+ That should only be the case for very fast file switches;
+ We can't do much more than telling the child to stop.
+ (This is the "emergency brake" if the user e.g. wants to
+ switch files every second).
+
+ This can also happen if the user specified "-", meaning
+ "standard output", as the capture file. */
+ sync_pipe_stop(capture_opts);
+ capture_input_closed(capture_opts, NULL);
+ return FALSE;
+ }
+ break;
+ case SP_PACKET_COUNT:
+ nread = atoi(buffer);
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", nread);
+ capture_input_new_packets(capture_opts, nread);
+ break;
+ case SP_ERROR_MSG:
+ /* convert primary message */
+ pipe_convert_header(buffer, 4, &indicator, &primary_len);
+ primary_msg = buffer+4;
+ /* convert secondary message */
+ pipe_convert_header(primary_msg + primary_len, 4, &indicator, &secondary_len);
+ secondary_msg = primary_msg + primary_len + 4;
+ /* message output */
+ capture_input_error_message(capture_opts, primary_msg, secondary_msg);
+ /* the capture child will close the sync_pipe, nothing to do for now */
+ /* (an error message doesn't mean we have to stop capturing) */
+ break;
+ case SP_BAD_FILTER: {
+ char *ch;
+ int index;
+
+ ch = strtok(buffer, ":");
+ index = (int)strtol(ch, NULL, 10);
+ ch = strtok(NULL, ":");
+ capture_input_cfilter_error_message(capture_opts, index, ch);
+ /* the capture child will close the sync_pipe, nothing to do for now */
+ break;
+ }
+ case SP_DROPS:
+ capture_input_drops(capture_opts, (guint32)strtoul(buffer, NULL, 10));
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ return TRUE;