changeset 5351:00a3204a58af draft

privsep: Fix a shutdown race Only test a successful stop IPC command. By the time we shutdown the socket to be extra nice, the process we sent stop to could have already exited, therefore we can discard any error.
author Roy Marples <roy@marples.name>
date Wed, 10 Jun 2020 16:32:04 +0100
parents f97d9554afb4
children 599c75a0ac56
files src/privsep-root.c src/privsep.c
diffstat 2 files changed, 3 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/privsep-root.c	Wed Jun 10 14:47:00 2020 +0100
+++ b/src/privsep-root.c	Wed Jun 10 16:32:04 2020 +0100
@@ -480,7 +480,6 @@
 			shutdown(psp->psp_fd, SHUT_RDWR);
 			close(psp->psp_fd);
 			psp->psp_fd = -1;
-			ps_dostop(ctx, &psp->psp_pid, &psp->psp_fd);
 			ps_freeprocess(psp);
 		}
 		return 0;
--- a/src/privsep.c	Wed Jun 10 14:47:00 2020 +0100
+++ b/src/privsep.c	Wed Jun 10 16:32:04 2020 +0100
@@ -401,17 +401,16 @@
 	int err = 0;
 
 #ifdef PRIVSEP_DEBUG
-	logdebugx("%s: pid %d fd %d", __func__, *pid, *fd);
+	logdebugx("%s: pid=%d fd=%d", __func__, *pid, *fd);
 #endif
 
 	if (*fd != -1) {
 		eloop_event_delete(ctx->eloop, *fd);
-		if (ps_sendcmd(ctx, *fd, PS_STOP, 0, NULL, 0) == -1 ||
-		    shutdown(*fd, SHUT_RDWR) == -1)
-		{
+		if (ps_sendcmd(ctx, *fd, PS_STOP, 0, NULL, 0) == -1) {
 			logerr(__func__);
 			err = -1;
 		}
+		(void)shutdown(*fd, SHUT_RDWR);
 		close(*fd);
 		*fd = -1;
 	}