Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Feb 2000 02:21:49 -0800
From:      Alfred Perlstein <bright@wintelcom.net>
To:        current@freebsd.org
Subject:   "Fixing" init.
Message-ID:  <20000219022149.N21720@fw.wintelcom.net>

next in thread | raw e-mail | index | archive | help
I remeber being a newbie and getting burned by the need to explicitly
turn a line 'off' in my /etc/ttys file instead of simply deleting it.

This fixes it using a trivial mark then collect sweep.

Can a couple people take a look?  I'd like to get it into 4.0 because
it seems to follow POLA better. 

"hey i deleted and HUP'd but init keeps spawing them!"

thanks,
-Alfred

Index: init.c
===================================================================
RCS file: /home/ncvs/src/sbin/init/init.c,v
retrieving revision 1.37
diff -u -u -r1.37 init.c
--- init.c	1999/11/22 04:23:09	1.37
+++ init.c	2000/02/19 13:53:52
@@ -156,6 +156,7 @@
 	char    *se_window_argv_space;  /* pre-parsed argument array space */
 	char	**se_window_argv;	/* pre-parsed argument array */
 	char    *se_type;               /* default terminal type */
+	int     se_collect;		/* flag for garbage collection */
 	struct	init_session *se_prev;
 	struct	init_session *se_next;
 } session_t;
@@ -1330,7 +1331,7 @@
 }
 
 /*
- * This is an n-squared algorithm.  We hope it isn't run often...
+ * This is an (n*2)+(n^2) algorithm.  We hope it isn't run often...
  */
 state_func_t
 clean_ttys()
@@ -1344,6 +1345,14 @@
 	if (! sessions)
 		return (state_func_t) multi_user;
 
+	/* 
+	 * mark all sessions for death, 
+	 * as we find or create new ones they'll be marked as keepers,
+	 * nuke all the ones not found in /etc/ttys
+	 */
+	for (sp = sessions; sp != NULL; sp = sp->se_next)
+		sp->se_collect = 1;
+
 	devlen = sizeof(_PATH_DEV) - 1;
 	while ((typ = getttyent()) != NULL) {
 		++session_index;
@@ -1353,6 +1362,8 @@
 				break;
 
 		if (sp) {
+			/* we want this one to live */
+			sp->se_collect = 0;
 			if (sp->se_index != session_index) {
 				warning("port %s changed utmp index from %d to %d",
 				       sp->se_device, sp->se_index,
@@ -1402,6 +1413,18 @@
 	}
 
 	endttyent();
+
+	/*
+	 * sweep through and kill all deleted sessions
+	 * (ones who's /etc/ttys line was deleted)
+	 */
+	for (sp = sessions; sp != NULL; sp = sp->se_next) {
+		/* if the gc flag hasn't been cleared, nuke it. */
+		if (sp->se_collect == 1) {
+			sp->se_flags |= SE_SHUTDOWN;
+			kill(sp->se_process, SIGHUP);
+		}
+	}
 
 	return (state_func_t) multi_user;
 }



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000219022149.N21720>