summaryrefslogtreecommitdiffstats
path: root/sbin/init
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1994-10-14 17:15:40 +0000
committerache <ache@FreeBSD.org>1994-10-14 17:15:40 +0000
commit9cd061f6c1bf0cf3d26d34f45b6edd267755b265 (patch)
treebfc606726d2423d963436d5541ab667e511fde3f /sbin/init
parenta92485cbaca698673d223c798fdd1e66a54101fd (diff)
downloadFreeBSD-src-9cd061f6c1bf0cf3d26d34f45b6edd267755b265.zip
FreeBSD-src-9cd061f6c1bf0cf3d26d34f45b6edd267755b265.tar.gz
revision 1.6
date: 1994/03/06 08:55:02; author: ache; state: Exp; lines: +4 -1 Stop count getty spacing problem, if we issue kill -1 1 ---------------------------- revision 1.5 date: 1994/03/04 17:51:39; author: ache; state: Exp; lines: +9 -2 I got a lot of "getty repeating too quickly on port %s, sleeping" from init.bsdi, it means that getty start and exit in five seconds. This is common situation for poor quality Russian phone lines: modem got CONNECT message and after retries got NO CARRIER. So I introduce spacing count, it means that this warning and sleep occurse only after GETTY_NSPACE times of sequental attempts. ---------------------------- revision 1.4 date: 1994/02/28 21:53:52; author: ache; state: Exp; lines: +71 -10 I found (and fix) ugly bugs in init.bsdi (this bugs not present in old init) 1) Init don't setup TERM environment variable for default terminal type from /etc/ttys before calling getty/window. 2) When "kill -1 1" issued, init don't restart getty when /etc/ttys parameters was changed (it only kill "off" end empty entries). 3) Small memory leak if "window" /etc/ttys parameter specified and "kill -1 1" issued. Obtained from: FreeBSD 1.x
Diffstat (limited to 'sbin/init')
-rw-r--r--sbin/init/init.c91
1 files changed, 81 insertions, 10 deletions
diff --git a/sbin/init/init.c b/sbin/init/init.c
index 8bbe9c7..74d48f0 100644
--- a/sbin/init/init.c
+++ b/sbin/init/init.c
@@ -85,6 +85,7 @@ extern void logwtmp __P((const char *, const char *, const char *));
*/
#define GETTY_SPACING 5 /* N secs minimum getty spacing */
#define GETTY_SLEEP 30 /* sleep N secs after spacing problem */
+#define GETTY_NSPACE 3 /* max. spacing count to bring reaction */
#define WINDOW_WAIT 3 /* wait N secs after starting window */
#define STALL_TIMEOUT 30 /* wait N secs after warning */
#define DEATH_WATCH 10 /* wait N secs for procs to die */
@@ -128,11 +129,15 @@ typedef struct init_session {
time_t se_started; /* used to avoid thrashing */
int se_flags; /* status of session */
#define SE_SHUTDOWN 0x1 /* session won't be restarted */
+ int se_nspace; /* spacing count */
char *se_device; /* filename of port */
char *se_getty; /* what to run on that port */
+ char *se_getty_argv_space; /* pre-parsed argument array space */
char **se_getty_argv; /* pre-parsed argument array */
char *se_window; /* window system (started only once) */
+ char *se_window_argv_space; /* pre-parsed argument array space */
char **se_window_argv; /* pre-parsed argument array */
+ char *se_type; /* default terminal type */
struct init_session *se_prev;
struct init_session *se_next;
} session_t;
@@ -882,12 +887,16 @@ free_session(sp)
free(sp->se_device);
if (sp->se_getty) {
free(sp->se_getty);
+ free(sp->se_getty_argv_space);
free(sp->se_getty_argv);
}
if (sp->se_window) {
free(sp->se_window);
+ free(sp->se_window_argv_space);
free(sp->se_window_argv);
}
+ if (sp->se_type)
+ free(sp->se_type);
free(sp);
}
@@ -943,30 +952,43 @@ setupargv(sp, typ)
if (sp->se_getty) {
free(sp->se_getty);
+ free(sp->se_getty_argv_space);
free(sp->se_getty_argv);
}
sp->se_getty = malloc(strlen(typ->ty_getty) + strlen(typ->ty_name) + 2);
(void) sprintf(sp->se_getty, "%s %s", typ->ty_getty, typ->ty_name);
- sp->se_getty_argv = construct_argv(sp->se_getty);
+ sp->se_getty_argv_space = strdup(sp->se_getty);
+ sp->se_getty_argv = construct_argv(sp->se_getty_argv_space);
if (sp->se_getty_argv == 0) {
warning("can't parse getty for port %s", sp->se_device);
free(sp->se_getty);
- sp->se_getty = 0;
+ free(sp->se_getty_argv_space);
+ sp->se_getty = sp->se_getty_argv_space = 0;
return (0);
}
- if (typ->ty_window) {
- if (sp->se_window)
+ if (sp->se_window) {
free(sp->se_window);
+ free(sp->se_window_argv_space);
+ free(sp->se_window_argv);
+ }
+ sp->se_window = sp->se_window_argv_space = 0;
+ sp->se_window_argv = 0;
+ if (typ->ty_window) {
sp->se_window = strdup(typ->ty_window);
- sp->se_window_argv = construct_argv(sp->se_window);
+ sp->se_window_argv_space = strdup(sp->se_window);
+ sp->se_window_argv = construct_argv(sp->se_window_argv_space);
if (sp->se_window_argv == 0) {
warning("can't parse window for port %s",
sp->se_device);
+ free(sp->se_window_argv_space);
free(sp->se_window);
- sp->se_window = 0;
+ sp->se_window = sp->se_window_argv_space = 0;
return (0);
}
}
+ if (sp->se_type)
+ free(sp->se_type);
+ sp->se_type = typ->ty_type ? strdup(typ->ty_type) : 0;
return (1);
}
@@ -1016,6 +1038,7 @@ start_window_system(sp)
{
pid_t pid;
sigset_t mask;
+ char term[64], *env[2];
if ((pid = fork()) == -1) {
emergency("can't fork for window system on port %s: %m",
@@ -1033,7 +1056,16 @@ start_window_system(sp)
if (setsid() < 0)
emergency("setsid failed (window) %m");
- execv(sp->se_window_argv[0], sp->se_window_argv);
+ if (sp->se_type) {
+ /* Don't use malloc after fork */
+ strcpy(term, "TERM=");
+ strcat(term, sp->se_type);
+ env[0] = term;
+ env[1] = 0;
+ }
+ else
+ env[0] = 0;
+ execve(sp->se_window_argv[0], sp->se_window_argv, env);
stall("can't exec window system '%s' for port %s: %m",
sp->se_window_argv[0], sp->se_device);
_exit(1);
@@ -1049,6 +1081,7 @@ start_getty(sp)
pid_t pid;
sigset_t mask;
time_t current_time = time((time_t *) 0);
+ char term[64], *env[2];
/*
* fork(), not vfork() -- we can't afford to block.
@@ -1063,10 +1096,15 @@ start_getty(sp)
if (current_time > sp->se_started &&
current_time - sp->se_started < GETTY_SPACING) {
- warning("getty repeating too quickly on port %s, sleeping",
- sp->se_device);
+ if (++sp->se_nspace > GETTY_NSPACE) {
+ sp->se_nspace = 0;
+ warning("getty repeating too quickly on port %s, sleeping %d secs",
+ sp->se_device, GETTY_SLEEP);
sleep((unsigned) GETTY_SLEEP);
}
+ }
+ else
+ sp->se_nspace = 0;
if (sp->se_window) {
start_window_system(sp);
@@ -1076,7 +1114,16 @@ start_getty(sp)
sigemptyset(&mask);
sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0);
- execv(sp->se_getty_argv[0], sp->se_getty_argv);
+ if (sp->se_type) {
+ /* Don't use malloc after fork */
+ strcpy(term, "TERM=");
+ strcat(term, sp->se_type);
+ env[0] = term;
+ env[1] = 0;
+ }
+ else
+ env[0] = 0;
+ execve(sp->se_getty_argv[0], sp->se_getty_argv, env);
stall("can't exec getty '%s' for port %s: %m",
sp->se_getty_argv[0], sp->se_device);
_exit(1);
@@ -1204,6 +1251,7 @@ clean_ttys()
register struct ttyent *typ;
register int session_index = 0;
register int devlen;
+ char *old_getty, *old_window, *old_type;
if (! sessions)
return (state_func_t) multi_user;
@@ -1230,12 +1278,35 @@ clean_ttys()
continue;
}
sp->se_flags &= ~SE_SHUTDOWN;
+ old_getty = sp->se_getty ? strdup(sp->se_getty) : 0;
+ old_window = sp->se_window ? strdup(sp->se_window) : 0;
+ old_type = sp->se_type ? strdup(sp->se_type) : 0;
if (setupargv(sp, typ) == 0) {
warning("can't parse getty for port %s",
sp->se_device);
sp->se_flags |= SE_SHUTDOWN;
kill(sp->se_process, SIGHUP);
}
+ else if ( !old_getty
+ || !old_type && sp->se_type
+ || old_type && !sp->se_type
+ || !old_window && sp->se_window
+ || old_window && !sp->se_window
+ || strcmp(old_getty, sp->se_getty) != 0
+ || old_window && strcmp(old_window, sp->se_window) != 0
+ || old_type && strcmp(old_type, sp->se_type) != 0
+ ) {
+ /* Don't set SE_SHUTDOWN here */
+ sp->se_nspace = 0;
+ sp->se_started = 0;
+ kill(sp->se_process, SIGHUP);
+ }
+ if (old_getty)
+ free(old_getty);
+ if (old_getty)
+ free(old_window);
+ if (old_type)
+ free(old_type);
continue;
}
OpenPOWER on IntegriCloud