00001 /*************************************************************************** 00002 BSD License 00003 00004 Copyright (c) 2002, Intel Corporation 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without 00008 modification, are permitted provided that the following conditions are met: 00009 00010 a.. Redistributions of source code must retain the above copyright notice, 00011 this list of conditions and the following disclaimer. 00012 b.. Redistributions in binary form must reproduce the above copyright notice, 00013 this list of conditions and the following disclaimer in the documentation 00014 and/or other materials provided with the distribution. 00015 c.. Neither the name of Intel Corporation nor the names of its contributors 00016 may be used to endorse or promote products derived from this software 00017 without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00023 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00026 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 00030 ****************************************************************************/ 00031 00032 #ifndef __AHM_H__ 00033 #define __AHM_H__ 00034 00035 #include <sys/types.h> 00036 #include <unistd.h> 00037 #include <glib.h> 00038 00039 #if (POSIX_EVENT_LOGGING) 00040 #include <posix_evlog.h> 00041 #endif 00042 00043 00044 #define REGISTRATION_DIRECTORY "/var/appmonitord" 00045 #define REGISTRATION_INTERVAL 3000 /* in milliseconds */ 00046 #define NAME_LENGTH 256 00047 #define STRING_LENGTH 256 00048 00049 #define MILLISECONDS_TO_MICROSECONDS 1000 00050 00051 #define ASCII_ZERO 48 00052 #define ASCII_NINE 57 00053 00054 #define ENOTFOUND 1 00055 #define E_UID_INVALID 2 00056 #define E_GID_INVALID 3 00057 #define E_MODE_INVALID 4 00058 #define E_FILE_NOT_FOUND 5 00059 #define E_INVALID 6 00060 #define E_FAULT 7 00061 00062 #define SUCCESS 0 00063 00064 extern int errno; 00065 00066 /** 00067 * Each application may register using a registration file and 00068 * writing its registration information in that file. The 00069 * application may provide an application identifier that is 00070 * unique to the application's actual process id (which is 00071 * unique on the system). This allows a single process 00072 * to register more than one heartbeat. 00073 * 00074 * This structure is used as the "value" for the hash table. 00075 */ 00076 typedef struct reginfo { 00077 00078 pid_t m_pid; /** the process id */ 00079 uid_t m_uid; /** the uid of the process */ 00080 uid_t m_gid; /** the gid of the process */ 00081 00082 unsigned long m_appid; /** the application identifier */ 00083 00084 int m_hbfd; /** the heartbeat fifo descriptor */ 00085 char m_procname[NAME_LENGTH]; /** The name of the process */ 00086 char m_regfilename[NAME_LENGTH]; /** The registration file filename */ 00087 char m_processname[NAME_LENGTH]; /** The process name */ 00088 char m_hbfifoname[NAME_LENGTH]; /** The name of the fifo to read heartbeats */ 00089 char m_script[NAME_LENGTH]; /** The full path to the recovery script */ 00090 unsigned long m_period; /** The duration between updates, in milliseconds */ 00091 time_t m_creation; /** The timestamp for creation of file */ 00092 00093 gboolean m_invalid_registration; /** indicates if the registration file could not be parsed or has invalid components */ 00094 00095 } registration_info; 00096 00097 /** 00098 * This structure is used as the "key" in the hash table 00099 */ 00100 typedef struct regkey { 00101 pid_t pid; 00102 } registration_key; 00103 00104 /** 00105 * This is the structure that contains the fifo data to 00106 * be passed in a heartbeat. 00107 * 00108 */ 00109 typedef struct pingdata { 00110 long data; 00111 time_t timestamp; 00112 } ping_data; 00113 00114 /** This is the hash table containing the registered processes */ 00115 extern GHashTable * prochash; 00116 00117 /** This is the main event loop for the application */ 00118 extern GMainLoop * mainloop; 00119 00120 /** Indicates if the monitor should be run as a daemon or not. 00121 This intent of this is to help with debugging */ 00122 extern gboolean daemon_mode; 00123 00124 /** This is the location where applications should register */ 00125 extern char registration_dir[NAME_LENGTH]; 00126 00127 /** This is the approximate amount of time to allow to lapse 00128 between checking for new registrations */ 00129 extern unsigned long register_period; 00130 00131 /** FUNCTION PROTOTYPES */ 00132 00133 void signal_shutdown(int a_arg); 00134 pid_t extract_pid(const char *d_name); 00135 int start_daemon(int a_ignoreSIGCLD); 00136 void sig_child(); 00137 int validate_process(pid_t a_pid); 00138 gboolean find_registration_files(gpointer a_data); 00139 int verify_heartbeat_fifo(const char *a_fifoname, const registration_info *a_reginfo); 00140 void recover_process(registration_key *a_regkey, registration_info *a_reginfo); 00141 00142 00143 #endif /* __AHM_H__ */ 00144 00145