Daemonize the program.
More...
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include "defaults.h"
#include "log.h"
static void check_pidfile |
( |
const char * |
pidfile | ) |
|
|
static |
Exit if the process referenced by pidfile
is running.
- Parameters
-
static char * getpwd |
( |
void |
| ) |
|
|
static |
Get the current working directory.
- Returns
- Absolute path to the current working directory if successful, or
NULL
if unsuccessful
- Note
- Like
get_current_dir_name(3)
-
If successful, caller is responsible for
free(3)
ing the result
- See also
get_current_dir_name(3)
static pid_t write_pidfile |
( |
const char * |
pidfile, |
|
|
pid_t |
pid |
|
) |
| |
|
static |
Write a PID file.
Attempts to do so "atomically" as per daemon(7)
. Does not write PID file if the file referenced by pidfile
already exists, or the process ID referenced by the file is in use by a running process.
- Parameters
-
pidfile | Path to PID file |
pid | A PID |
- Returns
- The PID actually written to the PID file
- Note
- Result should be equal to
-
Exits if unsuccessful
void daemonize |
( |
const char * |
pidfile | ) |
|
Daemonize the program.
Attempts to do so in the manner described in daemon(7)
- forks twice, with the parent writing the PID of the second child to a PID file before exiting. The daemon child also adds $PWD to its environment, in case any scripts it executes require it.
- Parameters
-
- Note
- Exits if unsuccessful