YAZ  5.34.0
Functions
daemon.c File Reference

Unix daemon management. More...

#include <yaz/yconfig.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <yaz/daemon.h>
#include <yaz/log.h>
#include <yaz/snprintf.h>

Go to the source code of this file.

Functions

void yaz_daemon_stop (void)
 stop daemon - stop parent process More...
 
int yaz_daemon (const char *progname, unsigned int flags, void(*work)(void *data), void *data, const char *pidfile, const char *uid)
 daemon utility. More...
 

Detailed Description

Unix daemon management.

Definition in file daemon.c.

Function Documentation

◆ yaz_daemon()

int yaz_daemon ( const char *  progname,
unsigned int  flags,
void(*)(void *data)  work,
void *  data,
const char *  pidfile,
const char *  uid 
)

daemon utility.

Parameters
prognameprogram name for logging purposes.
flagsflags which is a bit-wise combination of YAZ_DAEMON_..
workworking handler (which may be running in different process)
dataopaque data to be passed to work handler
pidfilefilename with Process-ID (NULL for no file)
uideffective user ID for handler (NULL for no same as caller)
Returns
0 for success, non-zero for failure.

This function puts calls work handler which is supposed to carry out a daemon service with a possible changed User ID and in a child process.

Flag YAZ_DAEMON_FORK: Puts the service in the background on Unix.

Flag YAZ_DAEMON_DEBUG: Puts the service in debug mode (no fork at all).

Flag YAZ_DAEMON_KEEPALIVE: Repeatedly calls work handler if it makes a "fatal" error.

Flag YAZ_DAEMON_LOG_REOPEN: Re-opens yaz log if SIGHUP is received

Definition at line 229 of file daemon.c.

References YAZ_DAEMON_DEBUG, YAZ_DAEMON_FORK, YAZ_DAEMON_KEEPALIVE, YAZ_DAEMON_LOG_REOPEN, yaz_log(), yaz_log_file(), YLOG_ERRNO, YLOG_FATAL, and YLOG_WARN.

Referenced by statserv_sc_main().

◆ yaz_daemon_stop()

void yaz_daemon_stop ( void  )

stop daemon - stop parent process

This function sends a signal to the parent keepalive process that makes it exit immediately - without waiting. If there's no parent keepalive process, this function does nothing. SHould be called when the child process has freed resources, such as listening socket. But the child process may continue running.

Definition at line 220 of file daemon.c.