mirror of
https://github.com/troglobit/libite.git
synced 2026-10-01 05:22:34 +07:00
Update pidfile() documentation and add unit test for __pidfile_name
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -177,8 +177,10 @@ Generic Functions
|
||||
- `pidfile(basename)`
|
||||
|
||||
Create a daemon PID file in `_PATH_VARRUN` using either `basename` or,
|
||||
if `basename` is `NULL`, `__progname`. The file name has the form
|
||||
`/var/run/basename.pid`.
|
||||
if `basename` is `NULL`, `__progname`. The resulting file name is
|
||||
available to the user as a read-only pointer:
|
||||
|
||||
extern char *__pidfile_name;
|
||||
|
||||
Use this function to create a PID file for your daemon when it is
|
||||
ready to receive signals. A client application may poll for the
|
||||
@@ -242,7 +244,9 @@ The following are the popular OpenBSD string functions.
|
||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
||||
|
||||
**Note:** this version of `pidfile()` has been extended to handle it
|
||||
being called multiple times. See previous section for details.
|
||||
being called multiple times, and also to export the path to the PID
|
||||
file `__pidfile_name`, similar to `__progname`. See previous section
|
||||
for details.
|
||||
|
||||
- `strlcpy(dst, src, len)`
|
||||
|
||||
|
||||
+7
-2
@@ -21,6 +21,7 @@
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern char *__pidfile_name;
|
||||
extern char *chomp(char *str);
|
||||
|
||||
/**
|
||||
@@ -126,12 +127,12 @@ int pidfile_signal(const char *pidfile, int signal)
|
||||
extern char *__progname;
|
||||
static char PIDFILE[42];
|
||||
|
||||
static void sigterm_handler(int signo)
|
||||
static void sigterm_handler(int UNUSED(signo))
|
||||
{
|
||||
printf("Exiting ...\n");
|
||||
}
|
||||
|
||||
static void sigalrm_handler(int signo)
|
||||
static void sigalrm_handler(int UNUSED(signo))
|
||||
{
|
||||
printf("Testing pidfile() ...\n");
|
||||
pidfile(NULL);
|
||||
@@ -159,6 +160,10 @@ int main(void)
|
||||
printf("Reading pid file, should be %d ...\n", getpid());
|
||||
printf("=> %d\n", pidfile_read(PIDFILE));
|
||||
|
||||
printf("\nComparing __pidfile_name with our guessed PID filename ...\n");
|
||||
printf("strcmp(\"%s\",\n \"%s\") => %s\n\n", __pidfile_name, PIDFILE,
|
||||
!strcmp(__pidfile_name, PIDFILE) ? "OK" : "FAIL");
|
||||
|
||||
/* Occular verification that calling pidfile() again updates mtime */
|
||||
snprintf(cmd, sizeof(cmd), "ls -l --full-time %s", PIDFILE);
|
||||
system(cmd);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
CFLAGS = -W -Wall -Wextra -Werror
|
||||
OBJS = pidfile.o chomp.o fexist.o
|
||||
ASROOT = 1
|
||||
TARGET = clean $(OBJS) pidfilefn.test
|
||||
|
||||
Reference in New Issue
Block a user