~yolanda.robla/ubuntu/saucy/nagios3/dep-8-tests

« back to all changes in this revision

Viewing changes to base/nagios.c

  • Committer: Package Import Robot
  • Author(s): Alexander Wirt
  • Date: 2012-06-16 09:05:19 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120616090519-ne14zejkhhyboolc
Tags: 3.4.1-1
* [28e077b] Imported Upstream version 3.3.1
* [d5314e0] don't call updatepo in clean target
* [45b3eb9] Don't remove config foo
* [54e3dff] Don't fix permissions in cgi postinst
* [d7be9db] Build-depend on libpng-dev (Closes: #662441)
* [4c47006] Add dutch po translation (Closes: #654855)
* [2b6573b] Refresh 10_p1_pl_shebang.dpatch
* [316fd7a] Update 40_fix_spurious_dollar_signs_added_to_command_lines
* [5ff2780] Refresh 55_strip_logarchivepath.dpatch
* [811d269] Refresh 60_fix_p1.pl_patch_mini_epn.dpatch
* [39a1e9c] Remove now unneeded patch 98_fix_XSS_CVE-2011-2179
* [785a4e8] Remove unneded patch 99_fix_XSS_CVE-2011-1523
* [6ce98ef] Remove unneeded patchs from 00list
* [1d18266] Imported Upstream version 3.4.0
* [05584c8] Refresh patches
* [58098cd] Imported Upstream version 3.4.1
* [3e9e07a] Bump standards version
* [fe991e2] wrap-and-sort
* [1ba78f7] Also create /var/run/nagios in cgi package (Closes: #626854)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * NAGIOS.C - Core Program Code For Nagios
4
4
 *
5
5
 * Program: Nagios Core
6
 
 * Version: 3.2.3
 
6
 * Version: 3.4.1
7
7
 * License: GPL
8
8
 * Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
9
9
 * Copyright (c) 1999-2009 Ethan Galstad
10
10
 *
11
11
 * First Written:   01-28-1999 (start of development)
12
 
 * Last Modified:   10-03-2010
 
12
 * Last Modified:   05-11-2012
13
13
 *
14
14
 * Description:
15
15
 *
56
56
#endif
57
57
 
58
58
 
59
 
char            *config_file=NULL;
60
 
char            *log_file=NULL;
61
 
char            *command_file=NULL;
62
 
char            *temp_file=NULL;
63
 
char            *temp_path=NULL;
64
 
char            *check_result_path=NULL;
65
 
char            *lock_file=NULL;
66
 
char            *log_archive_path=NULL;
67
 
char            *p1_file=NULL;    /**** EMBEDDED PERL ****/
68
 
char            *auth_file=NULL;  /**** EMBEDDED PERL INTERPRETER AUTH FILE ****/
69
 
char            *nagios_user=NULL;
70
 
char            *nagios_group=NULL;
71
 
 
72
 
extern char     *macro_x[MACRO_X_COUNT];
73
 
 
74
 
char            *global_host_event_handler=NULL;
75
 
char            *global_service_event_handler=NULL;
76
 
command         *global_host_event_handler_ptr=NULL;
77
 
command         *global_service_event_handler_ptr=NULL;
78
 
 
79
 
char            *ocsp_command=NULL;
80
 
char            *ochp_command=NULL;
81
 
command         *ocsp_command_ptr=NULL;
82
 
command         *ochp_command_ptr=NULL;
83
 
 
84
 
char            *illegal_object_chars=NULL;
85
 
char            *illegal_output_chars=NULL;
86
 
 
87
 
int             use_regexp_matches=FALSE;
88
 
int             use_true_regexp_matching=FALSE;
89
 
 
90
 
int             use_syslog=DEFAULT_USE_SYSLOG;
91
 
int             log_notifications=DEFAULT_NOTIFICATION_LOGGING;
92
 
int             log_service_retries=DEFAULT_LOG_SERVICE_RETRIES;
93
 
int             log_host_retries=DEFAULT_LOG_HOST_RETRIES;
94
 
int             log_event_handlers=DEFAULT_LOG_EVENT_HANDLERS;
95
 
int             log_initial_states=DEFAULT_LOG_INITIAL_STATES;
96
 
int             log_external_commands=DEFAULT_LOG_EXTERNAL_COMMANDS;
97
 
int             log_passive_checks=DEFAULT_LOG_PASSIVE_CHECKS;
98
 
 
99
 
unsigned long   logging_options=0;
100
 
unsigned long   syslog_options=0;
101
 
 
102
 
int             service_check_timeout=DEFAULT_SERVICE_CHECK_TIMEOUT;
103
 
int             host_check_timeout=DEFAULT_HOST_CHECK_TIMEOUT;
104
 
int             event_handler_timeout=DEFAULT_EVENT_HANDLER_TIMEOUT;
105
 
int             notification_timeout=DEFAULT_NOTIFICATION_TIMEOUT;
106
 
int             ocsp_timeout=DEFAULT_OCSP_TIMEOUT;
107
 
int             ochp_timeout=DEFAULT_OCHP_TIMEOUT;
108
 
 
109
 
double          sleep_time=DEFAULT_SLEEP_TIME;
110
 
int             interval_length=DEFAULT_INTERVAL_LENGTH;
111
 
int             service_inter_check_delay_method=ICD_SMART;
112
 
int             host_inter_check_delay_method=ICD_SMART;
113
 
int             service_interleave_factor_method=ILF_SMART;
114
 
int             max_host_check_spread=DEFAULT_HOST_CHECK_SPREAD;
115
 
int             max_service_check_spread=DEFAULT_SERVICE_CHECK_SPREAD;
116
 
 
117
 
int             command_check_interval=DEFAULT_COMMAND_CHECK_INTERVAL;
118
 
int             check_reaper_interval=DEFAULT_CHECK_REAPER_INTERVAL;
119
 
int             max_check_reaper_time=DEFAULT_MAX_REAPER_TIME;
120
 
int             service_freshness_check_interval=DEFAULT_FRESHNESS_CHECK_INTERVAL;
121
 
int             host_freshness_check_interval=DEFAULT_FRESHNESS_CHECK_INTERVAL;
122
 
int             auto_rescheduling_interval=DEFAULT_AUTO_RESCHEDULING_INTERVAL;
123
 
 
124
 
int             check_external_commands=DEFAULT_CHECK_EXTERNAL_COMMANDS;
125
 
int             check_orphaned_services=DEFAULT_CHECK_ORPHANED_SERVICES;
126
 
int             check_orphaned_hosts=DEFAULT_CHECK_ORPHANED_HOSTS;
127
 
int             check_service_freshness=DEFAULT_CHECK_SERVICE_FRESHNESS;
128
 
int             check_host_freshness=DEFAULT_CHECK_HOST_FRESHNESS;
129
 
int             auto_reschedule_checks=DEFAULT_AUTO_RESCHEDULE_CHECKS;
130
 
int             auto_rescheduling_window=DEFAULT_AUTO_RESCHEDULING_WINDOW;
131
 
 
132
 
int             additional_freshness_latency=DEFAULT_ADDITIONAL_FRESHNESS_LATENCY;
133
 
 
134
 
int             check_for_updates=DEFAULT_CHECK_FOR_UPDATES;
135
 
int             bare_update_check=DEFAULT_BARE_UPDATE_CHECK;
136
 
time_t          last_update_check=0L;
137
 
unsigned long   update_uid=0L;
138
 
int             update_available=FALSE;
139
 
char            *last_program_version=NULL;
140
 
char            *new_program_version=NULL;
141
 
 
142
 
time_t          last_command_check=0L;
143
 
time_t          last_command_status_update=0L;
144
 
time_t          last_log_rotation=0L;
145
 
 
146
 
int             use_aggressive_host_checking=DEFAULT_AGGRESSIVE_HOST_CHECKING;
147
 
unsigned long   cached_host_check_horizon=DEFAULT_CACHED_HOST_CHECK_HORIZON;
148
 
unsigned long   cached_service_check_horizon=DEFAULT_CACHED_SERVICE_CHECK_HORIZON;
149
 
int             enable_predictive_host_dependency_checks=DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS;
150
 
int             enable_predictive_service_dependency_checks=DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS;
151
 
 
152
 
int             soft_state_dependencies=FALSE;
153
 
 
154
 
int             retain_state_information=FALSE;
155
 
int             retention_update_interval=DEFAULT_RETENTION_UPDATE_INTERVAL;
156
 
int             use_retained_program_state=TRUE;
157
 
int             use_retained_scheduling_info=FALSE;
158
 
int             retention_scheduling_horizon=DEFAULT_RETENTION_SCHEDULING_HORIZON;
159
 
unsigned long   modified_host_process_attributes=MODATTR_NONE;
160
 
unsigned long   modified_service_process_attributes=MODATTR_NONE;
161
 
unsigned long   retained_host_attribute_mask=0L;
162
 
unsigned long   retained_service_attribute_mask=0L;
163
 
unsigned long   retained_contact_host_attribute_mask=0L;
164
 
unsigned long   retained_contact_service_attribute_mask=0L;
165
 
unsigned long   retained_process_host_attribute_mask=0L;
166
 
unsigned long   retained_process_service_attribute_mask=0L;
167
 
 
168
 
unsigned long   next_comment_id=0L;
169
 
unsigned long   next_downtime_id=0L;
170
 
unsigned long   next_event_id=0L;
171
 
unsigned long   next_problem_id=0L;
172
 
unsigned long   next_notification_id=0L;
173
 
 
174
 
int             log_rotation_method=LOG_ROTATION_NONE;
175
 
 
176
 
int             sigshutdown=FALSE;
177
 
int             sigrestart=FALSE;
178
 
char            *sigs[35]={"EXIT","HUP","INT","QUIT","ILL","TRAP","ABRT","BUS","FPE","KILL","USR1","SEGV","USR2","PIPE","ALRM","TERM","STKFLT","CHLD","CONT","STOP","TSTP","TTIN","TTOU","URG","XCPU","XFSZ","VTALRM","PROF","WINCH","IO","PWR","UNUSED","ZERR","DEBUG",(char *)NULL};
179
 
int             caught_signal=FALSE;
180
 
int             sig_id=0;
181
 
 
182
 
int             restarting=FALSE;
183
 
 
184
 
int             verify_config=FALSE;
185
 
int             verify_object_relationships=TRUE;
186
 
int             verify_circular_paths=TRUE;
187
 
int             test_scheduling=FALSE;
188
 
int             precache_objects=FALSE;
189
 
int             use_precached_objects=FALSE;
190
 
 
191
 
int             daemon_mode=FALSE;
192
 
int             daemon_dumps_core=TRUE;
193
 
 
194
 
int             max_parallel_service_checks=DEFAULT_MAX_PARALLEL_SERVICE_CHECKS;
195
 
int             currently_running_service_checks=0;
196
 
int             currently_running_host_checks=0;
197
 
 
198
 
time_t          program_start=0L;
199
 
time_t          event_start=0L;
200
 
int             nagios_pid=0;
201
 
int             enable_notifications=TRUE;
202
 
int             execute_service_checks=TRUE;
203
 
int             accept_passive_service_checks=TRUE;
204
 
int             execute_host_checks=TRUE;
205
 
int             accept_passive_host_checks=TRUE;
206
 
int             enable_event_handlers=TRUE;
207
 
int             obsess_over_services=FALSE;
208
 
int             obsess_over_hosts=FALSE;
209
 
int             enable_failure_prediction=TRUE;
210
 
 
211
 
int             translate_passive_host_checks=DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS;
212
 
int             passive_host_checks_are_soft=DEFAULT_PASSIVE_HOST_CHECKS_SOFT;
213
 
 
214
 
int             aggregate_status_updates=TRUE;
215
 
int             status_update_interval=DEFAULT_STATUS_UPDATE_INTERVAL;
216
 
 
217
 
int             time_change_threshold=DEFAULT_TIME_CHANGE_THRESHOLD;
218
 
 
219
 
unsigned long   event_broker_options=BROKER_NOTHING;
220
 
 
221
 
int             process_performance_data=DEFAULT_PROCESS_PERFORMANCE_DATA;
222
 
 
223
 
int             enable_flap_detection=DEFAULT_ENABLE_FLAP_DETECTION;
224
 
 
225
 
double          low_service_flap_threshold=DEFAULT_LOW_SERVICE_FLAP_THRESHOLD;
226
 
double          high_service_flap_threshold=DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD;
227
 
double          low_host_flap_threshold=DEFAULT_LOW_HOST_FLAP_THRESHOLD;
228
 
double          high_host_flap_threshold=DEFAULT_HIGH_HOST_FLAP_THRESHOLD;
229
 
 
230
 
int             use_large_installation_tweaks=DEFAULT_USE_LARGE_INSTALLATION_TWEAKS;
231
 
int             enable_environment_macros=TRUE;
232
 
int             free_child_process_memory=-1;
233
 
int             child_processes_fork_twice=-1;
234
 
 
235
 
int             enable_embedded_perl=DEFAULT_ENABLE_EMBEDDED_PERL;
236
 
int             use_embedded_perl_implicitly=DEFAULT_USE_EMBEDDED_PERL_IMPLICITLY;
237
 
int             embedded_perl_initialized=FALSE;
238
 
 
239
 
int             date_format=DATE_FORMAT_US;
240
 
char            *use_timezone=NULL;
 
59
char            *config_file = NULL;
 
60
char            *log_file = NULL;
 
61
char            *command_file = NULL;
 
62
char            *temp_file = NULL;
 
63
char            *temp_path = NULL;
 
64
char            *check_result_path = NULL;
 
65
char            *lock_file = NULL;
 
66
char            *log_archive_path = NULL;
 
67
char            *p1_file = NULL;  /**** EMBEDDED PERL ****/
 
68
char            *auth_file = NULL; /**** EMBEDDED PERL INTERPRETER AUTH FILE ****/
 
69
char            *nagios_user = NULL;
 
70
char            *nagios_group = NULL;
 
71
 
 
72
char            *global_host_event_handler = NULL;
 
73
char            *global_service_event_handler = NULL;
 
74
command         *global_host_event_handler_ptr = NULL;
 
75
command         *global_service_event_handler_ptr = NULL;
 
76
 
 
77
char            *ocsp_command = NULL;
 
78
char            *ochp_command = NULL;
 
79
command         *ocsp_command_ptr = NULL;
 
80
command         *ochp_command_ptr = NULL;
 
81
 
 
82
char            *illegal_object_chars = NULL;
 
83
char            *illegal_output_chars = NULL;
 
84
 
 
85
int             use_regexp_matches = FALSE;
 
86
int             use_true_regexp_matching = FALSE;
 
87
 
 
88
int             use_syslog = DEFAULT_USE_SYSLOG;
 
89
int             log_notifications = DEFAULT_NOTIFICATION_LOGGING;
 
90
int             log_service_retries = DEFAULT_LOG_SERVICE_RETRIES;
 
91
int             log_host_retries = DEFAULT_LOG_HOST_RETRIES;
 
92
int             log_event_handlers = DEFAULT_LOG_EVENT_HANDLERS;
 
93
int             log_initial_states = DEFAULT_LOG_INITIAL_STATES;
 
94
int             log_external_commands = DEFAULT_LOG_EXTERNAL_COMMANDS;
 
95
int             log_passive_checks = DEFAULT_LOG_PASSIVE_CHECKS;
 
96
 
 
97
unsigned long   logging_options = 0;
 
98
unsigned long   syslog_options = 0;
 
99
 
 
100
int             service_check_timeout = DEFAULT_SERVICE_CHECK_TIMEOUT;
 
101
int             service_check_timeout_state=STATE_CRITICAL;
 
102
int             host_check_timeout = DEFAULT_HOST_CHECK_TIMEOUT;
 
103
int             event_handler_timeout = DEFAULT_EVENT_HANDLER_TIMEOUT;
 
104
int             notification_timeout = DEFAULT_NOTIFICATION_TIMEOUT;
 
105
int             ocsp_timeout = DEFAULT_OCSP_TIMEOUT;
 
106
int             ochp_timeout = DEFAULT_OCHP_TIMEOUT;
 
107
 
 
108
double          sleep_time = DEFAULT_SLEEP_TIME;
 
109
int             interval_length = DEFAULT_INTERVAL_LENGTH;
 
110
int             service_inter_check_delay_method = ICD_SMART;
 
111
int             host_inter_check_delay_method = ICD_SMART;
 
112
int             service_interleave_factor_method = ILF_SMART;
 
113
int             max_host_check_spread = DEFAULT_HOST_CHECK_SPREAD;
 
114
int             max_service_check_spread = DEFAULT_SERVICE_CHECK_SPREAD;
 
115
 
 
116
int             command_check_interval = DEFAULT_COMMAND_CHECK_INTERVAL;
 
117
int             check_reaper_interval = DEFAULT_CHECK_REAPER_INTERVAL;
 
118
int             max_check_reaper_time = DEFAULT_MAX_REAPER_TIME;
 
119
int             service_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL;
 
120
int             host_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL;
 
121
int             auto_rescheduling_interval = DEFAULT_AUTO_RESCHEDULING_INTERVAL;
 
122
 
 
123
int             check_external_commands = DEFAULT_CHECK_EXTERNAL_COMMANDS;
 
124
int             check_orphaned_services = DEFAULT_CHECK_ORPHANED_SERVICES;
 
125
int             check_orphaned_hosts = DEFAULT_CHECK_ORPHANED_HOSTS;
 
126
int             check_service_freshness = DEFAULT_CHECK_SERVICE_FRESHNESS;
 
127
int             check_host_freshness = DEFAULT_CHECK_HOST_FRESHNESS;
 
128
int             auto_reschedule_checks = DEFAULT_AUTO_RESCHEDULE_CHECKS;
 
129
int             auto_rescheduling_window = DEFAULT_AUTO_RESCHEDULING_WINDOW;
 
130
 
 
131
int             additional_freshness_latency = DEFAULT_ADDITIONAL_FRESHNESS_LATENCY;
 
132
 
 
133
int             check_for_updates = DEFAULT_CHECK_FOR_UPDATES;
 
134
int             bare_update_check = DEFAULT_BARE_UPDATE_CHECK;
 
135
time_t          last_update_check = 0L;
 
136
unsigned long   update_uid = 0L;
 
137
int             update_available = FALSE;
 
138
char            *last_program_version = NULL;
 
139
char            *new_program_version = NULL;
 
140
 
 
141
time_t          last_command_check = 0L;
 
142
time_t          last_command_status_update = 0L;
 
143
time_t          last_log_rotation = 0L;
 
144
time_t          last_program_stop = 0L;
 
145
 
 
146
int             use_aggressive_host_checking = DEFAULT_AGGRESSIVE_HOST_CHECKING;
 
147
unsigned long   cached_host_check_horizon = DEFAULT_CACHED_HOST_CHECK_HORIZON;
 
148
unsigned long   cached_service_check_horizon = DEFAULT_CACHED_SERVICE_CHECK_HORIZON;
 
149
int             enable_predictive_host_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS;
 
150
int             enable_predictive_service_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS;
 
151
 
 
152
int             soft_state_dependencies = FALSE;
 
153
 
 
154
int             retain_state_information = FALSE;
 
155
int             retention_update_interval = DEFAULT_RETENTION_UPDATE_INTERVAL;
 
156
int             use_retained_program_state = TRUE;
 
157
int             use_retained_scheduling_info = FALSE;
 
158
int             retention_scheduling_horizon = DEFAULT_RETENTION_SCHEDULING_HORIZON;
 
159
unsigned long   modified_host_process_attributes = MODATTR_NONE;
 
160
unsigned long   modified_service_process_attributes = MODATTR_NONE;
 
161
unsigned long   retained_host_attribute_mask = 0L;
 
162
unsigned long   retained_service_attribute_mask = 0L;
 
163
unsigned long   retained_contact_host_attribute_mask = 0L;
 
164
unsigned long   retained_contact_service_attribute_mask = 0L;
 
165
unsigned long   retained_process_host_attribute_mask = 0L;
 
166
unsigned long   retained_process_service_attribute_mask = 0L;
 
167
 
 
168
unsigned long   next_comment_id = 0L;
 
169
unsigned long   next_downtime_id = 0L;
 
170
unsigned long   next_event_id = 0L;
 
171
unsigned long   next_problem_id = 0L;
 
172
unsigned long   next_notification_id = 0L;
 
173
 
 
174
int             log_rotation_method = LOG_ROTATION_NONE;
 
175
 
 
176
int             sigshutdown = FALSE;
 
177
int             sigrestart = FALSE;
 
178
char            *sigs[35] = {"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "URG", "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "IO", "PWR", "UNUSED", "ZERR", "DEBUG", (char *)NULL};
 
179
int             caught_signal = FALSE;
 
180
int             sig_id = 0;
 
181
 
 
182
int             restarting = FALSE;
 
183
 
 
184
int             verify_config = FALSE;
 
185
int             verify_object_relationships = TRUE;
 
186
int             verify_circular_paths = TRUE;
 
187
int             test_scheduling = FALSE;
 
188
int             precache_objects = FALSE;
 
189
int             use_precached_objects = FALSE;
 
190
 
 
191
int             daemon_mode = FALSE;
 
192
int             daemon_dumps_core = TRUE;
 
193
 
 
194
int             max_parallel_service_checks = DEFAULT_MAX_PARALLEL_SERVICE_CHECKS;
 
195
int             currently_running_service_checks = 0;
 
196
int             currently_running_host_checks = 0;
 
197
 
 
198
time_t          program_start = 0L;
 
199
time_t          event_start = 0L;
 
200
int             nagios_pid = 0;
 
201
int             enable_notifications = TRUE;
 
202
int             execute_service_checks = TRUE;
 
203
int             accept_passive_service_checks = TRUE;
 
204
int             execute_host_checks = TRUE;
 
205
int             accept_passive_host_checks = TRUE;
 
206
int             enable_event_handlers = TRUE;
 
207
int             obsess_over_services = FALSE;
 
208
int             obsess_over_hosts = FALSE;
 
209
int             enable_failure_prediction = TRUE;
 
210
 
 
211
int             translate_passive_host_checks = DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS;
 
212
int             passive_host_checks_are_soft = DEFAULT_PASSIVE_HOST_CHECKS_SOFT;
 
213
 
 
214
int             aggregate_status_updates = TRUE;
 
215
int             status_update_interval = DEFAULT_STATUS_UPDATE_INTERVAL;
 
216
 
 
217
int             time_change_threshold = DEFAULT_TIME_CHANGE_THRESHOLD;
 
218
 
 
219
unsigned long   event_broker_options = BROKER_NOTHING;
 
220
 
 
221
int             process_performance_data = DEFAULT_PROCESS_PERFORMANCE_DATA;
 
222
 
 
223
int             enable_flap_detection = DEFAULT_ENABLE_FLAP_DETECTION;
 
224
 
 
225
double          low_service_flap_threshold = DEFAULT_LOW_SERVICE_FLAP_THRESHOLD;
 
226
double          high_service_flap_threshold = DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD;
 
227
double          low_host_flap_threshold = DEFAULT_LOW_HOST_FLAP_THRESHOLD;
 
228
double          high_host_flap_threshold = DEFAULT_HIGH_HOST_FLAP_THRESHOLD;
 
229
 
 
230
int             use_large_installation_tweaks = DEFAULT_USE_LARGE_INSTALLATION_TWEAKS;
 
231
int             enable_environment_macros = TRUE;
 
232
int             free_child_process_memory = -1;
 
233
int             child_processes_fork_twice = -1;
 
234
 
 
235
int             enable_embedded_perl = DEFAULT_ENABLE_EMBEDDED_PERL;
 
236
int             use_embedded_perl_implicitly = DEFAULT_USE_EMBEDDED_PERL_IMPLICITLY;
 
237
int             embedded_perl_initialized = FALSE;
 
238
 
 
239
int             date_format = DATE_FORMAT_US;
 
240
char            *use_timezone = NULL;
 
241
 
 
242
int             allow_empty_hostgroup_assignment = DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT;
241
243
 
242
244
int             command_file_fd;
243
245
FILE            *command_file_fp;
244
 
int             command_file_created=FALSE;
 
246
int             command_file_created = FALSE;
245
247
 
246
248
 
247
249
extern contact         *contact_list;
254
256
notification    *notification_list;
255
257
 
256
258
check_result    check_result_info;
257
 
check_result    *check_result_list=NULL;
258
 
unsigned long   max_check_result_file_age=DEFAULT_MAX_CHECK_RESULT_AGE;
 
259
check_result    *check_result_list = NULL;
 
260
unsigned long   max_check_result_file_age = DEFAULT_MAX_CHECK_RESULT_AGE;
259
261
 
260
262
dbuf            check_result_dbuf;
261
263
 
262
264
circular_buffer external_command_buffer;
263
265
circular_buffer check_result_buffer;
264
266
pthread_t       worker_threads[TOTAL_WORKER_THREADS];
265
 
int             external_command_buffer_slots=DEFAULT_EXTERNAL_COMMAND_BUFFER_SLOTS;
 
267
int             external_command_buffer_slots = DEFAULT_EXTERNAL_COMMAND_BUFFER_SLOTS;
266
268
 
267
269
check_stats     check_statistics[MAX_CHECK_STATS_TYPES];
268
270
 
269
271
char            *debug_file;
270
 
int             debug_level=DEFAULT_DEBUG_LEVEL;
271
 
int             debug_verbosity=DEFAULT_DEBUG_VERBOSITY;
272
 
unsigned long   max_debug_file_size=DEFAULT_MAX_DEBUG_FILE_SIZE;
 
272
int             debug_level = DEFAULT_DEBUG_LEVEL;
 
273
int             debug_verbosity = DEFAULT_DEBUG_VERBOSITY;
 
274
unsigned long   max_debug_file_size = DEFAULT_MAX_DEBUG_FILE_SIZE;
273
275
 
274
276
 
275
277
 
276
278
 
277
279
/* Following main() declaration required by older versions of Perl ut 5.00503 */
278
 
#ifdef EMBEDDEDPERL
279
 
int main(int argc, char **argv, char **env){
280
 
#else
281
 
int main(int argc, char **argv){
282
 
#endif
 
280
int main(int argc, char **argv, char **env) {
283
281
        int result;
284
 
        int error=FALSE;
285
 
        char *buffer=NULL;
286
 
        int display_license=FALSE;
287
 
        int display_help=FALSE;
288
 
        int c=0;
289
 
        struct tm *tm;
 
282
        int error = FALSE;
 
283
        char *buffer = NULL;
 
284
        int display_license = FALSE;
 
285
        int display_help = FALSE;
 
286
        int c = 0;
 
287
        struct tm *tm, tm_s;
290
288
        time_t now;
291
289
        char datestring[256];
 
290
        nagios_macros *mac;
 
291
 
 
292
        mac = get_global_macros();
292
293
 
293
294
 
294
295
 
295
296
#ifdef HAVE_GETOPT_H
296
 
        int option_index=0;
297
 
        static struct option long_options[]=
298
 
        {
299
 
                {"help",no_argument,0,'h'},
300
 
                {"version",no_argument,0,'V'},
301
 
                {"license",no_argument,0,'V'},
302
 
                {"verify-config",no_argument,0,'v'},
303
 
                {"daemon",no_argument,0,'d'},
304
 
                {"test-scheduling",no_argument,0,'s'},
305
 
                {"dont-verify-objects",no_argument,0,'o'},
306
 
                {"dont-verify-paths",no_argument,0,'x'},
307
 
                {"precache-objects",no_argument,0,'p'},
308
 
                {"use-precached-objects",no_argument,0,'u'},
309
 
                {0,0,0,0}
310
 
        };
 
297
        int option_index = 0;
 
298
        static struct option long_options[] = {
 
299
                        {"help", no_argument, 0, 'h'},
 
300
                        {"version", no_argument, 0, 'V'},
 
301
                        {"license", no_argument, 0, 'V'},
 
302
                        {"verify-config", no_argument, 0, 'v'},
 
303
                        {"daemon", no_argument, 0, 'd'},
 
304
                        {"test-scheduling", no_argument, 0, 's'},
 
305
                        {"dont-verify-objects", no_argument, 0, 'o'},
 
306
                        {"dont-verify-paths", no_argument, 0, 'x'},
 
307
                        {"precache-objects", no_argument, 0, 'p'},
 
308
                        {"use-precached-objects", no_argument, 0, 'u'},
 
309
                        {0, 0, 0, 0}
 
310
                };
311
311
#endif
312
312
 
313
313
        /* make sure we have the correct number of command line arguments */
314
 
        if(argc<2)
315
 
                error=TRUE;
 
314
        if(argc < 2)
 
315
                error = TRUE;
316
316
 
317
317
 
318
318
        /* get all command line arguments */
319
 
        while(1){
 
319
        while(1) {
320
320
 
321
321
#ifdef HAVE_GETOPT_H
322
 
                c=getopt_long(argc,argv,"+hVvdsoxpu",long_options,&option_index);
 
322
                c = getopt_long(argc, argv, "+hVvdsoxpu", long_options, &option_index);
323
323
#else
324
 
                c=getopt(argc,argv,"+hVvdsoxpu");
 
324
                c = getopt(argc, argv, "+hVvdsoxpu");
325
325
#endif
326
326
 
327
 
                if(c==-1 || c==EOF)
328
 
                        break;
329
 
 
330
 
                switch(c){
331
 
                        
332
 
                case '?': /* usage */
333
 
                case 'h':
334
 
                        display_help=TRUE;
335
 
                        break;
336
 
 
337
 
                case 'V': /* version */
338
 
                        display_license=TRUE;
339
 
                        break;
340
 
 
341
 
                case 'v': /* verify */
342
 
                        verify_config=TRUE;
343
 
                        break;
344
 
 
345
 
                case 's': /* scheduling check */
346
 
                        test_scheduling=TRUE;
347
 
                        break;
348
 
 
349
 
                case 'd': /* daemon mode */
350
 
                        daemon_mode=TRUE;
351
 
                        break;
352
 
 
353
 
                case 'o': /* don't verify objects */
354
 
                        /*
355
 
                        verify_object_relationships=FALSE;
356
 
                        */
357
 
                        break;
358
 
 
359
 
                case 'x': /* don't verify circular paths */
360
 
                        verify_circular_paths=FALSE;
361
 
                        break;
362
 
 
363
 
                case 'p': /* precache object config */
364
 
                        precache_objects=TRUE;
365
 
                        break;
366
 
 
367
 
                case 'u': /* use precached object config */
368
 
                        use_precached_objects=TRUE;
369
 
                        break;
370
 
 
371
 
                default:
372
 
                        break;
373
 
                        }
374
 
 
375
 
                }
 
327
                if(c == -1 || c == EOF)
 
328
                        break;
 
329
 
 
330
                switch(c) {
 
331
 
 
332
                        case '?': /* usage */
 
333
                        case 'h':
 
334
                                display_help = TRUE;
 
335
                                break;
 
336
 
 
337
                        case 'V': /* version */
 
338
                                display_license = TRUE;
 
339
                                break;
 
340
 
 
341
                        case 'v': /* verify */
 
342
                                verify_config = TRUE;
 
343
                                break;
 
344
 
 
345
                        case 's': /* scheduling check */
 
346
                                test_scheduling = TRUE;
 
347
                                break;
 
348
 
 
349
                        case 'd': /* daemon mode */
 
350
                                daemon_mode = TRUE;
 
351
                                break;
 
352
 
 
353
                        case 'o': /* don't verify objects */
 
354
                                /*
 
355
                                verify_object_relationships=FALSE;
 
356
                                */
 
357
                                break;
 
358
 
 
359
                        case 'x': /* don't verify circular paths */
 
360
                                verify_circular_paths = FALSE;
 
361
                                break;
 
362
 
 
363
                        case 'p': /* precache object config */
 
364
                                precache_objects = TRUE;
 
365
                                break;
 
366
 
 
367
                        case 'u': /* use precached object config */
 
368
                                use_precached_objects = TRUE;
 
369
                                break;
 
370
 
 
371
                        default:
 
372
                                break;
 
373
                        }
 
374
 
 
375
                }
376
376
 
377
377
        /* make sure we have the right combination of arguments */
378
 
        if(precache_objects==TRUE && (test_scheduling==FALSE && verify_config==FALSE)){
379
 
                error=TRUE;
380
 
                display_help=TRUE;
381
 
                }
 
378
        if(precache_objects == TRUE && (test_scheduling == FALSE && verify_config == FALSE)) {
 
379
                error = TRUE;
 
380
                display_help = TRUE;
 
381
                }
382
382
 
383
383
#ifdef DEBUG_MEMORY
384
384
        mtrace();
385
385
#endif
386
386
 
387
 
        if(daemon_mode==FALSE){
388
 
                printf("\nNagios Core %s\n",PROGRAM_VERSION);
389
 
                printf("Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors\n");
 
387
        if(daemon_mode == FALSE) {
 
388
                printf("\nNagios Core %s\n", PROGRAM_VERSION);
 
389
                printf("Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors\n");
390
390
                printf("Copyright (c) 1999-2009 Ethan Galstad\n");
391
 
                printf("Last Modified: %s\n",PROGRAM_MODIFICATION_DATE);
 
391
                printf("Last Modified: %s\n", PROGRAM_MODIFICATION_DATE);
392
392
                printf("License: GPL\n\n");
393
393
                printf("Website: http://www.nagios.org\n");
394
 
                }
 
394
                }
395
395
 
396
396
        /* just display the license */
397
 
        if(display_license==TRUE){
 
397
        if(display_license == TRUE) {
398
398
 
399
399
                printf("This program is free software; you can redistribute it and/or modify\n");
400
400
                printf("it under the terms of the GNU General Public License version 2 as\n");
408
408
                printf("Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n");
409
409
 
410
410
                exit(OK);
411
 
                }
 
411
                }
412
412
 
413
413
        /* make sure we got the main config file on the command line... */
414
 
        if(optind>=argc)
415
 
                error=TRUE;
 
414
        if(optind >= argc)
 
415
                error = TRUE;
416
416
 
417
417
        /* if there are no command line options (or if we encountered an error), print usage */
418
 
        if(error==TRUE || display_help==TRUE){
 
418
        if(error == TRUE || display_help == TRUE) {
419
419
 
420
 
                printf("Usage: %s [options] <main_config_file>\n",argv[0]);
 
420
                printf("Usage: %s [options] <main_config_file>\n", argv[0]);
421
421
                printf("\n");
422
422
                printf("Options:\n");
423
423
                printf("\n");
440
440
 
441
441
 
442
442
        /* config file is last argument specified */
443
 
        config_file=(char *)strdup(argv[optind]);
444
 
        if(config_file==NULL){
 
443
        config_file = (char *)strdup(argv[optind]);
 
444
        if(config_file == NULL) {
445
445
                printf("Error allocating memory.\n");
446
446
                exit(ERROR);
447
 
                }
 
447
                }
448
448
 
449
449
        /* make sure the config file uses an absolute path */
450
 
        if(config_file[0]!='/'){
 
450
        if(config_file[0] != '/') {
451
451
 
452
452
                /* save the name of the config file */
453
 
                buffer=(char *)strdup(config_file);
 
453
                buffer = (char *)strdup(config_file);
454
454
 
455
455
                /* reallocate a larger chunk of memory */
456
 
                config_file=(char *)realloc(config_file,MAX_FILENAME_LENGTH);
457
 
                if(config_file==NULL){
 
456
                config_file = (char *)realloc(config_file, MAX_FILENAME_LENGTH);
 
457
                if(config_file == NULL) {
458
458
                        printf("Error allocating memory.\n");
459
459
                        exit(ERROR);
460
 
                        }
 
460
                        }
461
461
 
462
462
                /* get absolute path of current working directory */
463
 
                getcwd(config_file,MAX_FILENAME_LENGTH);
 
463
                getcwd(config_file, MAX_FILENAME_LENGTH);
464
464
 
465
465
                /* append a forward slash */
466
 
                strncat(config_file,"/",1);
467
 
                config_file[MAX_FILENAME_LENGTH-1]='\x0';
 
466
                strncat(config_file, "/", 1);
 
467
                config_file[MAX_FILENAME_LENGTH - 1] = '\x0';
468
468
 
469
469
                /* append the config file to the path */
470
 
                strncat(config_file,buffer,MAX_FILENAME_LENGTH-strlen(config_file)-1);
471
 
                config_file[MAX_FILENAME_LENGTH-1]='\x0';
 
470
                strncat(config_file, buffer, MAX_FILENAME_LENGTH - strlen(config_file) - 1);
 
471
                config_file[MAX_FILENAME_LENGTH - 1] = '\x0';
472
472
 
473
473
                my_free(buffer);
474
 
                }
 
474
                }
475
475
 
476
476
 
477
477
        /* we're just verifying the configuration... */
478
 
        if(verify_config==TRUE){
 
478
        if(verify_config == TRUE) {
479
479
 
480
480
                /* reset program variables */
481
481
                reset_variables();
483
483
                printf("Reading configuration data...\n");
484
484
 
485
485
                /* read in the configuration files (main config file, resource and object config files) */
486
 
                if((result=read_main_config_file(config_file))==OK){
 
486
                if((result = read_main_config_file(config_file)) == OK) {
487
487
 
488
488
                        printf("   Read main config file okay...\n");
489
489
 
490
490
                        /* drop privileges */
491
 
                        if((result=drop_privileges(nagios_user,nagios_group))==ERROR)
 
491
                        if((result = drop_privileges(nagios_user, nagios_group)) == ERROR)
492
492
                                printf("   Failed to drop privileges.  Aborting.");
493
 
                        else{
 
493
                        else {
494
494
                                /* read object config files */
495
 
                                if((result=read_all_object_data(config_file))==OK)
 
495
                                if((result = read_all_object_data(config_file)) == OK)
496
496
                                        printf("   Read object config files okay...\n");
497
497
                                else
498
498
                                        printf("   Error processing object config files!\n");
499
499
                                }
500
 
                        }
 
500
                        }
501
501
                else
502
502
                        printf("   Error processing main config file!\n\n");
503
503
 
504
504
                printf("\n");
505
505
 
506
506
                /* there was a problem reading the config files */
507
 
                if(result!=OK){
 
507
                if(result != OK) {
508
508
 
509
509
                        /* if the config filename looks fishy, warn the user */
510
 
                        if(!strstr(config_file,"nagios.cfg")){
 
510
                        if(!strstr(config_file, "nagios.cfg")) {
511
511
                                printf("\n***> The name of the main configuration file looks suspicious...\n");
512
512
                                printf("\n");
513
513
                                printf("     Make sure you are specifying the name of the MAIN configuration file on\n");
514
514
                                printf("     the command line and not the name of another configuration file.  The\n");
515
515
                                printf("     main configuration file is typically '/usr/local/nagios/etc/nagios.cfg'\n");
516
 
                                }
 
516
                                }
517
517
 
518
518
                        printf("\n***> One or more problems was encountered while processing the config files...\n");
519
519
                        printf("\n");
523
523
                        printf("     may have been removed or modified in this version.  Make sure to read\n");
524
524
                        printf("     the HTML documentation regarding the config files, as well as the\n");
525
525
                        printf("     'Whats New' section to find out what has changed.\n\n");
526
 
                        }
 
526
                        }
527
527
 
528
528
                /* the config files were okay, so run the pre-flight check */
529
 
                else{
 
529
                else {
530
530
 
531
531
                        printf("Running pre-flight check on configuration data...\n\n");
532
532
 
533
533
                        /* run the pre-flight check to make sure things look okay... */
534
 
                        result=pre_flight_check();
 
534
                        result = pre_flight_check();
535
535
 
536
 
                        if(result==OK)
 
536
                        if(result == OK)
537
537
                                printf("\nThings look okay - No serious problems were detected during the pre-flight check\n");
538
 
                        else{
 
538
                        else {
539
539
                                printf("\n***> One or more problems was encountered while running the pre-flight check...\n");
540
540
                                printf("\n");
541
541
                                printf("     Check your configuration file(s) to ensure that they contain valid\n");
544
544
                                printf("     may have been removed or modified in this version.  Make sure to read\n");
545
545
                                printf("     the HTML documentation regarding the config files, as well as the\n");
546
546
                                printf("     'Whats New' section to find out what has changed.\n\n");
547
 
                                }
548
 
                        }
 
547
                                }
 
548
                        }
549
549
 
550
550
                /* clean up after ourselves */
551
551
                cleanup();
555
555
 
556
556
                /* exit */
557
557
                exit(result);
558
 
                }
 
558
                }
559
559
 
560
560
 
561
561
        /* we're just testing scheduling... */
562
 
        else if(test_scheduling==TRUE){
 
562
        else if(test_scheduling == TRUE) {
563
563
 
564
564
                /* reset program variables */
565
565
                reset_variables();
566
566
 
567
567
                /* read in the configuration files (main config file and all host config files) */
568
 
                result=read_main_config_file(config_file);
 
568
                result = read_main_config_file(config_file);
569
569
 
570
570
                /* drop privileges */
571
 
                if(result==OK)
572
 
                        if((result=drop_privileges(nagios_user,nagios_group))==ERROR)
 
571
                if(result == OK)
 
572
                        if((result = drop_privileges(nagios_user, nagios_group)) == ERROR)
573
573
                                printf("Failed to drop privileges.  Aborting.");
574
574
 
575
575
                /* read object config files */
576
 
                if(result==OK)
577
 
                        result=read_all_object_data(config_file);
 
576
                if(result == OK)
 
577
                        result = read_all_object_data(config_file);
578
578
 
579
579
                /* read initial service and host state information */
580
 
                if(result==OK){
 
580
                if(result == OK) {
581
581
                        initialize_retention_data(config_file);
582
582
                        read_initial_state_information();
583
583
                        }
584
584
 
585
 
                if(result!=OK)
 
585
                if(result != OK)
586
586
                        printf("***> One or more problems was encountered while reading configuration data...\n");
587
587
 
588
588
                /* run the pre-flight check to make sure everything looks okay */
589
 
                if(result==OK){
590
 
                        if((result=pre_flight_check())!=OK)
 
589
                if(result == OK) {
 
590
                        if((result = pre_flight_check()) != OK)
591
591
                                printf("***> One or more problems was encountered while running the pre-flight check...\n");
592
592
                        }
593
593
 
594
 
                if(result==OK){
 
594
                if(result == OK) {
595
595
 
596
596
                        /* initialize the event timing loop */
597
597
                        init_timing_loop();
599
599
                        /* display scheduling information */
600
600
                        display_scheduling_info();
601
601
 
602
 
                        if(precache_objects==TRUE){
 
602
                        if(precache_objects == TRUE) {
603
603
                                printf("\n");
604
604
                                printf("OBJECT PRECACHING\n");
605
605
                                printf("-----------------\n");
606
606
                                printf("Object config files were precached.\n");
607
607
                                }
608
 
                        }
 
608
                        }
609
609
 
610
610
#undef TEST_TIMEPERIODS
611
611
#ifdef TEST_TIMEPERIODS
612
612
                /* DO SOME TIMEPERIOD TESTING - ADDED 08/11/2009 */
613
613
                time_t now, pref_time, valid_time;
614
614
                timeperiod *tp;
615
 
                tp=find_timeperiod("247_exclusion");
 
615
                tp = find_timeperiod("247_exclusion");
616
616
                time(&now);
617
 
                pref_time=now;
618
 
                get_next_valid_time(pref_time,&valid_time,tp);
 
617
                pref_time = now;
 
618
                get_next_valid_time(pref_time, &valid_time, tp);
619
619
                printf("=====\n");
620
 
                printf("CURRENT:   %lu = %s",(unsigned long)now,ctime(&now));
621
 
                printf("PREFERRED: %lu = %s",(unsigned long)pref_time,ctime(&pref_time));
622
 
                printf("NEXT:      %lu = %s",(unsigned long)valid_time,ctime(&valid_time));
 
620
                printf("CURRENT:   %lu = %s", (unsigned long)now, ctime(&now));
 
621
                printf("PREFERRED: %lu = %s", (unsigned long)pref_time, ctime(&pref_time));
 
622
                printf("NEXT:      %lu = %s", (unsigned long)valid_time, ctime(&valid_time));
623
623
                printf("=====\n");
624
624
#endif
625
625
 
628
628
 
629
629
                /* exit */
630
630
                exit(result);
631
 
                }
 
631
                }
632
632
 
633
633
 
634
634
        /* else start to monitor things... */
635
 
        else{
 
635
        else {
636
636
 
637
637
                /* keep monitoring things until we get a shutdown command */
638
 
                do{
 
638
                do {
639
639
 
640
640
                        /* reset program variables */
641
641
                        reset_variables();
642
642
 
643
643
                        /* get PID */
644
 
                        nagios_pid=(int)getpid();
 
644
                        nagios_pid = (int)getpid();
645
645
 
646
646
                        /* read in the configuration files (main and resource config files) */
647
 
                        result=read_main_config_file(config_file);
 
647
                        result = read_main_config_file(config_file);
648
648
 
649
649
                        /* NOTE 11/06/07 EG moved to after we read config files, as user may have overridden timezone offset */
650
650
                        /* get program (re)start time and save as macro */
651
 
                        program_start=time(NULL);
652
 
                        my_free(macro_x[MACRO_PROCESSSTARTTIME]);
653
 
                        asprintf(&macro_x[MACRO_PROCESSSTARTTIME],"%lu",(unsigned long)program_start);
 
651
                        program_start = time(NULL);
 
652
                        my_free(mac->x[MACRO_PROCESSSTARTTIME]);
 
653
                        asprintf(&mac->x[MACRO_PROCESSSTARTTIME], "%lu", (unsigned long)program_start);
654
654
 
655
655
                        /* open debug log */
656
656
                        open_debug_log();
657
657
 
658
658
                        /* drop privileges */
659
 
                        if(drop_privileges(nagios_user,nagios_group)==ERROR){
 
659
                        if(drop_privileges(nagios_user, nagios_group) == ERROR) {
660
660
 
661
 
                                logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR | NSLOG_CONFIG_ERROR,TRUE,"Failed to drop privileges.  Aborting.");
 
661
                                logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR | NSLOG_CONFIG_ERROR, TRUE, "Failed to drop privileges.  Aborting.");
662
662
 
663
663
                                cleanup();
664
664
                                exit(ERROR);
665
 
                                }
 
665
                                }
666
666
 
667
667
#ifdef USE_EVENT_BROKER
668
668
                        /* initialize modules */
671
671
#endif
672
672
 
673
673
                        /* this must be logged after we read config data, as user may have changed location of main log file */
674
 
                        logit(NSLOG_PROCESS_INFO,TRUE,"Nagios %s starting... (PID=%d)\n",PROGRAM_VERSION,(int)getpid());
 
674
                        logit(NSLOG_PROCESS_INFO, TRUE, "Nagios %s starting... (PID=%d)\n", PROGRAM_VERSION, (int)getpid());
675
675
 
676
676
                        /* log the local time - may be different than clock time due to timezone offset */
677
 
                        now=time(NULL);
678
 
                        tm=localtime(&now);
679
 
                        strftime(datestring,sizeof(datestring),"%a %b %d %H:%M:%S %Z %Y",tm);
680
 
                        asprintf(&buffer,"Local time is %s\n",datestring);
681
 
                        write_to_logs_and_console(buffer,NSLOG_PROCESS_INFO,TRUE);
682
 
                        my_free(buffer);
 
677
                        now = time(NULL);
 
678
                        tm = localtime_r(&now, &tm_s);
 
679
                        strftime(datestring, sizeof(datestring), "%a %b %d %H:%M:%S %Z %Y", tm);
 
680
                        logit(NSLOG_PROCESS_INFO, TRUE, "Local time is %s", datestring);
683
681
 
684
682
                        /* write log version/info */
685
683
                        write_log_file_info(NULL);
689
687
                        neb_load_all_modules();
690
688
 
691
689
                        /* send program data to broker */
692
 
                        broker_program_state(NEBTYPE_PROCESS_PRELAUNCH,NEBFLAG_NONE,NEBATTR_NONE,NULL);
 
690
                        broker_program_state(NEBTYPE_PROCESS_PRELAUNCH, NEBFLAG_NONE, NEBATTR_NONE, NULL);
693
691
#endif
694
692
 
695
693
                        /* read in all object config data */
696
 
                        if(result==OK)
697
 
                                result=read_all_object_data(config_file);
 
694
                        if(result == OK)
 
695
                                result = read_all_object_data(config_file);
698
696
 
699
697
                        /* there was a problem reading the config files */
700
 
                        if(result!=OK)
701
 
                                logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR | NSLOG_CONFIG_ERROR,TRUE,"Bailing out due to one or more errors encountered in the configuration files. Run Nagios from the command line with the -v option to verify your config before restarting. (PID=%d)",(int)getpid());
 
698
                        if(result != OK)
 
699
                                logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR | NSLOG_CONFIG_ERROR, TRUE, "Bailing out due to one or more errors encountered in the configuration files. Run Nagios from the command line with the -v option to verify your config before restarting. (PID=%d)", (int)getpid());
702
700
 
703
 
                        else{
 
701
                        else {
704
702
 
705
703
                                /* run the pre-flight check to make sure everything looks okay*/
706
 
                                if((result=pre_flight_check())!=OK)
707
 
                                        logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR | NSLOG_VERIFICATION_ERROR,TRUE,"Bailing out due to errors encountered while running the pre-flight check.  Run Nagios from the command line with the -v option to verify your config before restarting. (PID=%d)\n",(int)getpid());
 
704
                                if((result = pre_flight_check()) != OK)
 
705
                                        logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR | NSLOG_VERIFICATION_ERROR, TRUE, "Bailing out due to errors encountered while running the pre-flight check.  Run Nagios from the command line with the -v option to verify your config before restarting. (PID=%d)\n", (int)getpid());
708
706
                                }
709
707
 
710
708
                        /* an error occurred that prevented us from (re)starting */
711
 
                        if(result!=OK){
712
 
                                
 
709
                        if(result != OK) {
 
710
 
713
711
                                /* if we were restarting, we need to cleanup from the previous run */
714
 
                                if(sigrestart==TRUE){
 
712
                                if(sigrestart == TRUE) {
715
713
 
716
714
                                        /* clean up the status data */
717
 
                                        cleanup_status_data(config_file,TRUE);
 
715
                                        cleanup_status_data(config_file, TRUE);
718
716
 
719
717
                                        /* shutdown the external command worker thread */
720
718
                                        shutdown_command_file_worker_thread();
723
721
                                        close_command_file();
724
722
 
725
723
                                        /* cleanup embedded perl interpreter */
726
 
                                        if(embedded_perl_initialized==TRUE)
 
724
                                        if(embedded_perl_initialized == TRUE)
727
725
                                                deinit_embedded_perl();
728
726
                                        }
729
727
 
730
728
#ifdef USE_EVENT_BROKER
731
729
                                /* send program data to broker */
732
 
                                broker_program_state(NEBTYPE_PROCESS_SHUTDOWN,NEBFLAG_PROCESS_INITIATED,NEBATTR_SHUTDOWN_ABNORMAL,NULL);
 
730
                                broker_program_state(NEBTYPE_PROCESS_SHUTDOWN, NEBFLAG_PROCESS_INITIATED, NEBATTR_SHUTDOWN_ABNORMAL, NULL);
733
731
#endif
734
732
                                cleanup();
735
733
                                exit(ERROR);
740
738
                        /* initialize embedded Perl interpreter */
741
739
                        /* NOTE 02/15/08 embedded Perl must be initialized if compiled in, regardless of whether or not its enabled in the config file */
742
740
                        /* It compiled it, but not initialized, Nagios will segfault in readdir() calls, as libperl takes this function over */
743
 
                        if(embedded_perl_initialized==FALSE){
744
 
/*                              if(enable_embedded_perl==TRUE){*/
 
741
                        if(embedded_perl_initialized == FALSE) {
 
742
                                /*                              if(enable_embedded_perl==TRUE){*/
745
743
#ifdef EMBEDDEDPERL
746
744
                                init_embedded_perl(env);
747
745
#else
748
746
                                init_embedded_perl(NULL);
749
747
#endif
750
 
                                embedded_perl_initialized=TRUE;
751
 
/*                                      }*/
752
 
                                }
 
748
                                embedded_perl_initialized = TRUE;
 
749
                                /*                                      }*/
 
750
                                }
753
751
 
754
 
                        /* handle signals (interrupts) */
 
752
                        /* handle signals (interrupts) */
755
753
                        setup_sighandler();
756
754
 
757
755
 
758
756
#ifdef USE_EVENT_BROKER
759
757
                        /* send program data to broker */
760
 
                        broker_program_state(NEBTYPE_PROCESS_START,NEBFLAG_NONE,NEBATTR_NONE,NULL);
 
758
                        broker_program_state(NEBTYPE_PROCESS_START, NEBFLAG_NONE, NEBATTR_NONE, NULL);
761
759
#endif
762
760
 
763
761
                        /* enter daemon mode (unless we're restarting...) */
764
 
                        if(daemon_mode==TRUE && sigrestart==FALSE){
 
762
                        if(daemon_mode == TRUE && sigrestart == FALSE) {
765
763
 
766
 
                                result=daemon_init();
 
764
                                result = daemon_init();
767
765
 
768
766
                                /* we had an error daemonizing, so bail... */
769
 
                                if(result==ERROR){
770
 
                                        logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR,TRUE,"Bailing out due to failure to daemonize. (PID=%d)",(int)getpid());
 
767
                                if(result == ERROR) {
 
768
                                        logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR, TRUE, "Bailing out due to failure to daemonize. (PID=%d)", (int)getpid());
771
769
 
772
770
#ifdef USE_EVENT_BROKER
773
771
                                        /* send program data to broker */
774
 
                                        broker_program_state(NEBTYPE_PROCESS_SHUTDOWN,NEBFLAG_PROCESS_INITIATED,NEBATTR_SHUTDOWN_ABNORMAL,NULL);
 
772
                                        broker_program_state(NEBTYPE_PROCESS_SHUTDOWN, NEBFLAG_PROCESS_INITIATED, NEBATTR_SHUTDOWN_ABNORMAL, NULL);
775
773
#endif
776
774
                                        cleanup();
777
775
                                        exit(ERROR);
778
776
                                        }
779
777
 
780
 
                                asprintf(&buffer,"Finished daemonizing... (New PID=%d)\n",(int)getpid());
781
 
                                write_to_all_logs(buffer,NSLOG_PROCESS_INFO);
 
778
                                asprintf(&buffer, "Finished daemonizing... (New PID=%d)\n", (int)getpid());
 
779
                                write_to_all_logs(buffer, NSLOG_PROCESS_INFO);
782
780
                                my_free(buffer);
783
781
 
784
782
                                /* get new PID */
785
 
                                nagios_pid=(int)getpid();
786
 
                                }
 
783
                                nagios_pid = (int)getpid();
 
784
                                }
787
785
 
788
786
                        /* open the command file (named pipe) for reading */
789
 
                        result=open_command_file();
790
 
                        if(result!=OK){
 
787
                        result = open_command_file();
 
788
                        if(result != OK) {
791
789
 
792
 
                                logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR,TRUE,"Bailing out due to errors encountered while trying to initialize the external command file... (PID=%d)\n",(int)getpid());
 
790
                                logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR, TRUE, "Bailing out due to errors encountered while trying to initialize the external command file... (PID=%d)\n", (int)getpid());
793
791
 
794
792
#ifdef USE_EVENT_BROKER
795
793
                                /* send program data to broker */
796
 
                                broker_program_state(NEBTYPE_PROCESS_SHUTDOWN,NEBFLAG_PROCESS_INITIATED,NEBATTR_SHUTDOWN_ABNORMAL,NULL);
 
794
                                broker_program_state(NEBTYPE_PROCESS_SHUTDOWN, NEBFLAG_PROCESS_INITIATED, NEBATTR_SHUTDOWN_ABNORMAL, NULL);
797
795
#endif
798
796
                                cleanup();
799
797
                                exit(ERROR);
800
 
                                }
 
798
                                }
801
799
 
802
 
                        /* initialize status data unless we're starting */
803
 
                        if(sigrestart==FALSE)
 
800
                        /* initialize status data unless we're starting */
 
801
                        if(sigrestart == FALSE)
804
802
                                initialize_status_data(config_file);
805
803
 
806
804
                        /* read initial service and host state information  */
809
807
 
810
808
                        /* initialize comment data */
811
809
                        initialize_comment_data(config_file);
812
 
                        
 
810
 
813
811
                        /* initialize scheduled downtime data */
814
812
                        initialize_downtime_data(config_file);
815
 
                        
 
813
 
816
814
                        /* initialize performance data */
817
815
                        initialize_performance_data(config_file);
818
816
 
819
 
                        /* initialize the event timing loop */
 
817
                        /* initialize the event timing loop */
820
818
                        init_timing_loop();
821
 
                        
 
819
 
822
820
                        /* initialize check statistics */
823
821
                        init_check_stats();
824
822
 
825
823
                        /* check for updates */
826
 
                        check_for_nagios_updates(FALSE,TRUE);
 
824
                        check_for_nagios_updates(FALSE, TRUE);
827
825
 
828
826
                        /* update all status data (with retained information) */
829
827
                        update_all_status_data();
830
828
 
831
829
                        /* log initial host and service state */
832
 
                        log_host_states(INITIAL_STATES,NULL);
833
 
                        log_service_states(INITIAL_STATES,NULL);
 
830
                        log_host_states(INITIAL_STATES, NULL);
 
831
                        log_service_states(INITIAL_STATES, NULL);
834
832
 
835
833
                        /* reset the restart flag */
836
 
                        sigrestart=FALSE;
 
834
                        sigrestart = FALSE;
837
835
 
838
836
#ifdef USE_EVENT_BROKER
839
837
                        /* send program data to broker */
840
 
                        broker_program_state(NEBTYPE_PROCESS_EVENTLOOPSTART,NEBFLAG_NONE,NEBATTR_NONE,NULL);
 
838
                        broker_program_state(NEBTYPE_PROCESS_EVENTLOOPSTART, NEBFLAG_NONE, NEBATTR_NONE, NULL);
841
839
#endif
842
840
 
843
841
                        /* get event start time and save as macro */
844
 
                        event_start=time(NULL);
845
 
                        my_free(macro_x[MACRO_EVENTSTARTTIME]);
846
 
                        asprintf(&macro_x[MACRO_EVENTSTARTTIME],"%lu",(unsigned long)event_start);
 
842
                        event_start = time(NULL);
 
843
                        my_free(mac->x[MACRO_EVENTSTARTTIME]);
 
844
                        asprintf(&mac->x[MACRO_EVENTSTARTTIME], "%lu", (unsigned long)event_start);
847
845
 
848
 
                        /***** start monitoring all services *****/
 
846
                        /***** start monitoring all services *****/
849
847
                        /* (doesn't return until a restart or shutdown signal is encountered) */
850
848
                        event_execution_loop();
851
849
 
852
850
                        /* 03/01/2007 EG Moved from sighandler() to prevent FUTEX locking problems under NPTL */
853
851
                        /* 03/21/2007 EG SIGSEGV signals are still logged in sighandler() so we don't loose them */
854
852
                        /* did we catch a signal? */
855
 
                        if(caught_signal==TRUE){
856
 
 
857
 
                                if(sig_id==SIGHUP)
858
 
                                        asprintf(&buffer,"Caught SIGHUP, restarting...\n");
859
 
                                else if(sig_id!=SIGSEGV)
860
 
                                        asprintf(&buffer,"Caught SIG%s, shutting down...\n",sigs[sig_id]);
861
 
 
862
 
                                write_to_all_logs(buffer,NSLOG_PROCESS_INFO);
 
853
                        if(caught_signal == TRUE) {
 
854
 
 
855
                                if(sig_id == SIGHUP)
 
856
                                        asprintf(&buffer, "Caught SIGHUP, restarting...\n");
 
857
                                else if(sig_id != SIGSEGV)
 
858
                                        asprintf(&buffer, "Caught SIG%s, shutting down...\n", sigs[sig_id]);
 
859
 
 
860
                                write_to_all_logs(buffer, NSLOG_PROCESS_INFO);
863
861
                                my_free(buffer);
864
862
                                }
865
863
 
866
864
#ifdef USE_EVENT_BROKER
867
865
                        /* send program data to broker */
868
 
                        broker_program_state(NEBTYPE_PROCESS_EVENTLOOPEND,NEBFLAG_NONE,NEBATTR_NONE,NULL);
869
 
                        if(sigshutdown==TRUE)
870
 
                                broker_program_state(NEBTYPE_PROCESS_SHUTDOWN,NEBFLAG_USER_INITIATED,NEBATTR_SHUTDOWN_NORMAL,NULL);
871
 
                        else if(sigrestart==TRUE)
872
 
                                broker_program_state(NEBTYPE_PROCESS_RESTART,NEBFLAG_USER_INITIATED,NEBATTR_RESTART_NORMAL,NULL);
 
866
                        broker_program_state(NEBTYPE_PROCESS_EVENTLOOPEND, NEBFLAG_NONE, NEBATTR_NONE, NULL);
 
867
                        if(sigshutdown == TRUE)
 
868
                                broker_program_state(NEBTYPE_PROCESS_SHUTDOWN, NEBFLAG_USER_INITIATED, NEBATTR_SHUTDOWN_NORMAL, NULL);
 
869
                        else if(sigrestart == TRUE)
 
870
                                broker_program_state(NEBTYPE_PROCESS_RESTART, NEBFLAG_USER_INITIATED, NEBATTR_RESTART_NORMAL, NULL);
873
871
#endif
874
872
 
875
873
                        /* save service and host state information */
886
884
                        cleanup_comment_data(config_file);
887
885
 
888
886
                        /* clean up the status data unless we're restarting */
889
 
                        if(sigrestart==FALSE)
890
 
                                cleanup_status_data(config_file,TRUE);
 
887
                        if(sigrestart == FALSE)
 
888
                                cleanup_status_data(config_file, TRUE);
891
889
 
892
890
                        /* close and delete the external command file FIFO unless we're restarting */
893
 
                        if(sigrestart==FALSE){
 
891
                        if(sigrestart == FALSE) {
894
892
                                shutdown_command_file_worker_thread();
895
893
                                close_command_file();
896
894
                                }
897
895
 
898
896
                        /* cleanup embedded perl interpreter */
899
 
                        if(sigrestart==FALSE)
 
897
                        if(sigrestart == FALSE)
900
898
                                deinit_embedded_perl();
901
899
 
902
900
                        /* shutdown stuff... */
903
 
                        if(sigshutdown==TRUE){
 
901
                        if(sigshutdown == TRUE) {
904
902
 
905
903
                                /* make sure lock file has been removed - it may not have been if we received a shutdown command */
906
 
                                if(daemon_mode==TRUE)
 
904
                                if(daemon_mode == TRUE)
907
905
                                        unlink(lock_file);
908
906
 
909
907
                                /* log a shutdown message */
910
 
                                logit(NSLOG_PROCESS_INFO,TRUE,"Successfully shutdown... (PID=%d)\n",(int)getpid());
911
 
                                }
 
908
                                logit(NSLOG_PROCESS_INFO, TRUE, "Successfully shutdown... (PID=%d)\n", (int)getpid());
 
909
                                }
912
910
 
913
911
                        /* clean up after ourselves */
914
912
                        cleanup();
916
914
                        /* close debug log */
917
915
                        close_debug_log();
918
916
 
919
 
                        }while(sigrestart==TRUE && sigshutdown==FALSE);
 
917
                        }
 
918
                while(sigrestart == TRUE && sigshutdown == FALSE);
920
919
 
921
920
                /* free misc memory */
922
921
                my_free(config_file);
923
 
                }
 
922
                }
924
923
 
925
924
        return OK;
926
925
        }