files.c File Reference

Utilities used for managing files used by monit. More...

Go to the source code of this file.

Functions

void init_files ()
 Initialize the programs file variables. More...

void finalize_files ()
 Remove temporary files. More...

void re_init_files ()
 Reinitialize the programs file variables. More...

void set_file_timestamp ()
 Set the Runtime control file's last modified timestamp. More...

char * find_rcfile ()
 Search the system for the monit control file. More...

int create_pidfile (char *pidfile)
 Create a program's pidfile - Such a file is created when in daemon mode. More...

int is_rcfile_changed ()
 Test the monit control file for changes. More...

time_t file_changedtime (char *file)
 Get a files last modified timestamp. More...

int check_rcfile (char *rcfile)
 Secure check the monitrc file. More...

int isreg_file (char *file)
 Check if the file is a regular file. More...

int exist_file (char *file)


Detailed Description

Utilities used for managing files used by monit.

Author:
Jan-Henrik Haukeland, <hauk@tildeslash.com>
Version:
$Id: files.c,v 1.10 2002/09/13 10:32:40 hauk Exp $

Definition in file files.c.


Function Documentation

int check_rcfile char *    rcfile
 

Secure check the monitrc file.

The run control file must have the same uid as the REAL uid of this process, it must have permissions no greater than 700 and it must not be a symbolic link. We check these conditions here. (Inspired by code from fetchmail)

Parameters:
rcfile  The monitrc file
Returns:
TRUE if the test passed otherwise FALSE

Definition at line 246 of file files.c.

References error(), prog, and STRERROR.

int create_pidfile char *    pidfile
 

Create a program's pidfile - Such a file is created when in daemon mode.

The file is created with mask = PIDMASK (usually 644).

Parameters:
pidfile  The name of the pidfile to create
Returns:
TRUE if the file was created, otherwise FALSE.

Definition at line 175 of file files.c.

References error(), PIDMASK, prog, and STRERROR.

int exist_file char *    file
 

Definition at line 318 of file files.c.

Referenced by find_rcfile(), and get_pid().

time_t file_changedtime char *    file
 

Get a files last modified timestamp.

This function returns the max of either st_mtime or st_ctime. If the file does not exist or is not a regular file FALSE is returned

Parameters:
file  A file to stat
Returns:
last modification time or FALSE if not found or not a regular file

Definition at line 225 of file files.c.

References MAXIMUM.

Referenced by get_process_uptime().

void finalize_files  
 

Remove temporary files.

Definition at line 95 of file files.c.

References myrun::pidfile, and Run.

char* find_rcfile  
 

Search the system for the monit control file.

Try first ~/.monitrc, if that fails try ./monitrc and finally /etc/monitrc. Exit the application if the control file is not found.

Returns:
The location of monits control file (monitrc)

Definition at line 134 of file files.c.

References myrun::myenvironment::cwd, myrun::Env, error(), exist_file(), myrun::myenvironment::home, MONITRC, prog, Run, and xmalloc().

void init_files  
 

Initialize the programs file variables.

Definition at line 70 of file files.c.

References myrun::Env, myrun::myenvironment::home, MYPIDDIR, MYPIDFILE, myrun::pidfile, Run, set_file_timestamp(), and xstrdup().

int is_rcfile_changed  
 

Test the monit control file for changes.

Returns:
TRUE if the Runtime control file was changed, otherwise FALSE

Definition at line 203 of file files.c.

References myrun::controlfile, and Run.

int isreg_file char *    file
 

Check if the file is a regular file.

Parameters:
file  A path to the file to check
Returns:
TRUE if file exist and is a regular file, otherwise FALSE

Definition at line 304 of file files.c.

Referenced by get_md5sum(), and get_pid().

void re_init_files  
 

Reinitialize the programs file variables.

Definition at line 105 of file files.c.

References set_file_timestamp().

void set_file_timestamp  
 

Set the Runtime control file's last modified timestamp.

Definition at line 115 of file files.c.

References myrun::controlfile, and Run.

Referenced by init_files(), and re_init_files().