-#define CMDSIZ 200 /* max string length for getty or window command*/
-#define ALL p = itab; p ; p = p->next
-#define EVER ;;
-#define SCPYN(a, b) strncpy(a, b, sizeof(a))
-#define SCMPN(a, b) strncmp(a, b, sizeof(a))
-
-char shell[] = _PATH_BSHELL;
-char minus[] = "-";
-char runc[] = _PATH_RC;
-char ctty[] = _PATH_CONSOLE;
-
-struct tab
-{
- char line[UT_LINESIZE];
- char comn[CMDSIZ];
- char xflag;
- int pid;
- int wpid; /* window system pid for SIGHUP */
- char wcmd[CMDSIZ]; /* command to start window system process */
- time_t gettytime;
- int gettycnt;
- time_t windtime;
- int windcnt;
- struct tab *next;
-} *itab;
-
-int fi;
-int mergflag;
-char tty[20];
-jmp_buf sjbuf, shutpass;
-
-char *strcpy(), *strcat();
-long lseek();
-void idle(), merge(), reset();
-
-struct sigvec rvec = { reset, sigmask(SIGHUP), 0 };
+/*
+ * Until the mythical util.h arrives...
+ */
+extern int login_tty __P((int));
+extern int logout __P((const char *));
+extern void logwtmp __P((const char *, const char *, const char *));
+
+/*
+ * Sleep times; used to prevent thrashing.
+ */
+#define GETTY_SPACING 5 /* N secs minimum getty spacing */
+#define GETTY_SLEEP 30 /* sleep N secs after spacing problem */
+#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 */
+
+void handle __P((sig_t, ...));
+void delset __P((sigset_t *, ...));
+
+void stall __P((char *, ...));
+void warning __P((char *, ...));
+void emergency __P((char *, ...));
+void disaster __P((int));
+void badsys __P((int));
+
+/*
+ * We really need a recursive typedef...
+ * The following at least guarantees that the return type of (*state_t)()
+ * is sufficiently wide to hold a function pointer.
+ */
+typedef long (*state_func_t) __P((void));
+typedef state_func_t (*state_t) __P((void));
+
+state_func_t single_user __P((void));
+state_func_t runcom __P((void));
+state_func_t read_ttys __P((void));
+state_func_t multi_user __P((void));
+state_func_t clean_ttys __P((void));
+state_func_t catatonia __P((void));
+state_func_t death __P((void));
+
+enum { AUTOBOOT, FASTBOOT } runcom_mode = AUTOBOOT;
+
+void transition __P((state_t));
+state_t requested_transition = runcom;
+
+void setctty __P((char *));
+
+typedef struct init_session {
+ int se_index; /* index of entry in ttys file */
+ pid_t se_process; /* controlling process */
+ time_t se_started; /* used to avoid thrashing */
+ int se_flags; /* status of session */
+#define SE_SHUTDOWN 0x1 /* session won't be restarted */
+ char *se_device; /* filename of port */
+ char *se_getty; /* what to run on that port */
+ char **se_getty_argv; /* pre-parsed argument array */
+ char *se_window; /* window system (started only once) */
+ char **se_window_argv; /* pre-parsed argument array */
+ struct init_session *se_prev;
+ struct init_session *se_next;
+} session_t;