00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <stdio.h>
00023
00024 #ifdef HAVE_SYS_TYPES_H
00025 #include <sys/types.h>
00026 #endif
00027
00028 #include <sys/socket.h>
00029 #include <errno.h>
00030 #include <stdlib.h>
00031
00032 #ifdef HAVE_STRING_H
00033 #include <string.h>
00034 #endif
00035
00036 #ifdef HAVE_UNISTD_H
00037 #include <unistd.h>
00038 #endif
00039
00040 #ifdef HAVE_SYS_WAIT_H
00041 #include <sys/wait.h>
00042 #endif
00043
00044 #include "monitor.h"
00045 #include "net.h"
00046 #include "engine.h"
00047
00048
00049 static void *thread_wrapper(void *arg);
00050
00051
00052 static pthread_t thread;
00053
00054
00067
00068
00069
00073 int check_httpd() {
00074
00075 return check_connect(Run.bind_addr?Run.bind_addr:"localhost",
00076 Run.httpdport, SOCK_STREAM);
00077
00078 }
00079
00080
00086 int can_http() {
00087
00088 if ( Run.dohttpd && Run.isdaemon ) {
00089
00090 if(! has_hosts_allow() && ! Run.Auth.defined) {
00091
00092 log("%s: monit httpd not started since no connect allowed\n",
00093 prog);
00094
00095 return FALSE;
00096
00097 }
00098
00099 return TRUE;
00100
00101 }
00102
00103 return FALSE;
00104
00105 }
00106
00107
00112 void monit_http(int action) {
00113
00114 int status;
00115
00116 switch ( action ) {
00117
00118 case STOP_HTTP: {
00119
00120 log("Stopping %s HTTP server\n", prog);
00121 stop_httpd();
00122
00123 }
00124
00125 return;
00126 case START_HTTP:
00127 break;
00128
00129 }
00130
00131 status= pthread_create(&thread, NULL, thread_wrapper, NULL);
00132
00133 if ( status != 0 ) {
00134
00135 log("%s: Failed to create the http server. Thread error -- %s.\n",
00136 prog, strerror(status));
00137
00138 }
00139
00140 }
00141
00142
00143
00144
00145
00146 static void *thread_wrapper(void *arg) {
00147
00148 sigset_t ns;
00149
00150 pthread_detach(pthread_self());
00151
00152
00153 sigemptyset(&ns);
00154 sigaddset(&ns, SIGUSR1);
00155 pthread_sigmask(SIG_BLOCK, &ns, NULL);
00156
00157 start_httpd(Run.httpdport, 10, Run.bind_addr);
00158
00159 return NULL;
00160
00161 }
00162
00163