YAZ  5.23.1
Macros | Functions
daemon.h File Reference

Unix daemon management. More...

#include <stdio.h>
#include <yaz/yconfig.h>

Go to the source code of this file.

Macros

#define YAZ_DAEMON_FORK   1
 
#define YAZ_DAEMON_DEBUG   2
 
#define YAZ_DAEMON_KEEPALIVE   4
 
#define YAZ_DAEMON_LOG_REOPEN   8
 

Functions

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

Detailed Description

Unix daemon management.

Definition in file daemon.h.

Macro Definition Documentation

#define YAZ_DAEMON_DEBUG   2

Definition at line 42 of file daemon.h.

Referenced by yaz_daemon().

#define YAZ_DAEMON_FORK   1

Definition at line 41 of file daemon.h.

Referenced by statserv_sc_main(), and yaz_daemon().

#define YAZ_DAEMON_KEEPALIVE   4

Definition at line 43 of file daemon.h.

Referenced by yaz_daemon().

#define YAZ_DAEMON_LOG_REOPEN   8

Definition at line 44 of file daemon.h.

Referenced by yaz_daemon().

Function Documentation

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 227 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().

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 218 of file daemon.c.