Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

ahm.h File Reference

#include <sys/types.h>
#include <unistd.h>
#include <glib.h>

Go to the source code of this file.

Compounds

struct  pingdata
struct  reginfo
struct  regkey

Defines

#define REGISTRATION_DIRECTORY   "/var/appmonitord"
#define REGISTRATION_INTERVAL   3000
#define NAME_LENGTH   256
#define STRING_LENGTH   256
#define MILLISECONDS_TO_MICROSECONDS   1000
#define ASCII_ZERO   48
#define ASCII_NINE   57
#define ENOTFOUND   1
#define E_UID_INVALID   2
#define E_GID_INVALID   3
#define E_MODE_INVALID   4
#define E_FILE_NOT_FOUND   5
#define E_INVALID   6
#define E_FAULT   7
#define SUCCESS   0

Typedefs

typedef reginfo registration_info
typedef regkey registration_key
typedef pingdata ping_data

Functions

void signal_shutdown (int a_arg)
pid_t extract_pid (const char *d_name)
int start_daemon (int a_ignoreSIGCLD)
void sig_child ()
int validate_process (pid_t a_pid)
gboolean find_registration_files (gpointer a_data)
int verify_heartbeat_fifo (const char *a_fifoname, const registration_info *a_reginfo)
void recover_process (registration_key *a_regkey, registration_info *a_reginfo)

Variables

int errno
GHashTable * prochash
GMainLoop * mainloop
gboolean daemon_mode
char registration_dir [NAME_LENGTH]
unsigned long register_period


Define Documentation

#define ASCII_NINE   57
 

#define ASCII_ZERO   48
 

#define E_FAULT   7
 

#define E_FILE_NOT_FOUND   5
 

#define E_GID_INVALID   3
 

#define E_INVALID   6
 

#define E_MODE_INVALID   4
 

#define E_UID_INVALID   2
 

#define ENOTFOUND   1
 

#define MILLISECONDS_TO_MICROSECONDS   1000
 

#define NAME_LENGTH   256
 

#define REGISTRATION_DIRECTORY   "/var/appmonitord"
 

#define REGISTRATION_INTERVAL   3000
 

#define STRING_LENGTH   256
 

#define SUCCESS   0
 


Typedef Documentation

typedef struct pingdata ping_data
 

This is the structure that contains the fifo data to be passed in a heartbeat.

typedef struct reginfo registration_info
 

Each application may register using a registration file and writing its registration information in that file. The application may provide an application identifier that is unique to the application's actual process id (which is unique on the system). This allows a single process to register more than one heartbeat.

This structure is used as the "value" for the hash table.

typedef struct regkey registration_key
 

This structure is used as the "key" in the hash table


Function Documentation

pid_t extract_pid const char *    d_name
 

Extracts the PID from a potentially qualified filename of the format .phm_<PID>_XXXXXX.

Parameters:
d_name  The filename from which to extract the PID
Returns:
The pid obtained, or -1 on error.

gboolean find_registration_files gpointer    a_data
 

This function looks under the specified registration directory for potential registration files. For every file found, extract_pid() is called to attempt to parse out the PID. The PID is checked to see if it is already in the hash table. If it is, then there is a duplicate registration file and one of them needs to be removed (and a log generated and possibly a recovery executed). If there is no PID already in the hash table (i.e. nothing already used that PID), then the registration file is opened and its contents parsed out and used to fill the registration_info structure. With this information, the process is then authenticated using /proc/<pid> information and compared against what was in the registration file. If all turns up ok, then the PID and registration_info are added to the hash table.

If a process was in the process of writing the registration file while it is being parsed, then it will be invalid and the registration will be picked up the next time this function is called. However, if the second time this function attempts to read the registration file and it still contains errors, it will be renamed (having "invalid" pre-pended to the name) and a log entry generated. It is up to the application owner or the system administrator to remove these files. They are not immediately deleted and are renamed instead, so that the application (or anyone else interested) may inspect the file to see what the problem may be.

If there are not files that fit the registration filename format, then this function returns without doing anything.

The following is a list of the log messages generated by this function (xxxx denotes a process identifier):

"malloc failed during registration key creation for PID xxxx" "malloc failed during registration of PID xxxx" "registration file invalid for PID xxxx" "unable to open client fifo for PID xxxx" "failed to create thread for PID xxxx" "registration completed for PID xxxx" "process xxxx not authenticated or does not exist" "renaming invalid registration file for PID xxxx"

Parameters:
a_data  (un-used)
Returns:
TRUE if we should continue to call this function; FALSE if the callback should be removed

Todo:
handle duplicate registrations

void recover_process registration_key   a_regkey,
registration_info   a_reginfo
 

void sig_child  
 

This is a signal handler that will wait for child processes to terminate and thus avoiding zombies. This function was adapted from the Richard Stevens book on Unix Network Programming.

It should be noted that the calling process may get an interrupted system call upon return from this function and it should be handled appropriatly.

void signal_shutdown int    a_arg
 

This method keeps the monitor from being killed and leaving various pipes and memory allocated when used to shutdown the heartbeat monitor.

Parameters:
a_arg  (unused)

int start_daemon int    a_ignoreSIGCLD
 

This function is called when the App. Heartbeat Monitor should execute as a daemon. This code was adapted from the Richard Stevens book on Unix Network Programming.

Returns:
zero on success; non-zero on error

int validate_process pid_t    a_pid
 

int verify_heartbeat_fifo const char *    a_fifoname,
const registration_info   a_reginfo
 

Determine if the file is a fifo and if it is opened for writing by the process specified. The fifo must not be opened by anything other than the process wishing to be monitored and the heartbeat service that will be listening for heartbeats.

Parameters:
a_fifoname  The name of the fifo to be verified
a_reginfo  The information regarding the process that should own the fifo.
Returns:
SUCCESS (0) on success or E_INVALID (non-zero) on failure E_UID_INVALID if the uid is not that of the process registering E_GID_INVALID if the gid is not that of the process registering E_FILE_NOT_FOUND if the file could not be verified.


Variable Documentation

gboolean daemon_mode
 

Indicates if the monitor should be run as a daemon or not. This intent of this is to help with debugging

int errno
 

GMainLoop* mainloop
 

This is the main event loop for the application

GHashTable* prochash
 

This is the hash table containing the registered processes

unsigned long register_period
 

This is the approximate amount of time to allow to lapse between checking for new registrations

char registration_dir[NAME_LENGTH]
 

This is the location where applications should register


Generated on Wed Oct 30 15:21:17 2002 for Application Heartbeat Monitor by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002