peapod  0.1.0
EAPOL Proxy Daemon
Functions | Variables
daemonize.c File Reference

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"
Include dependency graph for daemonize.c:

Functions

static void check_pidfile (const char *pidfile)
 Exit if the process referenced by pidfile is running. More...
 
static char * getpwd (void)
 Get the current working directory. More...
 
static pid_t write_pidfile (const char *pidfile, pid_t pid)
 Write a PID file. More...
 
void daemonize (const char *pidfile)
 Daemonize the program. More...
 

Variables

char ** environ
 

Detailed Description

Daemonize the program.

Function Documentation

static void check_pidfile ( const char *  pidfile)
static

Exit if the process referenced by pidfile is running.

Parameters
pidfilePath to PID file
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
pidfilePath to PID file
pidA 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
pidfilePath to PID file
Note
Exits if unsuccessful

Variable Documentation

char** environ