mirror of
https://github.com/troglobit/libite.git
synced 2026-11-12 16:51:16 +00:00
Update pidfile() documentation and add unit test for __pidfile_name
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
253460b4b8
commit
5d07594709
3 files changed
+15
-5
No files matched your search
@@ -177,8 +177,10 @@ Generic Functions
|
|||||||
- `pidfile(basename)`
|
- `pidfile(basename)`
|
||||||
|
|
||||||
Create a daemon PID file in `_PATH_VARRUN` using either `basename` or,
|
Create a daemon PID file in `_PATH_VARRUN` using either `basename` or,
|
||||||
if `basename` is `NULL`, `__progname`. The file name has the form
|
if `basename` is `NULL`, `__progname`. The resulting file name is
|
||||||
`/var/run/basename.pid`.
|
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
|
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
|
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
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
||||||
|
|
||||||
**Note:** this version of `pidfile()` has been extended to handle it
|
**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)`
|
- `strlcpy(dst, src, len)`
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -21,6 +21,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
extern char *__pidfile_name;
|
||||||
extern char *chomp(char *str);
|
extern char *chomp(char *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,12 +127,12 @@ int pidfile_signal(const char *pidfile, int signal)
|
|||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
static char PIDFILE[42];
|
static char PIDFILE[42];
|
||||||
|
|
||||||
static void sigterm_handler(int signo)
|
static void sigterm_handler(int UNUSED(signo))
|
||||||
{
|
{
|
||||||
printf("Exiting ...\n");
|
printf("Exiting ...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigalrm_handler(int signo)
|
static void sigalrm_handler(int UNUSED(signo))
|
||||||
{
|
{
|
||||||
printf("Testing pidfile() ...\n");
|
printf("Testing pidfile() ...\n");
|
||||||
pidfile(NULL);
|
pidfile(NULL);
|
||||||
@@ -159,6 +160,10 @@ int main(void)
|
|||||||
printf("Reading pid file, should be %d ...\n", getpid());
|
printf("Reading pid file, should be %d ...\n", getpid());
|
||||||
printf("=> %d\n", pidfile_read(PIDFILE));
|
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 */
|
/* Occular verification that calling pidfile() again updates mtime */
|
||||||
snprintf(cmd, sizeof(cmd), "ls -l --full-time %s", PIDFILE);
|
snprintf(cmd, sizeof(cmd), "ls -l --full-time %s", PIDFILE);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
CFLAGS = -W -Wall -Wextra -Werror
|
||||||
OBJS = pidfile.o chomp.o fexist.o
|
OBJS = pidfile.o chomp.o fexist.o
|
||||||
ASROOT = 1
|
ASROOT = 1
|
||||||
TARGET = clean $(OBJS) pidfilefn.test
|
TARGET = clean $(OBJS) pidfilefn.test
|
||||||
|
|||||||
Reference in new issue
Block a user