git » chasquid » commit 17eff21

Only fail if there is no address to listen on at all, regardless of mode

author Alberto Bertogli
2017-04-11 22:34:55 UTC
committer Alberto Bertogli
2017-04-12 09:32:41 UTC
parent 7f5bedf4aa7f678f11e4547941cdbc6b846c8b87

Only fail if there is no address to listen on at all, regardless of mode

Currently, chasquid exits if any mode (SMTP/submission/submission+tls)
has no addresses to listen on. This means that chasquid must be given
addresses for all three.

While that's generally the expected configuration, there are cases where
users may not want to have all three.

So this patch replaces that fatal error with a warning, and only makes
chasquid exit if there are no addresses to listen on at all.

chasquid.go +14 -11
test/t-06-idna/A/chasquid.conf +0 -1
test/t-06-idna/B/chasquid.conf +0 -1
test/t-07-smtputf8/config/chasquid.conf +0 -1
test/t-10-hooks/config/chasquid.conf +0 -1

diff --git a/chasquid.go b/chasquid.go
index 9b073a2..2bcf803 100644
--- a/chasquid.go
+++ b/chasquid.go
@@ -149,35 +149,38 @@ func main() {
 		log.Fatalf("Error getting systemd listeners: %v", err)
 	}
 
-	loadAddresses(s, conf.SmtpAddress,
+	naddr := loadAddresses(s, conf.SmtpAddress,
 		systemdLs["smtp"], smtpsrv.ModeSMTP)
-	loadAddresses(s, conf.SubmissionAddress,
+	naddr += loadAddresses(s, conf.SubmissionAddress,
 		systemdLs["submission"], smtpsrv.ModeSubmission)
-	loadAddresses(s, conf.SubmissionOverTlsAddress,
+	naddr += loadAddresses(s, conf.SubmissionOverTlsAddress,
 		systemdLs["submission_tls"], smtpsrv.ModeSubmissionTLS)
 
+	if naddr == 0 {
+		log.Fatalf("No address to listen on")
+	}
+
 	s.ListenAndServe()
 }
 
-func loadAddresses(srv *smtpsrv.Server, addrs []string, ls []net.Listener, mode smtpsrv.SocketMode) {
-	// Load addresses.
-	acount := 0
+func loadAddresses(srv *smtpsrv.Server, addrs []string, ls []net.Listener, mode smtpsrv.SocketMode) int {
+	naddr := 0
 	for _, addr := range addrs {
 		// The "systemd" address indicates we get listeners via systemd.
 		if addr == "systemd" {
 			srv.AddListeners(ls, mode)
-			acount += len(ls)
+			naddr += len(ls)
 		} else {
 			srv.AddAddr(addr, mode)
-			acount++
+			naddr++
 		}
 	}
 
-	if acount == 0 {
-		log.Errorf("No %v addresses/listeners", mode)
+	if naddr == 0 {
+		log.Errorf("Warning: No %v addresses/listeners", mode)
 		log.Errorf("If using systemd, check that you named the sockets")
-		log.Fatalf("Exiting")
 	}
+	return naddr
 }
 
 func initMailLog(path string) {
diff --git a/test/t-06-idna/A/chasquid.conf b/test/t-06-idna/A/chasquid.conf
index 5b54c64..6f0db35 100644
--- a/test/t-06-idna/A/chasquid.conf
+++ b/test/t-06-idna/A/chasquid.conf
@@ -1,6 +1,5 @@
 smtp_address: ":1025"
 submission_address: ":1587"
-submission_over_tls_address: ":1465"
 monitoring_address: ":1099"
 
 mail_delivery_agent_bin: "test-mda"
diff --git a/test/t-06-idna/B/chasquid.conf b/test/t-06-idna/B/chasquid.conf
index e572536..ef7a0da 100644
--- a/test/t-06-idna/B/chasquid.conf
+++ b/test/t-06-idna/B/chasquid.conf
@@ -1,6 +1,5 @@
 smtp_address: ":2025"
 submission_address: ":2587"
-submission_over_tls_address: ":2465"
 monitoring_address: ":2099"
 
 mail_delivery_agent_bin: "test-mda"
diff --git a/test/t-07-smtputf8/config/chasquid.conf b/test/t-07-smtputf8/config/chasquid.conf
index cf76e8a..2da8942 100644
--- a/test/t-07-smtputf8/config/chasquid.conf
+++ b/test/t-07-smtputf8/config/chasquid.conf
@@ -1,6 +1,5 @@
 smtp_address: ":1025"
 submission_address: ":1587"
-submission_over_tls_address: ":1465"
 monitoring_address: ":1099"
 
 mail_delivery_agent_bin: "test-mda"
diff --git a/test/t-10-hooks/config/chasquid.conf b/test/t-10-hooks/config/chasquid.conf
index cf76e8a..2da8942 100644
--- a/test/t-10-hooks/config/chasquid.conf
+++ b/test/t-10-hooks/config/chasquid.conf
@@ -1,6 +1,5 @@
 smtp_address: ":1025"
 submission_address: ":1587"
-submission_over_tls_address: ":1465"
 monitoring_address: ":1099"
 
 mail_delivery_agent_bin: "test-mda"