pid_lock.h File Reference

PID file management APIs. More...


Defines

#define MAX_PID_SIZE   10
 Maximum number of digits in a PID string, including the NULL-terminator character.

Functions

int pid_lock (const char *filename)
 Checks to see if the PID file is locked, and if it is, pull the PID out of the file and check if the process is running.
int pid_update (int fd)
 Update the PID file with our current process ID.
static char * pid_gen_filename (const char *dname, const char *prov_prefix, char *buf, size_t sz)
 Generates a PID file given a daemon name.
int pid_is_locked (const char *filename)
 Tests whether a PID file exists, and is locked.
int pid_get_process (const char *pidfile_path)
 See if the PID file is locked, and if it is, pull the PID out of the file and check if the process is running.

Variables

int pid_lkquiet
 Silences pid lock failure messages.


Detailed Description

PID file management APIs.

pid_lock() Open lock, and write a PID file all in one fell swoop.

It's useful to first open and lock the PID file. If it fails, you can exit cleanly with an error message on the console. If it succeeds, you might daemonize() and then have a new PID that you want to write into the file.

There is no pid_close(), you never close your PID file, it gets closed on exit, and the lock gets broken then.

All routines return < 0 on failure.


Function Documentation

static char* pid_gen_filename const char *  dname,
const char *  prov_prefix,
char *  buf,
size_t  sz
[inline, static]
 

Generates a PID file given a daemon name.

Parameters:
[in] dname Name of daemon used to generate the PID file
[in] is_internal Non-zero for Juniper-developed application, 0 otherwise
[out] buf Buffer to place the generated string
[in] sz Size of output buffer
Returns:
A pointer to the buffer.

int pid_get_process const char *  pidfile_path  ) 
 

See if the PID file is locked, and if it is, pull the PID out of the file and check if the process is running.

Parameters:
[in] pidfile_path Name of the pid file
Returns:
< 0 if we encounter an error and sets errno; Otherwise returns the running process PID. errno will be set to ESRCH if the process is not running.

int pid_is_locked const char *  filename  ) 
 

Tests whether a PID file exists, and is locked.

Unlike pid_lock(), this function doesn't create the file if it doesn't exist.

Parameters:
[in] filename Name of the PID file
Returns:
TRUE if filename is locked; FALSE if filename doesn't exist, or isn't locked.

int pid_lock const char *  filename  ) 
 

Checks to see if the PID file is locked, and if it is, pull the PID out of the file and check if the process is running.

Parameters:
[in] filename The name of the PID file
Returns:
< 0 if we encounter an error and sets errno; Otherwise returns the running process PID. errno will be ESRCH if the process is not running.

int pid_update int  fd  ) 
 

Update the PID file with our current process ID.

Parameters:
[in] fd File descriptor for the PID file
Returns:
0 on success; otherwise < 0 if an error is encountered.


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:23:40 2010 for libjuniper by Doxygen 1.4.5