From owner-freebsd-current Sat Feb 19 11:19:23 2000 Delivered-To: freebsd-current@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id EA78737BD32; Sat, 19 Feb 2000 11:19:12 -0800 (PST) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) id LAA00618; Sat, 19 Feb 2000 11:45:47 -0800 (PST) Date: Sat, 19 Feb 2000 11:45:47 -0800 From: Alfred Perlstein To: current@FreeBSD.ORG Cc: jkh@FreeBSD.ORG Subject: Re: "Fixing" init. Message-ID: <20000219114547.T21720@fw.wintelcom.net> References: <20000219022149.N21720@fw.wintelcom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <20000219022149.N21720@fw.wintelcom.net>; from bright@wintelcom.net on Sat, Feb 19, 2000 at 02:21:49AM -0800 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * Alfred Perlstein [000219 02:22] wrote: > 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!" ok, NetBSD has had this fixed for _several years_, and they use bitmasks in the se_flags field, here's an updated patch that's essentially the same as the old one but using NetBSD's se_flags implementation. 4.0 please? :) thanks, -Alfred Index: init.c =================================================================== RCS file: /home/ncvs/src/sbin/init/init.c,v retrieving revision 1.37 diff -u -r1.37 init.c --- init.c 1999/11/22 04:23:09 1.37 +++ init.c 2000/02/19 23:26:32 @@ -147,6 +147,7 @@ time_t se_started; /* used to avoid thrashing */ int se_flags; /* status of session */ #define SE_SHUTDOWN 0x1 /* session won't be restarted */ +#define SE_PRESENT 0x2 /* session is in /etc/ttys */ int se_nspace; /* spacing count */ char *se_device; /* filename of port */ char *se_getty; /* what to run on that port */ @@ -964,6 +965,7 @@ /* * Allocate a new session descriptor. + * Mark it SE_PRESENT. */ session_t * new_session(sprev, session_index, typ) @@ -982,6 +984,7 @@ sp = (session_t *) calloc(1, sizeof (session_t)); sp->se_index = session_index; + sp->se_flags |= SE_PRESENT; sp->se_device = malloc(sizeof(_PATH_DEV) + strlen(typ->ty_name)); (void) sprintf(sp->se_device, "%s%s", _PATH_DEV, typ->ty_name); @@ -1330,7 +1333,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 +1347,14 @@ if (! sessions) return (state_func_t) multi_user; + /* + * mark all sessions for death, (!SE_PRESENT) + * as we find or create new ones they'll be marked as keepers, + * we'll later nuke all the ones not found in /etc/ttys + */ + for (sp = sessions; sp != NULL; sp = sp->se_next) + sp->se_flags &= ~SE_PRESENT; + devlen = sizeof(_PATH_DEV) - 1; while ((typ = getttyent()) != NULL) { ++session_index; @@ -1353,6 +1364,8 @@ break; if (sp) { + /* we want this one to live */ + sp->se_flags |= SE_PRESENT; if (sp->se_index != session_index) { warning("port %s changed utmp index from %d to %d", sp->se_device, sp->se_index, @@ -1402,6 +1415,17 @@ } endttyent(); + + /* + * sweep through and kill all deleted sessions + * ones who's /etc/ttys line was deleted (SE_PRESENT unset) + */ + for (sp = sessions; sp != NULL; sp = sp->se_next) { + if ((sp->se_flags & SE_PRESENT) == 0) { + 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