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

utils.c File Reference

#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <signal.h>
#include <getopt.h>
#include <syslog.h>
#include "utils.h"
#include "ahm.h"
#include "watchdog.h"

Functions

void get_command_line_options (int a_argc, char *a_argv[])
int check_file_mode (const char *a_fname)
int check_file_owner (const char *a_fname, uid_t a_uid, gid_t a_gid)
int check_file_owner_mode (const char *a_fname, uid_t a_uid, gid_t a_gid)
void key_destroy_func (gpointer a_data)
void value_destroy_func (gpointer a_data)
int open_fifo (registration_info **a_reginfo)
int file_exists (const char *a_filename)
int read_registration_file (const char *a_filename, registration_info **a_reginfo)
void log_message (int a_event, int a_severity, unsigned int a_flags, const char *a_format,...)
void display_registration_info (const registration_info *a_reginfo)

Function Documentation

int check_file_mode const char *    a_fname
 

Checks the file to see if its mode is 0600.

Parameters:
a_fname  The full path and name of file to check
Returns:
Non-zero on failure; zero on success E_MODE_INVALID E_FILE_NOT_FOUND

int check_file_owner const char *    a_fname,
uid_t    a_uid,
gid_t    a_gid
 

Determines if the file provided, is owned by the uid and of the gid provided.

Parameters:
a_fname  The file to investigate
a_uid  The uid to check on the file
a_gid  The gid to check on the file
Returns:
E_UID_INVALID if the uid is not correct E_GID_INVALID if the gid is not correct E_FILE_NOT_FOUND if the stat() fails SUCCESS if the uid and gid are equal to a_uid and a_gid

int check_file_owner_mode const char *    a_fname,
uid_t    a_uid,
gid_t    a_gid
 

Checks the file to see if its mode is 0600 and has the uid and gid as indicated.

Parameters:
a_fname  The full path and name of file to check
a_uid  The uid that the file should have
a_gid  The gid that the file should have
Returns:
Non-zero on failure; zero on success E_UID_INVALID E_GID_INVALID E_MODE_INVALID

void display_registration_info const registration_info   a_reginfo
 

This is a debugging function to display the contents of the registration structure.

int file_exists const char *    a_filename
 

Checks if a file exists.

Parameters:
a_filename 
Returns:
non-zero if exists; zero if does not exist (stat fails)

void get_command_line_options int    a_argc,
char *    a_argv[]
 

This function parses the command line for specific options. The available options are:

--non-daemon: allows the running the application monitor as an application with standard out directed to the terminal --enable-watchdog: enables opening the watchdog device and updating it. --watchdog-period[=value]: Sets the period between reseting the watchdog timer (in seconds). This is not useful unless used with --enable-watchdog. --register-period[=value]: Sets the period to check for registrations (in milliseconds) --registration-dir[=value]: Indicates where it should look for registrations

Changing the registration directory and/or the registration period in the daemon will not cause the library code to be updated. Any clients must be separately configured to use the new registration directory and period, independent of the library. However, the library is not required by a client application. The client may opt to register without using the client library.

void key_destroy_func gpointer    a_data
 

Frees memory allocated for a hash key.

Parameters:
a_data  The key data to free

void log_message int    a_event,
int    a_severity,
unsigned int    a_flags,
const char *    a_format,
...   
 

Logs a message to either the POSIX event log or syslog depending if POSIX_EVENT_LOGGING is defined. The only parameters used for logging using syslog are the a_severity and a_format (and its args).

Parameters:
a_event  The event as described for POSIX
a_serverity  This is the serverity (0-7) as defined by syslog and POSIX event logging. At the time of this writing, these values had identical meaing between the two.
a_flags  The flags as described for POSIX
a_format  The format string
...  The data associated with the format specifiers in a_format

int open_fifo registration_info **    a_reginfo
 

Opens the heartbeat fifo and sets the value of the m_hbfd variable in the registration structure to that of the fifo's open file descriptor.

Parameters:
a_reginfo  The registration structure for the process
Returns:
E_INVALID if unable to open the fifo SUCCESS if no error

int read_registration_file const char *    a_filename,
registration_info **    a_reginfo
 

Opens the registration file and reads in its contents. The caller must provide a pointer whose memory is already allocated.

If an application happens to be creating the registration file when the daemon is attempting to read it, it will most likely be treated by the daemon as an invalid file. However, it will be picked up by the next registration check.

The following are messages that are logged for various registration file issues (where xxxx is a process identifier):

"permissions on registration file are invalid for PID xxxxx" "script does not exist for PID xxxxx" "fifo does not exist for PID xxxxx"

Parameters:
a_filename  The name of the registration file
a_reginfo  The return location for the registration information
Returns:
EINVAL if the file cannot be opened,permissions are bad or content invalid. ENOMEM if unable allocate sufficient memory for the registration structure.

void value_destroy_func gpointer    a_data
 

Frees memory allocated for a hash value.

Parameters:
a_data  The hash value to free


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