1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include "natfork.ih"
//f: NatFork::childProcess()
//c: DevicesProducer::DevicesProducer(std::ostream&, Storage&)
//c: TcpdumpProducer::TcpdumpProducer(std::ostream&, Storage&)
//c: ConntrackProducer::ConntrackProducer(std::ostream&, Storage&)
void NatFork::childProcess()
{
ShowSeconds::setFormat();
Storage storage;
// Constructing of the producers may fail. At that point messages can
// still be written to cout since we're busy starting the daemon.
// Once the producers have been constructed, messages to cout are
// suppressed by prepareDaemon below
unique_ptr<Producer> producer {
(*s_producer[d_mode]) (d_stdMsg, storage)
};
ConnectionsConsumer connections{ d_stdMsg, storage };
d_stdMsg << "processing: " << d_options.protocolNames() << endl;
if (d_options.daemon())
{
prepareDaemon();
// signals sent by Options::rotate[Data]
// handled by NatFork::signalHandler
Signal::instance().add(SIGHUP, *this); // for --rotate
Signal::instance().add(SIGALRM, *this); // for --rotate-data
}
RotatingStreambuf::startThread();
thread producerThread{ Producer::process, producer.get(), ref(storage) };
connections.run();
producerThread.join();
d_stdMsg << "NatFork::childProcess notifying RotatingStreambuf" << endl;
RotatingStreambuf::notify(); // ends the log-rotating threads.
d_stdMsg << "NatFork::childProcess ends" << endl;
}
|