summaryrefslogtreecommitdiffstats
path: root/libexec/getty/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/getty/main.c')
-rw-r--r--libexec/getty/main.c176
1 files changed, 63 insertions, 113 deletions
diff --git a/libexec/getty/main.c b/libexec/getty/main.c
index ddfc272..7c11279 100644
--- a/libexec/getty/main.c
+++ b/libexec/getty/main.c
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1980, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1980 The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,42 +32,32 @@
*/
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1980, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+char copyright[] =
+"@(#) Copyright (c) 1980 The Regents of the University of California.\n\
+ All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/20/93";
+static char sccsid[] = "@(#)main.c 5.16 (Berkeley) 3/27/91";
#endif /* not lint */
#define USE_OLD_TTY
#include <sys/param.h>
#include <sys/stat.h>
-#include <sys/resource.h>
-
-#include <ctype.h>
-#include <ctype.h>
+#include <signal.h>
#include <fcntl.h>
-#include <setjmp.h>
#include <sgtty.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
#include <time.h>
+#include <ctype.h>
+#include <setjmp.h>
+#include <syslog.h>
#include <unistd.h>
-
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
#include "gettytab.h"
#include "pathnames.h"
-#include "extern.h"
-
-/*
- * Set the amount of running time that getty should accumulate
- * before deciding that something is wrong and exit.
- */
-#define GETTY_TIMEOUT 60 /* seconds */
struct sgttyb tmode = {
0, 0, CERASE, CKILL, 0
@@ -94,7 +84,9 @@ char *ttyname();
#define TABBUFSIZ 512
char defent[TABBUFSIZ];
+char defstrs[TABBUFSIZ];
char tabent[TABBUFSIZ];
+char tabstrs[TABBUFSIZ];
char *env[128];
@@ -142,54 +134,21 @@ interrupt()
longjmp(intrupt, 1);
}
-/*
- * Action to take when getty is running too long.
- */
-void
-timeoverrun(signo)
- int signo;
-{
-
- syslog(LOG_ERR, "getty exiting due to excessive running time\n");
- exit(1);
-}
-
-static int getname __P((void));
-static void oflush __P((void));
-static void prompt __P((void));
-static void putchr __P((int));
-static void putf __P((char *));
-static void putpad __P((char *));
-static void puts __P((char *));
-extern void reset_fbtab __P((char *));
-int
main(argc, argv)
int argc;
- char *argv[];
+ char **argv;
{
- extern char **environ;
+ extern char **environ;
char *tname;
- long allflags;
int repcnt = 0;
- struct rlimit limit;
signal(SIGINT, SIG_IGN);
-/*
signal(SIGQUIT, SIG_DFL);
-*/
+
openlog("getty", LOG_ODELAY|LOG_CONS, LOG_AUTH);
gethostname(hostname, sizeof(hostname));
if (hostname[0] == '\0')
strcpy(hostname, "Amnesiac");
-
- /*
- * Limit running time to deal with broken or dead lines.
- */
- (void)signal(SIGXCPU, timeoverrun);
- limit.rlim_max = RLIM_INFINITY;
- limit.rlim_cur = GETTY_TIMEOUT;
- (void)setrlimit(RLIMIT_CPU, &limit);
-
/*
* The following is a work around for vhangup interactions
* which cause great problems getting window systems started.
@@ -208,10 +167,6 @@ main(argc, argv)
chown(ttyn, 0, 0);
chmod(ttyn, 0600);
revoke(ttyn);
- /*
- * Delay the open so DTR stays down long enough to be detected.
- */
- sleep(2);
while ((i = open(ttyn, O_RDWR)) == -1) {
if (repcnt % 10 == 0) {
syslog(LOG_ERR, "%s: %m", ttyn);
@@ -224,25 +179,24 @@ main(argc, argv)
}
}
- /* Read the FBTAB file and check if we have to reset perms/ownership */
- reset_fbtab(ttyn);
-
- gettable("default", defent);
+ gettable("default", defent, defstrs);
gendefaults();
tname = "default";
if (argc > 1)
tname = argv[1];
for (;;) {
- int off;
+ int off = 0;
+ int flushboth = 0;
+ struct sgttyb fake;
- gettable(tname, tabent);
+ gettable(tname, tabent, tabstrs);
if (OPset || EPset || APset)
APset++, OPset++, EPset++;
setdefaults();
- off = 0;
- ioctl(0, TIOCFLUSH, &off); /* clear out the crap */
+ ioctl(0, TIOCFLUSH, &flushboth); /* clear out the crap */
ioctl(0, FIONBIO, &off); /* turn off non-blocking mode */
ioctl(0, FIOASYNC, &off); /* ditto for async mode */
+ ioctl(0, TIOCGETP, &fake); /* initialize kernel termios */
if (IS)
tmode.sg_ispeed = speed(IS);
else if (SP)
@@ -251,8 +205,7 @@ main(argc, argv)
tmode.sg_ospeed = speed(OS);
else if (SP)
tmode.sg_ospeed = speed(SP);
- tmode.sg_flags = setflags(0);
- ioctl(0, TIOCSETP, &tmode);
+ set_tmode(0);
setchars();
ioctl(0, TIOCSETC, &tc);
if (HC)
@@ -284,58 +237,39 @@ main(argc, argv)
if (getname()) {
register int i;
- oflush();
alarm(0);
signal(SIGALRM, SIG_DFL);
+ oflush();
if (name[0] == '-') {
puts("user names may not start with '-'.");
continue;
}
if (!(upper || lower || digit))
continue;
- allflags = setflags(2);
- tmode.sg_flags = allflags & 0xffff;
- allflags >>= 16;
- if (crmod || NL)
- tmode.sg_flags |= CRMOD;
- if (upper || UC)
- tmode.sg_flags |= LCASE;
- if (lower || LC)
- tmode.sg_flags &= ~LCASE;
- ioctl(0, TIOCSETP, &tmode);
+ set_tmode(2);
ioctl(0, TIOCSLTC, &ltc);
- ioctl(0, TIOCLSET, &allflags);
- signal(SIGINT, SIG_DFL);
for (i = 0; environ[i] != (char *)0; i++)
env[i] = environ[i];
makeenv(&env[i]);
- /*
- * this is what login was doing anyway.
- * soon we rewrite getty completely.
- */
- set_ttydefaults(0);
- limit.rlim_max = RLIM_INFINITY;
- limit.rlim_cur = RLIM_INFINITY;
- (void)setrlimit(RLIMIT_CPU, &limit);
execle(LO, "login", "-p", name, (char *) 0, env);
syslog(LOG_ERR, "%s: %m", LO);
exit(1);
}
+ signal(SIGINT, SIG_IGN);
alarm(0);
signal(SIGALRM, SIG_DFL);
- signal(SIGINT, SIG_IGN);
if (NX && *NX)
tname = NX;
}
}
-static int
getname()
{
register int c;
register char *np;
char cs;
+ int flushin = 1 /*FREAD*/;
/*
* Interrupt may happen if we use CBREAK mode
@@ -345,16 +279,14 @@ getname()
return (0);
}
signal(SIGINT, interrupt);
- tmode.sg_flags = setflags(0);
- ioctl(0, TIOCSETP, &tmode);
- tmode.sg_flags = setflags(1);
+ ioctl(0, TIOCFLUSH, &flushin); /* purge any input */
prompt();
+ oflush();
if (PF > 0) {
- oflush();
sleep(PF);
PF = 0;
}
- ioctl(0, TIOCSETP, &tmode);
+ set_tmode(1);
crmod = digit = lower = upper = 0;
np = name;
for (;;) {
@@ -363,7 +295,7 @@ getname()
exit(0);
if ((c = cs&0177) == 0)
return (0);
- if (c == EOT)
+ if (c == EOT || c == 4 /*^D*/)
exit(1);
if (c == '\r' || c == '\n' || np >= &name[sizeof name]) {
putf("\r\n");
@@ -373,7 +305,7 @@ getname()
lower = 1;
else if (isupper(c))
upper = 1;
- else if (c == ERASE || c == '#' || c == '\b') {
+ else if (c == ERASE || c == '\b' || c == 0177) {
if (np > name) {
np--;
if (tmode.sg_ospeed >= B1200)
@@ -382,8 +314,7 @@ getname()
putchr(cs);
}
continue;
- } else if (c == KILL || c == '@') {
- putchr(cs);
+ } else if (c == KILL || c == 025 /*^U*/) {
putchr('\r');
if (tmode.sg_ospeed < B1200)
putchr('\n');
@@ -416,7 +347,6 @@ short tmspc10[] = {
0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 15
};
-static void
putpad(s)
register char *s;
{
@@ -458,7 +388,6 @@ putpad(s)
putchr(*PC);
}
-static void
puts(s)
register char *s;
{
@@ -469,9 +398,7 @@ puts(s)
char outbuf[OBUFSIZ];
int obufcnt = 0;
-static void
putchr(cc)
- int cc;
{
char c;
@@ -489,7 +416,6 @@ putchr(cc)
write(STDOUT_FILENO, &c, 1);
}
-static void
oflush()
{
if (obufcnt)
@@ -497,7 +423,6 @@ oflush()
obufcnt = 0;
}
-static void
prompt()
{
@@ -506,7 +431,6 @@ prompt()
putchr('\n');
}
-static void
putf(cp)
register char *cp;
{
@@ -522,7 +446,7 @@ putf(cp)
switch (*++cp) {
case 't':
- slash = strrchr(ttyn, '/');
+ slash = rindex(ttyn, '/');
if (slash == (char *) 0)
puts(ttyn);
else
@@ -550,3 +474,29 @@ putf(cp)
cp++;
}
}
+
+/*
+ * The conversions from sgttyb to termios make LITOUT and PASS8 affect
+ * the parity. So every TIOCSETP ioctl has to be paired with a TIOCLSET
+ * ioctl (at least if LITOUT or PASS8 has changed, and PASS8 may vary
+ * with 'n').
+ */
+set_tmode(n)
+ int n;
+{
+ long allflags;
+
+ allflags = setflags(n);
+ tmode.sg_flags = allflags & 0xffff;
+ allflags >>= 16;
+ if (n == 2) {
+ if (crmod || NL)
+ tmode.sg_flags |= CRMOD;
+ if (upper || UC)
+ tmode.sg_flags |= LCASE;
+ if (lower || LC)
+ tmode.sg_flags &= ~LCASE;
+ }
+ ioctl(0, TIOCSETP, &tmode);
+ ioctl(0, TIOCLSET, &allflags);
+}
OpenPOWER on IntegriCloud