/[monit]/monit/sendmail.c
ViewVC logotype

Diff of /monit/sendmail.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by hauk, Sat Jul 26 00:22:55 2003 UTC revision 1.18 by hauk, Wed Jul 30 01:27:15 2003 UTC
# Line 27  Line 27 
27  #endif  #endif
28    
29  #include <sys/socket.h>  #include <sys/socket.h>
 #include <signal.h>  
30  #include <stdarg.h>  #include <stdarg.h>
31  #include <errno.h>  #include <errno.h>
32  #include <setjmp.h>  #include <setjmp.h>
# Line 62  Line 61 
61    
62  static Socket_T S;  static Socket_T S;
63  static char *server;  static char *server;
64  static int did_timeout;  static sigjmp_buf error;
 static sigjmp_buf timeout;  
65    
66    
67  /* -------------------------------------------------------------- Prototypes */  /* -------------------------------------------------------------- Prototypes */
68    
69    
70  static void do_status();  static void do_status();
 static void do_timeout(int);  
71  static void finalize_server();  static void finalize_server();
72  static int  initialize_server();  static int  initialize_server();
73  static void do_send(const char *, ...);  static void do_send(const char *, ...);
# Line 95  void sendmail(Mail_T mail) { Line 92  void sendmail(Mail_T mail) {
92      goto exit;      goto exit;
93    }    }
94        
95    if(sigsetjmp(timeout, TRUE)) {    if(sigsetjmp(error, TRUE)) {
96      goto exit;      goto exit;
97    }    }
98    
# Line 126  void sendmail(Mail_T mail) { Line 123  void sendmail(Mail_T mail) {
123      }      }
124      do_send(".\r\n");      do_send(".\r\n");
125      do_status();      do_status();
126        
     alarm(SMTP_TIMEOUT);  
   
127    }    }
128    
129    do_send("QUIT\r\n");    do_send("QUIT\r\n");
# Line 136  void sendmail(Mail_T mail) { Line 131  void sendmail(Mail_T mail) {
131    exit:    exit:
132    free(now);    free(now);
133    free(localhost);    free(localhost);
   if(did_timeout) {  
     log("Sendmail: Connection to mailserver timed out\n");  
   }  
134    finalize_server();    finalize_server();
135        
136  }  }
# Line 149  void sendmail(Mail_T mail) { Line 141  void sendmail(Mail_T mail) {
141    
142  static int initialize_server() {  static int initialize_server() {
143        
   struct sigaction sa;  
   
144    S= NULL;    S= NULL;
   did_timeout= FALSE;  
145    server= Run.mailserver?Run.mailserver:LOCALHOST;    server= Run.mailserver?Run.mailserver:LOCALHOST;
146        
   sa.sa_flags= 0;  
   sigemptyset(&sa.sa_mask);  
   sa.sa_handler= do_timeout;  
   sigaction(SIGALRM, &sa, NULL);  
   alarm(SMTP_TIMEOUT);  
   
147    S= socket_new(server, SMTP_PORT, SOCKET_TCP, FALSE);    S= socket_new(server, SMTP_PORT, SOCKET_TCP, FALSE);
148    if(!S) {    if(!S) {
149      log("Cannot open a connection to the mailserver '%s' -- %s\n",      log("Cannot open a connection to the mailserver '%s' -- %s\n",
# Line 175  static int initialize_server() { Line 158  static int initialize_server() {
158    
159  static void finalize_server() {  static void finalize_server() {
160        
   alarm(0);  
     
161    if(S) {    if(S) {
162      socket_free(&S);      socket_free(&S);
163    }    }
# Line 184  static void finalize_server() { Line 165  static void finalize_server() {
165  }  }
166    
167    
 static void do_timeout(int sig) {  
   
   did_timeout= TRUE;  
   siglongjmp(timeout, TRUE);  
     
 }  
   
   
168  void do_send(const char *format, ...) {  void do_send(const char *format, ...) {
169        
170    va_list ap;    va_list ap;
# Line 205  void do_send(const char *format, ...) { Line 178  void do_send(const char *format, ...) {
178            
179      log("Sendmail: error sending data to the server '%s' -- %s\n",      log("Sendmail: error sending data to the server '%s' -- %s\n",
180            server, STRERROR);            server, STRERROR);
181      siglongjmp(timeout, TRUE);      siglongjmp(error, TRUE);
182            
183    }    }
184        
# Line 221  static void do_status() { Line 194  static void do_status() {
194            
195      log("Sendmail: error receiving data from the mailserver '%s' -- %s\n",      log("Sendmail: error receiving data from the mailserver '%s' -- %s\n",
196          server, STRERROR);          server, STRERROR);
197      siglongjmp(timeout, TRUE);      siglongjmp(error, TRUE);
198            
199    }    }
200        
# Line 231  static void do_status() { Line 204  static void do_status() {
204    if(status >= 400) {    if(status >= 400) {
205            
206      log("Sendmail error: %s\n", buf);      log("Sendmail error: %s\n", buf);
207      siglongjmp(timeout, TRUE);      siglongjmp(error, TRUE);
208            
209    }    }
210        

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26