--- lmtp2nntp.c 2001/09/12 08:18:19 1.54
+++ lmtp2nntp.c 2001/09/12 09:58:22 1.55
@@ -32,6 +32,7 @@
#include <fcntl.h>
#include <sys/utsname.h>
#include <sys/time.h>
+#include <signal.h>
/* third party */
#include "str.h"
@@ -104,6 +105,7 @@
char *lhlo_domain;
};
+static void catchsignal(int sig, ...);
static int connect_nonb(int, const struct sockaddr *, socklen_t, int);
static void initsession(struct session *session);
static void resetsession(struct session *session);
@@ -260,6 +262,30 @@
return L2_OK;
}
+static void catchsignal(int sig, ...)
+{
+ va_list ap;
+ static lmtp2nntp_t *ctx = NULL;
+
+ va_start(ap, sig);
+ if(sig == 0) {
+ if ((ctx = va_arg(ap, lmtp2nntp_t *)) == NULL)
+ exit(ERR_EXECUTION);
+ log0(ctx, TRACE, "catching and logging signals now");
+ va_end(ap);
+ return;
+ }
+ if (ctx != NULL) {
+ if ((sig == SIGHUP) || (sig == SIGINT) || (sig == SIGQUIT))
+ log1(ctx, NOTICE, "caught signal %d - exit - no more logging", sig);
+ else
+ log1(ctx, PANIC, "CAUGHT SIGNAL %d - EXIT - NO MORE LOGGING", sig);
+ l2_stream_destroy(ctx->l2);
+ }
+ va_end(ap);
+ exit(ERR_EXECUTION);
+}
+
int main(int argc, char **argv)
{
lmtp_t *lmtp;
@@ -573,7 +599,7 @@
fprintf(stderr, "%s:Error: logging failed to create buffer channel\n", ctx->progname);
exit(ERR_EXECUTION);
}
- if (l2_channel_configure(chBuf, "size", 65536) != L2_OK) { //FIXME
+ if (l2_channel_configure(chBuf, "size", 65536) != L2_OK) {
fprintf(stderr, "%s:Error: logging failed to configure buffer channel\n", ctx->progname);
exit(ERR_EXECUTION);
}
@@ -612,6 +638,19 @@
exit(ERR_EXECUTION);
}
+ catchsignal(0, ctx);
+ signal(SIGHUP, (void(*)())catchsignal);
+ signal(SIGINT, (void(*)())catchsignal);
+ signal(SIGQUIT, (void(*)())catchsignal);
+ signal(SIGILL, (void(*)())catchsignal);
+ signal(SIGBUS, (void(*)())catchsignal);
+ signal(SIGSEGV, (void(*)())catchsignal);
+ signal(SIGSYS, (void(*)())catchsignal);
+ signal(SIGTERM, (void(*)())catchsignal);
+ signal(SIGINFO, SIG_IGN );
+ signal(SIGUSR1, SIG_IGN );
+ signal(SIGUSR2, SIG_IGN );
+
/* initialize LMTP context */
lmtp_io.ctx = ctx;
lmtp_io.select = NULL;
|