/* * Don't actually init nids/pcap until all the pre tags are loaded. * TRUE - call again in 1ms * FALSE - don't call again */ gboolean moloch_ready_gfunc (gpointer UNUSED(user_data)) { if (moloch_db_tags_loading() || moloch_http_queue_length(esServer)) return TRUE; if (config.debug) LOG("maxField = %d", config.maxField); if (config.pcapReadOffline) { if (config.dryRun || !config.copyPcap) { moloch_writers_start("inplace"); } else { moloch_writers_start(NULL); } } else { if (config.dryRun) { moloch_writers_start("null"); } else { moloch_writers_start(NULL); } } moloch_reader_start(); return FALSE; }
LOCAL gboolean reader_libpcapfile_read() { // pause reading if too many waiting disk operations if (moloch_writer_queue_length() > 10) { return TRUE; } // pause reading if too many waiting ES operations if (moloch_http_queue_length(esServer) > 50) { return TRUE; } // pause reading if too many packets are waiting to be processed if (moloch_packet_outstanding() > (int32_t)(config.maxPacketsInQueue/3)) { return TRUE; } int r; if (pktsToRead > 0) { r = pcap_dispatch(pcap, MIN(pktsToRead, 5000), reader_libpcapfile_pcap_cb, NULL); if (r > 0) pktsToRead -= r; if (pktsToRead == 0) r = 0; } else { r = pcap_dispatch(pcap, 5000, reader_libpcapfile_pcap_cb, NULL); } moloch_packet_batch_flush(&batch); // Some kind of failure, move to the next file or quit if (r <= 0) { if (config.pcapDelete && r == 0) { if (config.debug) LOG("Deleting %s", offlinePcapFilename); int rc = unlink(offlinePcapFilename); if (rc != 0) LOG("Failed to delete file %s %s (%d)", offlinePcapFilename, strerror(errno), errno); } pcap_close(pcap); if (reader_libpcapfile_next()) { return FALSE; } if (config.pcapMonitor) g_timeout_add(100, reader_libpcapfile_monitor_gfunc, 0); else moloch_quit(); return FALSE; } return TRUE; }