I'm going to strongly suggest we reject this change at the current stage. We have a lot of testing under our belts on the current arrangement and it works fine in all environments EXCEPT FreeBSD, which is known to be flakey re threads anyway.
If you will maintain this as a FreeBSD - only patch, we can revisit it after 3.0... Frankly I'd be more comfortable moving daemonize earlier, before the pcap_open_live - one of the post-3.0 things I'm looking at is a threads watchdog, which would be cleaner that way... Meanwhile, you should probably append this info the existing bug report on FreeBSD (http://www.freebsd.org/cgi/query-pr.cgi?pr=56339). And also to the tcpdump workers list. However, I'll bet you ultimately get the 'fork() and threads don't co-exist' answer. Also, look at PR 51535 which is the other open problem in this area. Thanks! And cool findings. -----Burton > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of Meloun Michal > Sent: Tuesday, February 03, 2004 8:04 AM > To: [EMAIL PROTECTED] > Subject: [Ntop-dev] [PATCH] FreeBSD hangs in daemon mode > > > Hi all, > I found (at least I hope) ?regular? solution for mysterious > FreeBSD hangs, > when ntop running in daemon mode. The core of problem lives in > fork() and > pcap_ initialization sequence. I?m not sure if its feature or > bug in FreeBSD > kernel, but looks like fork() corrupt pcap interface > functionality. Simply, > pcap_open_live() and pcap_dispatch() must be called from one > process context. > The sequence of pcap_open_live() , fork() and pcap_dispatch() > not works, but > fork(), pcap_open_live() and pcap_dispatch() works without problems. > > Yes, the pcap_open_live() is the root of this problem ? if > fork() is called > before pcap_open_live() then all works, if its called after, then not. > > > The attached patch is tested on FreeBSD 4.9 and FreeBSD 5.2 ? > works for all > combinations of ?K ?d switches without problem (and without --set-pcap- > nonblocking). > > Michal Meloun > > --- ntop.c.orig Tue Feb 3 11:16:38 2004 > +++ ntop.c Tue Feb 3 11:36:03 2004 > @@ -169,8 +169,7 @@ > childpid ? "parent" : "child", childpid); > #endif > if(!childpid) { /* child */ > - traceEvent(CONST_TRACE_INFO, "INIT: Bye bye: I'm becoming > a daemon..."); > - detachFromTerminal(1); > + traceEvent(CONST_TRACE_INFO, "INIT: daemonize..."); > } else { /* father */ > traceEvent(CONST_TRACE_INFO, "INIT: Parent process is > exiting (this is normal)"); > exit(0); > @@ -185,6 +184,9 @@ > alarm(120); /* Don't freeze */ > #endif > > + /* Last message on terminal, before switching to syslog */ > + traceEvent(CONST_TRACE_INFO, "INIT: Bye bye: I'm becoming a > daemon..."); > + > #if !defined(WIN32) && defined(MAKE_WITH_SYSLOG) > /* Child processes must log to syslog. > * If no facility was set through -L | --use-syslog=facility > @@ -195,22 +197,24 @@ > #endif > > if(doChdir) chdir("/"); > - setsid(); /* detach from the terminal */ > - > + > fclose(stdin); > fclose(stdout); > /* fclose(stderr); */ > > + setsid(); /* detach from the terminal */ > + > /* > * clear any inherited file mode creation mask > */ > umask (0); > > /* > - * Use linebuffered stdout > + * Use linebuffered stdout > */ > /* setlinebuf (stdout); */ > - setvbuf(stdout, (char *)NULL, _IOLBF, 0); > + /* stdout is closed already */ > + /* setvbuf(stdout, (char *)NULL, _IOLBF, 0); */ > > } > #endif /* WIN32 */ > > > > > --- globals-core.c.orig Tue Feb 3 11:17:14 2004 > +++ globals-core.c Tue Feb 3 11:32:10 2004 > @@ -534,6 +534,15 @@ > void initNtop(char *devices) { > char value[32]; > > +#ifndef WIN32 > + if(myGlobals.daemonMode) { > + /* deamonize as far as possible, so rest of initialization runs > + in daemon process context*/ > + daemonize(); > + traceEvent(CONST_TRACE_ALWAYSDISPLAY, "Now running as a daemon"); > + } > +#endif > + > initIPServices(); > > handleProtocols(); > @@ -552,11 +561,9 @@ > /* ********************************** */ > > initGdbm(myGlobals.dbPath, myGlobals.spoolPath, 0); > - > #ifndef WIN32 > if(myGlobals.daemonMode) { > - daemonize(); > - traceEvent(CONST_TRACE_ALWAYSDISPLAY, "Now running as a daemon"); > + detachFromTerminal(1); > } > #endif > > > _______________________________________________ > Ntop-dev mailing list > [EMAIL PROTECTED] > http://listgateway.unipi.it/mailman/listinfo/ntop-dev > _______________________________________________ Ntop-dev mailing list [EMAIL PROTECTED] http://listgateway.unipi.it/mailman/listinfo/ntop-dev
