Go to the source code of this file.
Data Structures | |
struct | mychecksum |
Defines a checksum object. More... | |
struct | mycommand |
Defines a command with ARGMAX optional arguments. More... | |
struct | mymail |
Defines a mailinglist object. More... | |
struct | myport |
Defines a port object. More... | |
struct | myprotocol |
struct | myprocess |
Defines process data. More... | |
struct | myprocinfo |
Defines procfs (or other mechanism) data. More... | |
struct | myresource |
Defines resource data. More... | |
struct | myformat |
User selected standard mail format. More... | |
struct | myautentication |
An object holding Basic Authentication information. More... | |
struct | myenvironment |
An object holding program relevant "environment" data, see; env.c. More... | |
struct | myrun |
Defines data for application runtime. More... | |
Defines | |
#define | VERSION PACKAGE_VERSION |
#define | MONITRC "monitrc" |
#define | TIMEFORMAT "%Z %b %e %T" |
#define | STRERROR strerror(errno) |
#define | STRLEN 256 |
#define | ARGMAX 64 |
#define | LOGMASK 0112 |
#define | PIDMASK 0122 |
#define | MYPIDDIR PIDDIR |
#define | MYPIDFILE "monit.pid" |
#define | LOCALHOST "localhost" |
#define | SMTP_PORT 25 |
#define | SMTP_TIMEOUT 30 |
#define | CHECK_TIMEOUT 30 |
#define | START_HTTP 1 |
#define | STOP_HTTP 2 |
#define | TRUE 1 |
#define | FALSE 0 |
#define | MAXIMUM(x, y) ((x) > (y) ? (x) : (y)) |
#define | is(a, b) ((a&&b)?!strcasecmp(a, b):0) |
#define | LOCK(mutex) |
------------------------------------------------- Synchronization macros. More... | |
#define | END_LOCK pthread_mutex_unlock(_yymutex); } while (0) |
#define | NEW(p) (xcalloc(1, (long)sizeof *(p))) |
----------------------------------------------- Object Constructor macro. More... | |
Typedefs | |
typedef void | Sigfunc (int) |
Replace the standard signal function with a more reliable using sigaction. More... | |
typedef myport * | Port_T |
Defines a port object. More... | |
typedef myprotocol * | Protocol_T |
Defines a protocol object with protocol functions. More... | |
typedef mychecksum * | Checksum_T |
Defines a checksum object. More... | |
typedef mymail * | Mail_T |
Defines a mailinglist object. More... | |
typedef myresource * | Resource_T |
Defines resource data. More... | |
typedef myprocinfo * | ProcInfo_T |
Defines procfs (or other mechanism) data. More... | |
typedef mycommand * | Command_T |
Defines a command with ARGMAX optional arguments. More... | |
typedef myprocess * | Process_T |
Defines process data. More... | |
Functions | |
Sigfunc * | signal (int signo, Sigfunc *func) |
Replace the standard signal() function, with a more reliable using sigaction. More... | |
void | error (const char *,...) |
Print a formated message to stderr or to the logfile if no tty exist. More... | |
char * | trim (char *) |
Remove leading and trailing space from the string. More... | |
char * | ltrim (char *) |
Remove leading white space [ \t\r ] from the string. More... | |
char * | rtrim (char *) |
Remove trailing white space [ \t\r ] from the string. More... | |
char * | trim_quotes (char *) |
Remove any enclosing quotes ["'] from the string. More... | |
int | starts_with (char *, char *) |
Return TRUE if the string a starts with the string b. More... | |
void | handle_string_escapes (char *) |
Exchanges \escape sequences in a string. More... | |
void | chomp (char *) |
Removes everything from the first newline (CR|LF). More... | |
int | exist_process (char *) |
Process_T | get_process (char *) |
void | printrunlist () |
Print the Runtime object. More... | |
void | printprocess (Process_T) |
Print a process object. More... | |
void | printprocesslist () |
Print all the processes in the processlist. More... | |
pid_t | get_pid (char *) |
Open and read the pid from the given pidfile. More... | |
int | is_process_running (Process_T) |
int | is_strdefined (char *) |
int | isreg_file (char *) |
Check if the file is a regular file. More... | |
char * | stripfilename (char *) |
Strip the path and return only the filename. More... | |
int | exist_file (char *) |
time_t | file_changedtime (char *file) |
Get a files last modified timestamp. More... | |
char * | get_ctime () |
Get a non terminated ctime. More... | |
char * | get_RFC1123date (long *) |
Returns a (RFC1123) Date string. More... | |
char * | get_uptime (long delta) |
char * | get_process_uptime (char *) |
Compute an uptime string for a process based on the ctime from the pidfile. More... | |
char * | get_md5sum (char *) |
int | check_md5 (char *, char *) |
char * | url_encode (char *uri) |
Escape an uri string converting unsafe characters to a hex (xx) representation. More... | |
char * | get_basic_authentication_header () |
int | set_md5sum (char **, char *) |
Compute a md5 checksum for the given file and save the result in an allocated area pointed to by dest. More... | |
int | parse (char *) |
void | start () |
Start all processes in the process list. More... | |
void | start_group (char *) |
Start all processes in the group. More... | |
void | start_process (Process_T) |
Start the given process. More... | |
void | dstart_process (char *) |
Request the monit deamon to start the process P. More... | |
void | stop () |
Stop all processes in the process list. More... | |
void | stop_group (char *) |
Stop all processes in the group. More... | |
void | stop_process (Process_T) |
stop the process. More... | |
void | dstop_process (char *) |
Request the monit deamon to stop the process P. More... | |
void | spawn (Process_T, Command_T) |
Execute the given command. More... | |
void | status () |
Show all processes in the process list. More... | |
void | status_group (char *) |
Show all processes in the group. More... | |
int | log_init () |
Initialize the log system and 'log' function. More... | |
void | log (const char *format,...) |
Log a message to monits logfile or syslog. More... | |
void | log_close () |
Close the log file or syslog. More... | |
int | get_log_fd () |
void | validate () |
Walk the process-list and validate each process. More... | |
void | daemonize () |
Transform a program into a daemon. More... | |
void | gc () |
void | gc_process (Process_T *) |
void | gc_mail_list (Mail_T *) |
void | init_files () |
Initialize the programs file variables. 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... | |
void | finalize_files () |
Remove temporary files. More... | |
char * | find_rcfile () |
Search the system for the monit control file. More... | |
int | create_pidfile (char *) |
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... | |
int | check_rcfile (char *) |
Secure check the monitrc file. More... | |
int | kill_daemon () |
Kill a daemon process. More... | |
int | exist_daemon () |
void | sendmail (Mail_T) |
Send SMTP mail messages. More... | |
int | sock_msg (int sock, char *,...) |
void | init_env () |
Initialize the program environment. More... | |
void * | xmalloc (int) |
void * | xcalloc (long, long) |
char * | xstrdup (const char *) |
void * | xresize (void *, long) |
void | set_alarm_handler (void *) |
Set a handler for the alarm signal, SIGALRM using sigaction. More... | |
void | monit_http (int) |
Start and stop the monit http server. More... | |
int | check_httpd () |
Check if the HTTPD server is running. More... | |
int | can_http () |
char * | format (const char *, va_list) |
Does printf style format line parsing. More... | |
Variables | |
Process_T | processlist |
The process list (created in p.y). More... | |
char * | prog |
The Name of this Program. More... | |
myrun | Run |
Struct holding runtime constants. More... | |
int | have_tty |
Do we have a valid tty. More... | |
char * | mygroup |
Group Name of the Process. More... |
|
|
|
|
|
Definition at line 78 of file monitor.h. Referenced by add_host_allow(), destroy_hosts_allow(), and has_hosts_allow(). |
|
|
|
Definition at line 65 of file monitor.h. Referenced by exist_process(), get_process(), start_group(), status_group(), and stop_group(). |
|
|
|
Value: do { pthread_mutex_t *_yymutex = &(mutex); \ pthread_mutex_lock(_yymutex);
Definition at line 76 of file monitor.h. Referenced by add_host_allow(), destroy_hosts_allow(), and has_hosts_allow(). |
|
|
|
Definition at line 64 of file monitor.h. Referenced by file_changedtime(). |
|
Definition at line 40 of file monitor.h. Referenced by find_rcfile(). |
|
Definition at line 49 of file monitor.h. Referenced by init_files(). |
|
Definition at line 50 of file monitor.h. Referenced by init_files(). |
|
----------------------------------------------- Object Constructor macro.
Definition at line 83 of file monitor.h. Referenced by add_host_allow(), create_default(), create_ftp(), create_http(), create_imap(), create_nntp(), create_pop(), create_smtp(), and set_header(). |
|
Definition at line 48 of file monitor.h. Referenced by create_pidfile(). |
|
|
|
Definition at line 55 of file monitor.h. Referenced by sendmail(). |
|
Definition at line 58 of file monitor.h. Referenced by monit_http(). |
|
Definition at line 59 of file monitor.h. Referenced by monit_http(). |
|
Definition at line 42 of file monitor.h. Referenced by check_ftp(), check_http(), check_imap(), check_nntp(), check_pop(), check_rcfile(), check_smtp(), create_pidfile(), daemonize(), get_pid(), kill_daemon(), log_close(), start_httpd(), xcalloc(), xmalloc(), and xresize(). |
|
|
|
|
|
|
|
Definition at line 39 of file monitor.h. Referenced by check_http(), and sendmail(). |
|
Defines a checksum object.
|
|
Defines a command with ARGMAX optional arguments. The arguments array must be NULL terminated and the first entry is the program itself. |
|
Defines a mailinglist object.
|
|
Defines a port object.
|
|
Defines process data.
|
|
Defines procfs (or other mechanism) data.
|
|
Defines a protocol object with protocol functions.
|
|
Defines resource data.
|
|
Replace the standard signal function with a more reliable using sigaction.
Definition at line 68 of file monitor.h. Referenced by signal(). |
|
Definition at line 86 of file monit_http.c. References myrun::Auth, myrun::myautentication::defined, myrun::dohttpd, error(), has_hosts_allow(), myrun::isdaemon, prog, and Run. |
|
Check if the HTTPD server is running.
Definition at line 73 of file monit_http.c. References myrun::bind_addr, check_connect(), myrun::httpdport, and Run. |
|
Definition at line 828 of file util.c. References get_md5sum(). |
|
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)
|
|
Removes everything from the first newline (CR|LF).
Definition at line 133 of file util.c. Referenced by check_ftp(), check_http(), check_imap(), check_nntp(), check_pop(), check_smtp(), and get_ctime(). |
|
Create a program's pidfile - Such a file is created when in daemon mode. The file is created with mask = PIDMASK (usually 644).
|
|
Transform a program into a daemon. Inspired by code from Stephen A. Rago's book, Unix System V Network Programming. Definition at line 70 of file daemonize.c. |
|
Request the monit deamon to start the process P.
Definition at line 125 of file start.c. References myrun::bind_addr, close_socket(), myrun::controlfile, create_socket(), error(), exist_daemon(), exist_process(), get_basic_authentication_header(), get_process(), myrun::httpdport, is_process_running(), prog, Run, sock_send(), and start_process(). Referenced by start(), and start_group(). |
|
Request the monit deamon to stop the process P.
Definition at line 123 of file stop.c. References myrun::bind_addr, close_socket(), myrun::controlfile, create_socket(), error(), exist_daemon(), exist_process(), get_basic_authentication_header(), get_process(), myrun::httpdport, is_process_running(), prog, Run, sock_send(), and stop_process(). Referenced by stop(), and stop_group(). |
|
Print a formated message to stderr or to the logfile if no tty exist.
Definition at line 81 of file util.c. References format(), and log(). Referenced by can_http(), check_rcfile(), create_pidfile(), dstart_process(), dstop_process(), find_rcfile(), kill_daemon(), log_close(), start_httpd(), start_process(), stop_process(), xcalloc(), xmalloc(), and xresize(). |
|
Definition at line 180 of file daemonize.c. References is_process_running(), myrun::pidfile, myprocess::pidfile, and Run. Referenced by dstart_process(), dstop_process(), and kill_daemon(). |
|
Definition at line 318 of file files.c. Referenced by find_rcfile(), and get_pid(). |
|
Definition at line 321 of file util.c. References is, myprocess::name, myprocess::next, and processlist. Referenced by dstart_process(), and dstop_process(). |
|
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
Definition at line 225 of file files.c. References MAXIMUM. Referenced by get_process_uptime(). |
|
Remove temporary files.
Definition at line 95 of file files.c. References myrun::pidfile, and Run. |
|
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.
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(). |
|
Does printf style format line parsing.
Definition at line 911 of file util.c. References xmalloc(), and xresize(). Referenced by error(). |
|
Definition at line 51 of file gc.c. References gc_protocols(), mygroup, and processlist. |
|
Definition at line 113 of file gc.c. Referenced by gc_process(), and spawn(). |
|
Definition at line 60 of file gc.c. References gc_mail_list(). |
|
Definition at line 883 of file util.c. References myrun::Auth, myrun::myautentication::defined, encode_base64(), myrun::myautentication::passwd, Run, myrun::myautentication::uname, xmalloc(), and xstrdup(). Referenced by dstart_process(), and dstop_process(). |
|
Get a non
|
|
|
|
Definition at line 781 of file util.c. References isreg_file(), and xstrdup(). Referenced by check_md5(), and set_md5sum(). |
|
Open and read the pid from the given pidfile.
Definition at line 570 of file util.c. References exist_file(), isreg_file(), log(), prog, and STRERROR. Referenced by is_process_running(). |
|
Definition at line 304 of file util.c. References is, myprocess::name, myprocess::next, and processlist. Referenced by dstart_process(), and dstop_process(). |
|
Compute an uptime string for a process based on the ctime from the pidfile. The caller must free the returned string.
Definition at line 703 of file util.c. References file_changedtime(), get_uptime(), and xstrdup(). Referenced by status(). |
|
Returns a (RFC1123) Date string. If the given date is NULL compute the date now.
Definition at line 642 of file util.c. References xstrdup(). Referenced by sendmail(). |
|
|
|
Exchanges \escape sequences in a string.
|
|
Initialize the program environment.
Definition at line 73 of file env.c. References have_tty. Referenced by main(). |
|
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(). |
|
Definition at line 617 of file util.c. References get_pid(), and myprocess::pidfile. Referenced by dstart_process(), dstop_process(), exist_daemon(), start_process(), and stop_process(). |
|
Test the monit control file for changes.
Definition at line 203 of file files.c. References myrun::controlfile, and Run. |
|
|
|
Check if the file is a regular file.
Definition at line 304 of file files.c. Referenced by get_md5sum(), and get_pid(). |
|
Kill a daemon process.
Definition at line 148 of file daemonize.c. References error(), exist_daemon(), prog, and STRERROR. |
|
Log a message to monits logfile or syslog.
Definition at line 111 of file log.c. References myrun::debug, myrun::dolog, have_tty, Run, and myrun::use_syslog. Referenced by check_ftp(), check_http(), check_imap(), check_nntp(), check_pop(), check_smtp(), compare_resource(), daemonize(), error(), get_pid(), monit_http(), out_print(), spawn(), start_process(), stop_process(), and validate(). |
|
Close the log file or syslog.
Definition at line 148 of file log.c. References error(), prog, Run, STRERROR, and myrun::use_syslog. Referenced by log_init(). |
|
Initialize the log system and 'log' function.
Definition at line 84 of file log.c. References myrun::dolog, log_close(), and Run. |
|
Remove leading white space [ \t\r
Definition at line 167 of file util.c. Referenced by trim(). |
|
Start and stop the monit http server.
Definition at line 112 of file monit_http.c. References myrun::httpdport, log(), prog, Run, START_HTTP, STOP_HTTP, and stop_httpd(). |
|
|
|
|
Print all the processes in the processlist.
Definition at line 545 of file util.c. References myprocess::next, printprocess(), and processlist. |
|
Print the Runtime object.
Definition at line 336 of file util.c. References myrun::Auth, myrun::bind_addr, myrun::controlfile, myrun::debug, myrun::myautentication::defined, myrun::dohttpd, myrun::dolog, myrun::doprocess, myrun::myformat::from, myrun::httpdport, myrun::isdaemon, myrun::logfile, myrun::MailFormat, myrun::mailserver, myrun::myformat::message, myrun::pidfile, myrun::polltime, Run, myrun::myformat::subject, and myrun::use_syslog. |
|
Reinitialize the programs file variables.
Definition at line 105 of file files.c. References set_file_timestamp(). |
|
Remove trailing white space [ \t\r
Definition at line 183 of file util.c. Referenced by trim(). |
|
Send SMTP mail messages.
Definition at line 78 of file sendmail.c. References mymail::from, get_localhostname(), get_RFC1123date(), mymail::message, mymail::next, mymail::opt_message, prog, SMTP_TIMEOUT, mymail::subject, mymail::to, and VERSION. Referenced by spawn(). |
|
Set a handler for the alarm signal, SIGALRM using sigaction.
|
|
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(). |
|
Compute a md5 checksum for the given file and save the result in an allocated area pointed to by dest. The caller is responsible for freeing dest.
Definition at line 765 of file util.c. References get_md5sum(). |
|
Replace the standard signal() function, with a more reliable using sigaction. From W. Richard Stevens' "Advanced Programming in the UNIX Environment" Definition at line 47 of file signal.c. References Sigfunc. |
|
|
|
Execute the given command. If the execution fails, an alert message is sent to the email addresses found in the process object that has registred interest for restart alerts.
Definition at line 84 of file spawn.c. References mycommand::arg, gc_mail_list(), log(), Run, sendmail(), signal(), and myrun::umask. Referenced by start_process(), and stop_process(). |
|
Start all processes in the process list.
Definition at line 56 of file start.c. References dstart_process(), myprocess::name, myprocess::next, processlist, and myprocess::start. |
|
Start all processes in the group.
Definition at line 72 of file start.c. References dstart_process(), myprocess::group, is, myprocess::name, myprocess::next, processlist, and myprocess::start. |
|
Start the given process.
Definition at line 94 of file start.c. References mycommand::arg, error(), is_process_running(), log(), myprocess::name, spawn(), and myprocess::start. Referenced by dstart_process(). |
|
Return TRUE if the string a starts with the string b.
|
|
Show all processes in the process list.
Definition at line 66 of file status.c. References get_process_uptime(), myprocess::next, myrun::pidfile, processlist, and Run. |
|
Show all processes in the group.
Definition at line 95 of file status.c. References myprocess::group, is, myprocess::next, and processlist. |
|
Stop all processes in the process list.
Definition at line 56 of file stop.c. References dstop_process(), myprocess::name, myprocess::next, processlist, and myprocess::stop. |
|
Stop all processes in the group.
Definition at line 72 of file stop.c. References dstop_process(), myprocess::group, is, myprocess::name, myprocess::next, processlist, and myprocess::stop. |
|
stop the process.
Definition at line 93 of file stop.c. References mycommand::arg, error(), is_process_running(), log(), myprocess::name, spawn(), and myprocess::stop. Referenced by dstop_process(). |
|
Strip the path and return only the filename.
Definition at line 120 of file util.c. Referenced by main(). |
|
Remove leading and trailing space from the string.
|
|
Remove any enclosing quotes ["'] from the string.
|
|
Escape an uri string converting unsafe characters to a hex (xx) representation. The caller must free the returned string.
Definition at line 853 of file util.c. References xmalloc(). |
|
Walk the process-list and validate each process.
Definition at line 86 of file validate.c. References log(), myprocess::next, processlist, and update_loadavg(). |
|
|
|
Definition at line 52 of file xmalloc.c. References error(), prog, and STRERROR. Referenced by decode_base64(), encode_base64(), find_rcfile(), format(), get_basic_authentication_header(), get_ctime(), makeword(), out_print(), url_encode(), xresize(), and xstrdup(). |
|
Definition at line 110 of file xmalloc.c. |
|
Definition at line 98 of file xmalloc.c. References xmalloc(). Referenced by add_host_allow(), get_basic_authentication_header(), get_header(), get_headers(), get_md5sum(), get_parameter(), get_process_uptime(), get_RFC1123date(), get_status_string(), get_uptime(), init_files(), set_header(), and set_status(). |
|
Do we have a valid tty.
|
|
Group Name of the Process.
Definition at line 253 of file monitor.h. Referenced by gc(). |
|
The process list (created in p.y).
Definition at line 249 of file monitor.h. Referenced by exist_process(), gc(), get_process(), printprocesslist(), start(), start_group(), status(), status_group(), stop(), stop_group(), and validate(). |
|
The Name of this Program.
Definition at line 250 of file monitor.h. Referenced by can_http(), check_http(), check_rcfile(), create_pidfile(), dstart_process(), dstop_process(), find_rcfile(), get_pid(), kill_daemon(), log_close(), main(), monit_http(), sendmail(), xcalloc(), xmalloc(), and xresize(). |
|
Struct holding runtime constants.
Definition at line 251 of file monitor.h. Referenced by can_http(), check_httpd(), dstart_process(), dstop_process(), exist_daemon(), finalize_files(), find_rcfile(), get_basic_authentication_header(), init_files(), is_rcfile_changed(), log(), log_close(), log_init(), monit_http(), printrunlist(), set_file_timestamp(), spawn(), status(), and update_loadavg(). |