43 |
|
|
44 |
#include "monitor.h" |
#include "monitor.h" |
45 |
#include "net.h" |
#include "net.h" |
46 |
|
#include "socket.h" |
47 |
|
|
48 |
|
|
49 |
/** |
/** |
60 |
/* ------------------------------------------------------- Private variables */ |
/* ------------------------------------------------------- Private variables */ |
61 |
|
|
62 |
|
|
63 |
|
static Socket_T S; |
64 |
static char *server; |
static char *server; |
65 |
static int mysocket; |
static sigjmp_buf timeout; |
|
static sigjmp_buf die; |
|
66 |
|
|
67 |
|
|
68 |
/* -------------------------------------------------------------- Prototypes */ |
/* -------------------------------------------------------------- Prototypes */ |
94 |
|
|
95 |
} |
} |
96 |
|
|
97 |
if(sigsetjmp(die, TRUE)) { |
if(sigsetjmp(timeout, TRUE)) { |
98 |
|
|
99 |
goto exit; |
goto exit; |
100 |
|
|
147 |
static int initialize_server() { |
static int initialize_server() { |
148 |
|
|
149 |
struct sigaction sa; |
struct sigaction sa; |
150 |
|
|
151 |
|
S= NULL; |
152 |
|
server= Run.mailserver?Run.mailserver:LOCALHOST; |
153 |
|
|
|
if((server= Run.mailserver) == NULL) { |
|
|
|
|
|
server= LOCALHOST; |
|
|
|
|
|
} |
|
|
|
|
|
sa.sa_handler= do_timeout; |
|
154 |
sa.sa_flags= 0; |
sa.sa_flags= 0; |
155 |
sigemptyset(&sa.sa_mask); |
sigemptyset(&sa.sa_mask); |
156 |
|
sa.sa_handler= do_timeout; |
157 |
sigaction(SIGALRM, &sa, NULL); |
sigaction(SIGALRM, &sa, NULL); |
158 |
alarm(SMTP_TIMEOUT); |
alarm(10000); |
159 |
|
//FIXME alarm(SMTP_TIMEOUT); |
|
if((mysocket= create_socket(server, SMTP_PORT, SOCK_STREAM)) <0) { |
|
160 |
|
|
161 |
|
S= socket_new(server, SMTP_PORT, SOCK_STREAM, FALSE); |
162 |
|
if(!S) { |
163 |
log("Cannot open a connection to the mailserver '%s' -- %s\n", |
log("Cannot open a connection to the mailserver '%s' -- %s\n", |
164 |
server, STRERROR); |
server, STRERROR); |
|
|
|
165 |
return FALSE; |
return FALSE; |
|
|
|
166 |
} |
} |
167 |
|
|
168 |
return TRUE; |
return TRUE; |
174 |
|
|
175 |
alarm(0); |
alarm(0); |
176 |
|
|
177 |
if(mysocket && !close_socket(mysocket)) { |
if(S) { |
178 |
|
socket_free(&S); |
|
log("Error shutting down socket connection to mailserver %s -- %s\n", |
|
|
server, STRERROR); |
|
|
|
|
179 |
} |
} |
180 |
|
|
181 |
} |
} |
184 |
static void do_timeout(int sig) { |
static void do_timeout(int sig) { |
185 |
|
|
186 |
log("Sendmail: Connection to mailserver timed out\n"); |
log("Sendmail: Connection to mailserver timed out\n"); |
187 |
siglongjmp(die, TRUE); |
siglongjmp(timeout, TRUE); |
188 |
|
|
189 |
} |
} |
190 |
|
|
198 |
vsnprintf(msg, 2048, format, ap); |
vsnprintf(msg, 2048, format, ap); |
199 |
va_end(ap); |
va_end(ap); |
200 |
|
|
201 |
if(sock_send(mysocket, msg, strlen(msg), 0) <= 0) { |
if(socket_write(S, msg, strlen(msg)) <= 0) { |
202 |
|
|
203 |
log("Sendmail: error sending data to the server '%s' -- %s\n", |
log("Sendmail: error sending data to the server '%s' -- %s\n", |
204 |
server, STRERROR); |
server, STRERROR); |
205 |
siglongjmp(die, TRUE); |
siglongjmp(timeout, TRUE); |
206 |
|
|
207 |
} |
} |
208 |
|
|
214 |
int status; |
int status; |
215 |
char buf[STRLEN]; |
char buf[STRLEN]; |
216 |
|
|
217 |
if(sock_recv(mysocket, buf, sizeof(buf), 0) <= 0) { |
if(socket_read(S, buf, sizeof(buf)) <= 0) { |
218 |
|
|
219 |
log("Sendmail: error receiving data from the mailserver '%s' -- %s\n", |
log("Sendmail: error receiving data from the mailserver '%s' -- %s\n", |
220 |
server, STRERROR); |
server, STRERROR); |
221 |
siglongjmp(die, TRUE); |
siglongjmp(timeout, TRUE); |
222 |
|
|
223 |
} |
} |
224 |
|
|
228 |
if(status >= 400) { |
if(status >= 400) { |
229 |
|
|
230 |
log("Sendmail error: %s\n", buf); |
log("Sendmail error: %s\n", buf); |
231 |
siglongjmp(die, TRUE); |
siglongjmp(timeout, TRUE); |
232 |
|
|
233 |
} |
} |
234 |
|
|