From 6775c971eedab4c61a95c9580a5fafcbff67566c Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 7 Sep 2005 22:28:51 +0000 Subject: - Fix problems with not listening properly when in daemon mode --- ChangeLog | 1 + common/smtppass.c | 58 ++++++++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3718ce0..43f6cb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.5.1 [???] - Support embedded NULLs in email data. + - Fix problems with not listening properly when in daemon mode 1.5 [2005-07-31] - Handle condition of server refusing data transfers more gracefully. diff --git a/common/smtppass.c b/common/smtppass.c index e94f95e..6a16db5 100644 --- a/common/smtppass.c +++ b/common/smtppass.c @@ -277,28 +277,6 @@ int sp_run(const char* configfile, const char* pidfile, int dbg_level) sp_messagex(NULL, LOG_DEBUG, "starting up (%s)...", VERSION); - /* Create the socket */ - sock = socket(SANY_TYPE(g_state.listenaddr), SOCK_STREAM, 0); - if(sock < 0) - err(1, "couldn't open socket"); - - fcntl(sock, F_SETFD, fcntl(sock, F_GETFD, 0) | FD_CLOEXEC); - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&true, sizeof(true)); - - /* Unlink the socket file if it exists */ - if(SANY_TYPE(g_state.listenaddr) == AF_UNIX) - unlink(g_state.listenname); - - if(bind(sock, &SANY_ADDR(g_state.listenaddr), SANY_LEN(g_state.listenaddr)) != 0) - err(1, "couldn't bind to address: %s", g_state.listenname); - - /* Let 5 connections queue up */ - if(listen(sock, 5) != 0) - { - sp_message(NULL, LOG_CRIT, "couldn't listen on socket"); - exit(1); - } - /* Drop privileges before daemonizing */ drop_privileges(); @@ -319,17 +297,45 @@ int sp_run(const char* configfile, const char* pidfile, int dbg_level) openlog(g_state.name, 0, LOG_MAIL); } - sp_messagex(NULL, LOG_DEBUG, "created socket: %s", g_state.listenname); - /* Handle some signals */ signal(SIGPIPE, SIG_IGN); - signal(SIGHUP, SIG_IGN); - signal(SIGINT, on_quit); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, on_quit); signal(SIGTERM, on_quit); siginterrupt(SIGINT, 1); siginterrupt(SIGTERM, 1); + /* Create the socket */ + sock = socket(SANY_TYPE(g_state.listenaddr), SOCK_STREAM, 0); + if(sock < 0) + { + sp_message(NULL, LOG_CRIT, "couldn't open socket"); + exit(1); + } + + fcntl(sock, F_SETFD, fcntl(sock, F_GETFD, 0) | FD_CLOEXEC); + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&true, sizeof(true)); + + /* Unlink the socket file if it exists */ + if(SANY_TYPE(g_state.listenaddr) == AF_UNIX) + unlink(g_state.listenname); + + if(bind(sock, &SANY_ADDR(g_state.listenaddr), SANY_LEN(g_state.listenaddr)) != 0) + { + sp_message(NULL, LOG_CRIT, "couldn't bind to address: %s", g_state.listenname); + exit(1); + } + + sp_messagex(NULL, LOG_DEBUG, "created socket: %s", g_state.listenname); + + /* Let 5 connections queue up */ + if(listen(sock, 5) != 0) + { + sp_message(NULL, LOG_CRIT, "couldn't listen on socket"); + exit(1); + } + pid_file(1); sp_messagex(NULL, LOG_DEBUG, "accepting connections"); -- cgit v1.2.3