-void start_daemon(void)
-{
- if(fork())
- exit(0);
-
- chdir("/");
- umask(0);
- (void) close(0);
- (void) close(1);
- (void) close(2);
- (void) open("/", O_RDONLY);
- (void) dup2(0, 1);
- (void) dup2(0, 2);
- setsid();
-}
-
-static void logopen(void)
-{
-#if HAVE_OPENLOG
- if(isDaemon)
- openlog("icmpmonitor", LOG_PID| LOG_CONS|LOG_NOWAIT, LOG_USER);
-#else
- log(LOG_WARNING,"Compiled without syslog. Syslog can't be used.");
-#endif
-}
-
-static void logclose(void)
-{
-#if HAVE_CLOSELOG
- if(isDaemon)
- closelog();
-#endif
-}
-
-/**
- * This function should be used as central logging facility.
- * 'type' argument should be one of following:
- *
- * LOG_EMERG system is unusable
- * LOG_ALERT action must be taken immediately
- * LOG_CRIT critical conditions
- * LOG_ERR error conditions
- * LOG_WARNING warning conditions
- * LOG_NOTICE normal but significant condition
- * LOG_INFO informational
- * LOG_DEBUG debug-level messages
- */
-static void log(int type, char *format, ...)
-{
- va_list ap;
-
-#ifndef DEBUG
- if(type==LOG_DEBUG)
- return;
-#endif
-
- va_start(ap, format);
-
- if(isDaemon)
- {
- char buffer[MAX_LOG_MSG_SIZE];
-
-#if HAVE_VSNPRINTF
- (void)vsnprintf(buffer, MAX_LOG_MSG_SIZE, format, ap);
-#else
-# if HAVE_VSPRINTF
-# warning "Using VSPRINTF. Buffer overflow could happen!"
- (void)vsprintf(buffer, format, ap);
-# else
-# error "Your standard libabry have neither vsnprintf nor vsprintf defined. One of them is reqired!"
-# endif
-#endif
-#if HAVE_SYSLOG
- syslog(type,buffer);
-#endif
- } else
- {
- (void) fprintf(stderr, "icmpmonitor[%d]:", (int)getpid());
- (void) vfprintf(stderr, format, ap);
- (void) fprintf(stderr, "\n");
- }
- va_end(ap);
-}
-