FreeBSD/contrib/openbsm/bin/auditd/auditd.c
/*
 * Register the daemon with the signal handler and the auditd pid file.
 */
Register the daemon with the signal handler and the auditd pid file.
Register the daemon with the signal handler and the auditd pid file .
static int
register_daemon(void)
{
	FILE * pidfile;
	int fd;
	pid_t pid;
	if (signal(SIGTERM, auditd_relay_signal) == SIG_ERR) {
		auditd_log_err(
		    "Could not set signal handler for SIGTERM");
		fail_exit();
	}
	if (signal(SIGCHLD, auditd_relay_signal) == SIG_ERR) {
		auditd_log_err(
		    "Could not set signal handler for SIGCHLD");
		fail_exit();
	}
	if (signal(SIGHUP, auditd_relay_signal) == SIG_ERR) {
		auditd_log_err(
		    "Could not set signal handler for SIGHUP");
		fail_exit();
	}
	if (signal(SIGALRM, auditd_relay_signal) == SIG_ERR) {
		auditd_log_err(
		    "Could not set signal handler for SIGALRM");
		fail_exit();
	}
	if ((pidfile = fopen(AUDITD_PIDFILE, "a")) == NULL) {
		auditd_log_err("Could not open PID file");
		audit_warn_tmpfile();
		return (-1);
	}
	fd = fileno(pidfile);
	if (flock(fd, LOCK_EX | LOCK_NB) < 0) {
		auditd_log_err(
		    "PID file is locked (is another auditd running?).");
		audit_warn_ebusy();
		return (-1);
	}
	pid = getpid();
	ftruncate(fd, 0);
	if (fprintf(pidfile, "%u\n", pid) < 0) {
		fail_exit();
	}
	fflush(pidfile);
	return (0);
}
static int register_daemon ( void ) { FILE * pidfile ; int fd ; pid_t pid ; if ( signal ( SIGTERM , auditd_relay_signal ) == SIG_ERR ) { auditd_log_err ( " " ) ; fail_exit ( ) ; } if ( signal ( SIGCHLD , auditd_relay_signal ) == SIG_ERR ) { auditd_log_err ( " " ) ; fail_exit ( ) ; } if ( signal ( SIGHUP , auditd_relay_signal ) == SIG_ERR ) { auditd_log_err ( " " ) ; fail_exit ( ) ; } if ( signal ( SIGALRM , auditd_relay_signal ) == SIG_ERR ) { auditd_log_err ( " " ) ; fail_exit ( ) ; } if ( ( pidfile = fopen ( AUDITD_PIDFILE , " " ) ) == NULL ) { auditd_log_err ( " " ) ; audit_warn_tmpfile ( ) ; return ( -1 ) ; } fd = fileno ( pidfile ) ; if ( flock ( fd , LOCK_EX | LOCK_NB ) < 0 ) { auditd_log_err ( " " ) ; audit_warn_ebusy ( ) ; return ( -1 ) ; } pid = getpid ( ) ; ftruncate ( fd , 0 ) ; if ( fprintf ( pidfile , " \n " , pid ) < 0 ) { fail_exit ( ) ; } fflush ( pidfile ) ; return ( 0 ) ; }
Register the daemon with the signal handler and the auditd pid file.
Register the daemon with the signal handler and the auditd pid file .
/* Set up the signal hander. */ /* Attempt to lock the pid file; if a lock is present, exit. */ /* Should not start the daemon. */