Subject: misc/893: mount_portal trashes /tmp if killed
To: None <gnats-admin@NetBSD.ORG>
From: Kenneth Stailey <kstailey@leidecker.gsfc.nasa.gov>
List: netbsd-bugs
Date: 03/22/1995 06:05:05
>Number:         893
>Category:       misc
>Synopsis:       mount_portal trashes /tmp if killed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 22 06:05:03 1995
>Originator:     Kenneth Stailey
>Organization:
self
>Release:        March 18th tarballs
>Environment:
System: NetBSD pluto 1.0A NetBSD 1.0A (PLUTO) #19: Sat Mar 18 16:46:13 EST 1995 ken@pluto:/usr/src/sys/arch/i386/compile/PLUTO i386


>Description:
	/sbin/mount_portal creates an unreferenced AF_LOCAL socket
	when run.  It does not clean this up if killed.  It does
	clean it up if you run 'umount' instead of kill on it.
>How-To-Repeat:
	1) make sure portal is not running
	2) make sure that the directory "/p" exists.
	   my /p looks like this:

drwxr-xr-x  2 root  wheel  512 Dec 24 15:49 /p

	3) Make sure that /etc/portal.conf exists and looks like this:

# from: Id: portal.conf,v 1.1 1992/05/27 06:50:13 jsp Exp
# from: @(#)portal.conf 8.1 (Berkeley) 6/5/93
# $Id: portal.conf,v 1.2 1994/06/08 19:24:50 mycroft Exp $
tcplisten/      tcplisten tcplisten/
tcp/            tcp tcp/
fs/             file fs/
pipe/           pipe

	3) Run fsck on /tmp (or root if you have no seperate /tmp)
	   to show that it's clean (if it's not you cannot proceed)
	4) Run "/sbin/mount_portal /etc/portal.conf /p"
	5) Run fsck on your /tmp (or root if you have no seperate /tmp).
	   You should see an unreferenced socket.
	6) If you kill mount_portal this will not be cleaned up by
	   anything but fsck.  If you "umount /p" it will be cleaned up.

>Fix:
	I added a sigterm handler to mount_portal to make it unmount
	itself when killed.

--- mount_portal.c.DIST	Wed Mar 22 06:58:49 1995
+++ mount_portal.c	Wed Mar 22 07:52:20 1995
@@ -69,6 +69,8 @@
 	{ NULL }
 };
 
+static char *mountpt;		/* made available to signal handler */
+
 static void usage __P((void));
 
 static sig_atomic_t readcf;	/* Set when SIGHUP received */
@@ -84,6 +86,14 @@
 		syslog(LOG_WARNING, "waitpid: %s", strerror(errno));
 }
 
+static void sigterm(sig)
+int sig;
+{
+	if (unmount(mountpt, MNT_FORCE) < 0)
+		syslog(LOG_WARNING, "sigterm: unmounting %s failed: %s",
+		       mountpt, strerror(errno));
+}
+
 int
 main(argc, argv)
 	int argc;
@@ -92,7 +102,6 @@
 	struct portal_args args;
 	struct sockaddr_un un;
 	char *conf;
-	char *mountpt;
 	int mntflags = 0;
 	char tag[32];
 
@@ -154,7 +163,7 @@
 	(void) listen(so, 5);
 
 	args.pa_socket = so;
-	sprintf(tag, "portal:%d", getpid());
+	sprintf(tag, "portal:%d", getpid() + 1);
 	args.pa_config = tag;
 
 	rc = mount(MOUNT_PORTAL, mountpt, mntflags, &args);
@@ -175,6 +184,7 @@
 	readcf = 1;
 
 	signal(SIGCHLD, sigchld);
+	signal(SIGTERM, sigterm);
 
 	/*
 	 * Just loop waiting for new connections and activating them

--HAA00579.795876875/pluto.spacenet.com--


>Audit-Trail:
>Unformatted: