Commit Diff


commit - c843d009bb9a70b70200ad8aee1db9bd6b4c67f0d518863045ab7383b34bddb4
commit + d07fd354e4388c7158706ed85589ff7cfa3e53616d21fd6459fb97ec7eba1248
blob - 41cd586c60e454b1b8bda52285db7f57e675e209e60b8daa863a8988d72fc6e6
blob + 3a3221bf76748d5bd7e327ba16e9190137fc6304d1cd5abdab604e8cca7f12eb
--- gotwebd/gotweb.c	
+++ gotwebd/gotweb.c	
@@ -1395,6 +1395,17 @@ gotweb_shutdown(void)
 		imsgbuf_clear(&gotwebd_env->iev_server->ibuf);
 		free(gotwebd_env->iev_server);
 	}
+
+	sockets_purge(gotwebd_env);
+
+	while (!TAILQ_EMPTY(&gotwebd_env->servers)) {
+		struct server *srv;
+
+		srv = TAILQ_FIRST(&gotwebd_env->servers);
+		TAILQ_REMOVE(&gotwebd_env->servers, srv, entry);
+		free(srv);
+	}
+
 	free(gotwebd_env);
 
 	exit(0);
blob - 94883bd0cab664a6bc578751524545a3f8432a301e5e0b522f9d2bd8ee9c50d3
blob + 4da3d3448be7594ac82d61255bcbff248c15a2b9e57e87221e8c6edb53975055
--- gotwebd/gotwebd.c	
+++ gotwebd/gotwebd.c	
@@ -51,7 +51,7 @@ int	 main(int, char **);
 int	 gotwebd_configure(struct gotwebd *, uid_t, gid_t);
 void	 gotwebd_configure_done(struct gotwebd *);
 void	 gotwebd_sighdlr(int sig, short event, void *arg);
-void	 gotwebd_shutdown(void);
+void	 gotwebd_shutdown(int);
 void	 gotwebd_dispatch_server(int, short, void *);
 void	 gotwebd_dispatch_gotweb(int, short, void *);
 
@@ -271,7 +271,7 @@ gotwebd_sighdlr(int sig, short event, void *arg)
 		break;
 	case SIGTERM:
 	case SIGINT:
-		gotwebd_shutdown();
+		gotwebd_shutdown(0);
 		break;
 	default:
 		log_warn("unexpected signal %d", sig);
@@ -419,11 +419,11 @@ main(int argc, char **argv)
 
 	if (proc_type == GOTWEBD_PROC_PARENT) {
 		if (parse_config(env->gotwebd_conffile, env) == -1)
-			exit(1);
+			gotwebd_shutdown(1);
 
 		if (no_action) {
 			fprintf(stderr, "configuration OK\n");
-			exit(0);
+			gotwebd_shutdown(0);
 		}
 
 		if (env->user)
@@ -549,6 +549,7 @@ main(int argc, char **argv)
 
 	log_debug("%s gotwebd exiting", getprogname());
 
+	gotwebd_shutdown(0);
 	return (0);
 }
 
@@ -637,7 +638,7 @@ gotwebd_configure_done(struct gotwebd *env)
 }
 
 void
-gotwebd_shutdown(void)
+gotwebd_shutdown(int exit_code)
 {
 	struct gotwebd	*env = gotwebd_env;
 	pid_t		 pid;
@@ -690,5 +691,5 @@ gotwebd_shutdown(void)
 	free(gotwebd_env);
 
 	log_warnx("gotwebd terminating");
-	exit(0);
+	exit(exit_code);
 }