1 /* vi: set sw=4 ts=4: */
2 /* agetty.c - another getty program for Linux. By W. Z. Venema 1989
3 Ported to Linux by Peter Orbaek <poe@daimi.aau.dk>
4 This program is freely distributable. The entire man-page used to
5 be here. Now read the real man-page agetty.8 instead.
7 -f option added by Eric Rasmussen <ear@usfirst.org> - 12/28/95
9 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
10 - added Native Language Support
12 1999-05-05 Thorsten Kranzkowski <dl8bcu@gmx.net>
13 - enable hardware flow control before displaying /etc/issue
21 #include <sys/ioctl.h>
24 #include <sys/signal.h>
32 #ifdef CONFIG_FEATURE_UTMP
36 #define _PATH_LOGIN "/bin/login"
38 /* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */
40 #include <sys/param.h>
46 * Some heuristics to find out what environment we are in: if it is not
47 * System V, assume it is SunOS 4.
50 #ifdef LOGIN_PROCESS /* defined in System V utmp.h */
51 #define SYSV_STYLE /* select System V style getty */
52 #ifdef CONFIG_FEATURE_WTMP
53 extern void updwtmp(const char *filename, const struct utmp *ut);
55 #endif /* LOGIN_PROCESS */
58 * Things you may want to modify.
60 * You may disagree with the default line-editing etc. characters defined
61 * below. Note, however, that DEL cannot be used for interrupt generation
62 * and for line editing at the same time.
66 #include <sys/utsname.h>
70 /* If ISSUE is not defined, agetty will never display the contents of the
71 * /etc/issue file. You will not want to spit out large "issue" files at the
74 #define ISSUE "/etc/issue" /* displayed before the login prompt */
76 /* Some shorthands for control characters. */
78 #define CTL(x) (x ^ 0100) /* Assumes ASCII dialect */
79 #define CR CTL('M') /* carriage return */
80 #define NL CTL('J') /* line feed */
81 #define BS CTL('H') /* back space */
82 #define DEL CTL('?') /* delete */
84 /* Defaults for line-editing etc. characters; you may want to change this. */
86 #define DEF_ERASE DEL /* default erase character */
87 #define DEF_INTR CTL('C') /* default interrupt character */
88 #define DEF_QUIT CTL('\\') /* default quit char */
89 #define DEF_KILL CTL('U') /* default kill char */
90 #define DEF_EOF CTL('D') /* default EOF char */
92 #define DEF_SWITCH 0 /* default switch char */
95 * SunOS 4.1.1 termio is broken. We must use the termios stuff instead,
96 * because the termio -> termios translation does not clear the termios
97 * CIBAUD bits. Therefore, the tty driver would sometimes report that input
98 * baud rate != output baud rate. I did not notice that problem with SunOS
99 * 4.1. We will use termios where available, and termio otherwise.
102 /* linux 0.12 termio is broken too, if we use it c_cc[VERASE] isn't set
103 properly, but all is well if we use termios?! */
109 #define termio termios
110 #define TCGETA TCGETS
111 #define TCSETA TCSETS
112 #define TCSETAW TCSETSW
116 * When multiple baud rates are specified on the command line, the first one
117 * we will try is the first one specified.
120 #define FIRST_SPEED 0
122 /* Storage for command-line options. */
124 #define MAX_SPEED 10 /* max. nr. of baud rates */
127 int flags; /* toggle switches, see below */
128 int timeout; /* time-out period */
129 char *login; /* login program */
130 char *tty; /* name of tty */
131 char *initstring; /* modem init string */
132 char *issue; /* alternative issue file */
133 int numspeed; /* number of baud rates to try */
134 int speeds[MAX_SPEED]; /* baud rates to be tried */
137 static const char opt_string[] = "I:LH:f:hil:mt:wn";
138 #define F_INITSTRING (1<<0) /* initstring is set */
139 #define F_LOCAL (1<<1) /* force local */
140 #define F_FAKEHOST (1<<2) /* force fakehost */
141 #define F_CUSTISSUE (1<<3) /* give alternative issue file */
142 #define F_RTSCTS (1<<4) /* enable RTS/CTS flow control */
143 #define F_ISSUE (1<<5) /* display /etc/issue */
144 #define F_LOGIN (1<<6) /* non-default login program */
145 #define F_PARSE (1<<7) /* process modem status messages */
146 #define F_TIMEOUT (1<<8) /* time out */
147 #define F_WAITCRLF (1<<9) /* wait for CR or LF */
148 #define F_NOPROMPT (1<<10) /* don't ask for login name! */
150 /* Storage for things detected while the login name was read. */
153 int erase; /* erase character */
154 int kill; /* kill character */
155 int eol; /* end-of-line character */
156 int parity; /* what parity did we see */
157 int capslock; /* upper case without lower case */
160 /* Initial values for the above. */
162 static struct chardata init_chardata = {
163 DEF_ERASE, /* default erase character */
164 DEF_KILL, /* default kill character */
165 13, /* default eol char */
166 0, /* space parity */
176 static struct Speedtab speedtab[] = {
215 static void parse_args(int argc, char **argv, struct options *op);
216 static void parse_speeds(struct options *op, char *arg);
217 static void open_tty(char *tty, struct termio *tp, int local);
218 static void termio_init(struct termio *tp, int speed, struct options *op);
219 static void auto_baud(struct termio *tp);
220 static void do_prompt(struct options *op, struct termio *tp);
221 static void next_speed(struct termio *tp, struct options *op);
222 static char *get_logname(struct options *op, struct chardata *cp,
224 static void termio_final(struct options *op, struct termio *tp,
225 struct chardata *cp);
226 static int caps_lock(const char *s);
227 static int bcode(const char *s);
228 static void error(const char *fmt, ...) ATTRIBUTE_NORETURN;
231 #ifdef CONFIG_FEATURE_UTMP
232 static void update_utmp(char *line);
236 /* The following is used for understandable diagnostics. */
238 /* Fake hostname for ut_host specified on command line. */
239 static char *fakehost = NULL;
243 #define debug(s) fprintf(dbf,s); fflush(dbf)
244 #define DEBUGTERM "/dev/ttyp0"
247 #define debug(s) /* nothing */
250 int getty_main(int argc, char **argv)
252 char *logname = NULL; /* login name, given to /bin/login */
253 struct chardata chardata; /* set by get_logname() */
254 struct termio termio; /* terminal mode bits */
255 static struct options options = {
256 0, /* show /etc/issue (SYSV_STYLE) */
258 _PATH_LOGIN, /* default login program */
259 "tty1", /* default tty line */
260 "", /* modem init string */
262 ISSUE, /* default issue file */
266 0, /* no baud rates known yet */
270 dbf = bb_xfopen(DEBUGTERM, "w");
275 for (i = 1; i < argc; i++) {
282 /* Parse command-line arguments. */
284 parse_args(argc, argv, &options);
290 /* Update the utmp file. */
294 #ifdef CONFIG_FEATURE_UTMP
295 update_utmp(options.tty);
299 debug("calling open_tty\n");
300 /* Open the tty as standard { input, output, error }. */
301 open_tty(options.tty, &termio, options.flags & F_LOCAL);
308 ioctl(0, TIOCSPGRP, &iv);
311 /* Initialize the termio settings (raw mode, eight-bit, blocking i/o). */
312 debug("calling termio_init\n");
313 termio_init(&termio, options.speeds[FIRST_SPEED], &options);
315 /* write the modem init string and DON'T flush the buffers */
316 if (options.flags & F_INITSTRING) {
317 debug("writing init string\n");
318 write(1, options.initstring, strlen(options.initstring));
321 if (!(options.flags & F_LOCAL)) {
322 /* go to blocking write mode unless -L is specified */
323 fcntl(1, F_SETFL, fcntl(1, F_GETFL, 0) & ~O_NONBLOCK);
326 /* Optionally detect the baud rate from the modem status message. */
327 debug("before autobaud\n");
328 if (options.flags & F_PARSE)
331 /* Set the optional timer. */
333 (void) alarm((unsigned) options.timeout);
335 /* optionally wait for CR or LF before writing /etc/issue */
336 if (options.flags & F_WAITCRLF) {
339 debug("waiting for cr-lf\n");
340 while (read(0, &ch, 1) == 1) {
341 ch &= 0x7f; /* strip "parity bit" */
343 fprintf(dbf, "read %c\n", ch);
345 if (ch == '\n' || ch == '\r')
350 chardata = init_chardata;
351 if (!(options.flags & F_NOPROMPT)) {
352 /* Read the login name. */
353 debug("reading login name\n");
354 /* while ((logname = get_logname(&options, &chardata, &termio)) == 0) */
355 while ((logname = get_logname(&options, &chardata, &termio)) ==
356 NULL) next_speed(&termio, &options);
364 /* Finalize the termio settings. */
366 termio_final(&options, &termio, &chardata);
368 /* Now the newline character should be properly written. */
370 (void) write(1, "\n", 1);
372 /* Let the login program take care of password validation. */
374 (void) execl(options.login, options.login, "--", logname, (char *) 0);
375 error("%s: can't exec %s: %m", options.tty, options.login);
378 /* parse-args - parse command-line arguments */
380 static void parse_args(int argc, char **argv, struct options *op)
384 op->flags = bb_getopt_ulflags(argc, argv, opt_string,
385 &(op->initstring), &fakehost, &(op->issue),
387 if(op->flags & F_INITSTRING) {
388 const char *p = op->initstring;
391 q = op->initstring = bb_xstrdup(op->initstring);
392 /* copy optarg into op->initstring decoding \ddd
393 octal codes into chars */
397 *q++ = bb_process_escape_sequence(&p);
404 op->flags ^= F_ISSUE; /* revert flag show /etc/issue */
405 if(op->flags & F_TIMEOUT) {
406 if ((op->timeout = atoi(ts)) <= 0)
407 error("bad timeout value: %s", ts);
409 debug("after getopt loop\n");
410 if (argc < optind + 2) /* check parameter count */
413 /* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */
414 if ('0' <= argv[optind][0] && argv[optind][0] <= '9') {
415 /* a number first, assume it's a speed (BSD style) */
416 parse_speeds(op, argv[optind++]); /* baud rate(s) */
417 op->tty = argv[optind]; /* tty name */
419 op->tty = argv[optind++]; /* tty name */
420 parse_speeds(op, argv[optind]); /* baud rate(s) */
424 if (argc > optind && argv[optind])
425 setenv("TERM", argv[optind], 1);
427 debug("exiting parseargs\n");
430 /* parse_speeds - parse alternate baud rates */
432 static void parse_speeds(struct options *op, char *arg)
436 debug("entered parse_speeds\n");
437 for (cp = strtok(arg, ","); cp != 0; cp = strtok((char *) 0, ",")) {
438 if ((op->speeds[op->numspeed++] = bcode(cp)) <= 0)
439 error("bad speed: %s", cp);
440 if (op->numspeed > MAX_SPEED)
441 error("too many alternate speeds");
443 debug("exiting parsespeeds\n");
447 #ifdef CONFIG_FEATURE_UTMP
449 /* update_utmp - update our utmp entry */
450 static void update_utmp(char *line)
455 int mypid = getpid();
456 #if ! (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1))
461 * The utmp file holds miscellaneous information about things started by
462 * /sbin/init and other system-related events. Our purpose is to update
463 * the utmp entry for the current process, in particular the process type
464 * and the tty line we are listening to. Return successfully only if the
465 * utmp file can be opened for update, and if we are able to find our
466 * entry in the utmp file.
468 if (access(_PATH_UTMP, R_OK|W_OK) == -1) {
469 close(creat(_PATH_UTMP, 0664));
471 utmpname(_PATH_UTMP);
473 while ((utp = getutent())
474 && !(utp->ut_type == INIT_PROCESS && utp->ut_pid == mypid)) /* nothing */
478 memcpy(&ut, utp, sizeof(ut));
480 /* some inits don't initialize utmp... */
481 memset(&ut, 0, sizeof(ut));
482 strncpy(ut.ut_id, line + 3, sizeof(ut.ut_id));
486 strncpy(ut.ut_user, "LOGIN", sizeof(ut.ut_user));
487 strncpy(ut.ut_line, line, sizeof(ut.ut_line));
489 strncpy(ut.ut_host, fakehost, sizeof(ut.ut_host));
492 ut.ut_type = LOGIN_PROCESS;
498 #ifdef CONFIG_FEATURE_WTMP
499 if (access(_PATH_WTMP, R_OK|W_OK) == -1)
500 close(creat(_PATH_WTMP, 0664));
501 updwtmp(_PATH_WTMP, &ut);
505 #endif /* CONFIG_FEATURE_UTMP */
506 #endif /* SYSV_STYLE */
508 /* open_tty - set up tty as standard { input, output, error } */
509 static void open_tty(char *tty, struct termio *tp, int local)
511 int chdir_to_root = 0;
513 /* Set up new standard input, unless we are given an already opened port. */
515 if (strcmp(tty, "-")) {
519 /* Sanity checks... */
522 error("/dev: chdir() failed: %m");
524 if (stat(tty, &st) < 0)
525 error("/dev/%s: %m", tty);
526 if ((st.st_mode & S_IFMT) != S_IFCHR)
527 error("/dev/%s: not a character device", tty);
529 /* Open the tty as standard input. */
533 fd = open(tty, O_RDWR | O_NONBLOCK, 0);
535 error("/dev/%s: cannot open as standard input: %m", tty);
539 * Standard input should already be connected to an open port. Make
540 * sure it is open for read/write.
543 if ((fcntl(0, F_GETFL, 0) & O_RDWR) != O_RDWR)
544 error("%s: not open for read/write", tty);
547 /* Replace current standard output/error fd's with new ones */
549 if (dup2(STDIN_FILENO, STDOUT_FILENO) == -1 ||
550 dup2(STDIN_FILENO, STDERR_FILENO) == -1)
551 error("%s: dup problem: %m", tty); /* we have a problem */
554 * The following ioctl will fail if stdin is not a tty, but also when
555 * there is noise on the modem control lines. In the latter case, the
556 * common course of action is (1) fix your cables (2) give the modem more
557 * time to properly reset after hanging up. SunOS users can achieve (2)
558 * by patching the SunOS kernel variable "zsadtrlow" to a larger value;
559 * 5 seconds seems to be a good value.
562 if (ioctl(0, TCGETA, tp) < 0)
563 error("%s: ioctl: %m", tty);
566 * It seems to be a terminal. Set proper protections and ownership. Mode
567 * 0622 is suitable for SYSV <4 because /bin/login does not change
568 * protections. SunOS 4 login will change the protections to 0620 (write
569 * access for group tty) after the login has succeeded.
574 /* tty to root.dialout 660 */
578 id = (gr = getgrnam("dialout")) ? gr->gr_gid : 0;
582 /* vcs,vcsa to root.sys 600 */
583 if (!strncmp(tty, "tty", 3) && isdigit(tty[3])) {
586 if (!(vcs = strdup(tty)))
587 error("Can't malloc for vcs");
588 if (!(vcsa = malloc(strlen(tty) + 2)))
589 error("Can't malloc for vcsa");
591 strcpy(vcs + 3, tty + 3);
592 strcpy(vcsa, "vcsa");
593 strcpy(vcsa + 4, tty + 3);
595 id = (gr = getgrnam("sys")) ? gr->gr_gid : 0;
606 (void) chown(tty, 0, 0); /* root, sys */
607 (void) chmod(tty, 0622); /* crw--w--w- */
609 if(chdir_to_root && chdir("/"))
610 error("chdir to / failed: %m");
613 /* termio_init - initialize termio settings */
615 static void termio_init(struct termio *tp, int speed, struct options *op)
618 * Initial termio settings: 8-bit characters, raw-mode, blocking i/o.
619 * Special characters are set after we have read the login name; all
620 * reads will be done in raw mode anyway. Errors will be dealt with
624 /* flush input and output queues, important for modems! */
625 (void) ioctl(0, TCFLSH, TCIOFLUSH);
628 tp->c_cflag = CS8 | HUPCL | CREAD | speed;
629 if (op->flags & F_LOCAL) {
630 tp->c_cflag |= CLOCAL;
633 tp->c_iflag = tp->c_lflag = tp->c_oflag = tp->c_line = 0;
637 /* Optionally enable hardware flow control */
640 if (op->flags & F_RTSCTS)
641 tp->c_cflag |= CRTSCTS;
644 (void) ioctl(0, TCSETA, tp);
646 /* go to blocking input even in local mode */
647 fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~O_NONBLOCK);
649 debug("term_io 2\n");
652 /* auto_baud - extract baud rate from modem status message */
653 static void auto_baud(struct termio *tp)
663 * This works only if the modem produces its status code AFTER raising
664 * the DCD line, and if the computer is fast enough to set the proper
665 * baud rate before the message has gone by. We expect a message of the
668 * <junk><number><junk>
670 * The number is interpreted as the baud rate of the incoming call. If the
671 * modem does not tell us the baud rate within one second, we will keep
672 * using the current baud rate. It is advisable to enable BREAK
673 * processing (comma-separated list of baud rates) if the processing of
674 * modem status messages is enabled.
678 * Use 7-bit characters, don't block if input queue is empty. Errors will
679 * be dealt with lateron.
683 tp->c_iflag |= ISTRIP; /* enable 8th-bit stripping */
684 vmin = tp->c_cc[VMIN];
685 tp->c_cc[VMIN] = 0; /* don't block if queue empty */
686 (void) ioctl(0, TCSETA, tp);
689 * Wait for a while, then read everything the modem has said so far and
690 * try to extract the speed of the dial-in call.
694 if ((nread = read(0, buf, sizeof(buf) - 1)) > 0) {
696 for (bp = buf; bp < buf + nread; bp++) {
697 if (isascii(*bp) && isdigit(*bp)) {
698 if ((speed = bcode(bp))) {
699 tp->c_cflag &= ~CBAUD;
700 tp->c_cflag |= speed;
706 /* Restore terminal settings. Errors will be dealt with lateron. */
709 tp->c_cc[VMIN] = vmin;
710 (void) ioctl(0, TCSETA, tp);
713 /* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
714 static void do_prompt(struct options *op, struct termio *tp)
716 #ifdef ISSUE /* optional: show /etc/issue */
717 print_login_issue(op->issue, op->tty);
719 print_login_prompt();
722 /* next_speed - select next baud rate */
723 static void next_speed(struct termio *tp, struct options *op)
725 static int baud_index = FIRST_SPEED; /* current speed index */
727 baud_index = (baud_index + 1) % op->numspeed;
728 tp->c_cflag &= ~CBAUD;
729 tp->c_cflag |= op->speeds[baud_index];
730 (void) ioctl(0, TCSETA, tp);
733 /* get_logname - get user name, establish parity, speed, erase, kill, eol */
734 /* return NULL on failure, logname on success */
735 static char *get_logname(struct options *op, struct chardata *cp, struct termio *tp)
737 #define logname bb_common_bufsiz1
739 char c; /* input character, full eight bits */
740 char ascval; /* low 7 bits of input character */
741 int bits; /* # of "1" bits per character */
742 int mask; /* mask with 1 bit up */
743 static char *erase[] = { /* backspace-space-backspace */
744 "\010\040\010", /* space parity */
745 "\010\040\010", /* odd parity */
746 "\210\240\210", /* even parity */
747 "\210\240\210", /* no parity */
750 /* Initialize kill, erase, parity etc. (also after switching speeds). */
754 /* Flush pending input (esp. after parsing or switching the baud rate). */
757 (void) ioctl(0, TCFLSH, TCIFLUSH);
759 /* Prompt for and read a login name. */
761 for (*logname = 0; *logname == 0; /* void */ ) {
763 /* Write issue file and prompt, with "parity" bit == 0. */
767 /* Read name, watch for break, parity, erase, kill, end-of-line. */
769 for (bp = logname, cp->eol = 0; cp->eol == 0; /* void */ ) {
771 /* Do not report trivial EINTR/EIO errors. */
773 if (read(0, &c, 1) < 1) {
774 if (errno == EINTR || errno == EIO)
776 error("%s: read: %m", op->tty);
778 /* Do BREAK handling elsewhere. */
780 if ((c == 0) && op->numspeed > 1)
784 /* Do parity bit handling. */
786 if (c != (ascval = (c & 0177))) { /* "parity" bit on ? */
787 for (bits = 1, mask = 1; mask & 0177; mask <<= 1)
789 bits++; /* count "1" bits */
790 cp->parity |= ((bits & 1) ? 1 : 2);
792 /* Do erase, kill and end-of-line processing. */
797 *bp = 0; /* terminate logname */
798 cp->eol = ascval; /* set end-of-line char */
803 cp->erase = ascval; /* set erase character */
805 (void) write(1, erase[cp->parity], 3);
811 cp->kill = ascval; /* set kill character */
812 while (bp > logname) {
813 (void) write(1, erase[cp->parity], 3);
820 if (!isascii(ascval) || !isprint(ascval)) {
821 /* ignore garbage characters */ ;
822 } else if (bp - logname >= sizeof(logname) - 1) {
823 error("%s: input overrun", op->tty);
825 (void) write(1, &c, 1); /* echo the character */
826 *bp++ = ascval; /* and store it */
832 /* Handle names with upper case and no lower case. */
834 if ((cp->capslock = caps_lock(logname))) {
835 for (bp = logname; *bp; bp++)
837 *bp = tolower(*bp); /* map name to lower case */
842 /* termio_final - set the final tty mode bits */
843 static void termio_final(struct options *op, struct termio *tp, struct chardata *cp)
845 /* General terminal-independent stuff. */
847 tp->c_iflag |= IXON | IXOFF; /* 2-way flow control */
848 tp->c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE;
849 /* no longer| ECHOCTL | ECHOPRT */
850 tp->c_oflag |= OPOST;
851 /* tp->c_cflag = 0; */
852 tp->c_cc[VINTR] = DEF_INTR; /* default interrupt */
853 tp->c_cc[VQUIT] = DEF_QUIT; /* default quit */
854 tp->c_cc[VEOF] = DEF_EOF; /* default EOF character */
855 tp->c_cc[VEOL] = DEF_EOL;
856 tp->c_cc[VSWTC] = DEF_SWITCH; /* default switch character */
858 /* Account for special characters seen in input. */
861 tp->c_iflag |= ICRNL; /* map CR in input to NL */
862 tp->c_oflag |= ONLCR; /* map NL in output to CR-NL */
864 tp->c_cc[VERASE] = cp->erase; /* set erase character */
865 tp->c_cc[VKILL] = cp->kill; /* set kill character */
867 /* Account for the presence or absence of parity bits in input. */
869 switch (cp->parity) {
870 case 0: /* space (always 0) parity */
872 case 1: /* odd parity */
873 tp->c_cflag |= PARODD;
875 case 2: /* even parity */
876 tp->c_cflag |= PARENB;
877 tp->c_iflag |= INPCK | ISTRIP;
879 case (1 | 2): /* no parity bit */
880 tp->c_cflag &= ~CSIZE;
884 /* Account for upper case without lower case. */
887 tp->c_iflag |= IUCLC;
888 tp->c_lflag |= XCASE;
889 tp->c_oflag |= OLCUC;
891 /* Optionally enable hardware flow control */
894 if (op->flags & F_RTSCTS)
895 tp->c_cflag |= CRTSCTS;
898 /* Finally, make the new settings effective */
900 if (ioctl(0, TCSETA, tp) < 0)
901 error("%s: ioctl: TCSETA: %m", op->tty);
904 /* caps_lock - string contains upper case without lower case */
905 /* returns 1 if true, 0 if false */
906 static int caps_lock(const char *s)
910 for (capslock = 0; *s; s++) {
914 capslock = isupper(*s);
919 /* bcode - convert speed string to speed code; return 0 on failure */
920 static int bcode(const char *s)
924 if (safe_strtoul((char *)s, &value)) {
927 if ((r = bb_value_to_baud(value)) > 0) {
934 * output error messages
936 static void error(const char *fmt, ...)
941 #ifdef CONFIG_SYSLOGD
942 va_start(va_alist, fmt);
943 vsnprintf(buf, sizeof(buf), fmt, va_alist);
944 openlog(bb_applet_name, 0, LOG_AUTH);
945 syslog(LOG_ERR, "%s", buf);
951 snprintf(buf, sizeof(buf), "%s: ", bb_applet_name);
953 va_start(va_alist, fmt);
954 vsnprintf(buf + l, sizeof(buf) - l, fmt, va_alist);
956 /* truncate if need */
957 if((l + 3) > sizeof(buf))
959 /* add \r\n always */
963 if ((fd = open("/dev/console", 1)) >= 0) {
971 (void) sleep((unsigned) 10); /* be kind to init(8) */