#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
- Author
- Joachim Wiberg
- Date
- 2009-2021
- Copyright
- ISC License
◆ chomp()
char* chomp |
( |
char * |
str | ) |
|
Perl like chomp function, chop off last char(s) if newline.
- Parameters
-
This function is like Perl chomp, but it's set to chop of all trailing newlines. Useful in combination with fgets().
- Returns
- str, or
NULL
with errno set, if str is not a valid pointer.
- Exceptions
-
EINVAL | if the input argument is not a valid pointer. |
◆ pidfile_poll()
pid_t pidfile_poll |
( |
const char * |
pidfile | ) |
|
Poll for the existence of a pidfile and return PID.
- Parameters
-
pidfile | Path to pidfile to poll for |
This function polls for the pidfile at pidfile
for at most 5 seconds before timing out. If the file is created within that time span the file is read and its PID contents returned.
- Returns
- The PID read from
pidfile
, or zero on timeout.
◆ pidfile_read()
pid_t pidfile_read |
( |
const char * |
pidfile | ) |
|
Reads a PID value from a pidfile.
- Parameters
-
pidfile | File containing PID, usually in /var/run/PROCNAME .pid |
This function takes a pidfile
and returns the PID found therein.
- Returns
- On invalid
pidfile
, -1 with errno set. If the pidfile
is empty, or when its contents cannot be translated, this function returns zero (0), on success this function returns a PID value greater than one.
- Note
- PID 1 is reserved for the system init process.
- Exceptions
-
EINVAL | on invalid pidfile , or |
ENOENT | when pidfile does not exist. |
◆ pidfile_signal()
int pidfile_signal |
( |
const char * |
pidfile, |
|
|
int |
signal |
|
) |
| |
Send signal to a PID and cleanup pidfile afterwards.
- Parameters
-
pidfile | File containing PID, usually in /var/run/PROCNAME .pid |
signal | Signal to send to PID found in pidfile . |
If signal
is any of SIGTERM
or SIGKILL
, or if kill(2) returns -1, the pidfile
is removed.
- Returns
- POSIX OK(0) on success, non-zero otherwise.