Date: Sat, 19 Feb 2000 11:45:47 -0800 From: Alfred Perlstein <bright@wintelcom.net> To: current@FreeBSD.ORG Cc: jkh@FreeBSD.ORG Subject: Re: "Fixing" init. Message-ID: <20000219114547.T21720@fw.wintelcom.net> In-Reply-To: <20000219022149.N21720@fw.wintelcom.net>; from bright@wintelcom.net on Sat, Feb 19, 2000 at 02:21:49AM -0800 References: <20000219022149.N21720@fw.wintelcom.net>
next in thread | previous in thread | raw e-mail | index | archive | help
* Alfred Perlstein <bright@wintelcom.net> [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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000219114547.T21720>