diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-23 02:11:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-23 02:11:22 +0000 |
commit | 50e77e1cc12d18716d1ab371ba4b145706e5192d (patch) | |
tree | 3106d2220086d8a0e5075775dde088014aafe708 | |
parent | dce3fde4148690e0323d36fbd1aa2e87a1316a49 (diff) | |
download | busybox-w32-50e77e1cc12d18716d1ab371ba4b145706e5192d.tar.gz busybox-w32-50e77e1cc12d18716d1ab371ba4b145706e5192d.tar.bz2 busybox-w32-50e77e1cc12d18716d1ab371ba4b145706e5192d.zip |
getty: cleanup part 2
-rw-r--r-- | loginutils/getty.c | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/loginutils/getty.c b/loginutils/getty.c index f2bff061e..ebca480bf 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -23,13 +23,6 @@ | |||
23 | #include <utmp.h> | 23 | #include <utmp.h> |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #define _PATH_LOGIN "/bin/login" | ||
27 | |||
28 | #ifdef CONFIG_SYSLOGD | ||
29 | #include <sys/param.h> | ||
30 | #endif | ||
31 | |||
32 | |||
33 | /* | 26 | /* |
34 | * Some heuristics to find out what environment we are in: if it is not | 27 | * Some heuristics to find out what environment we are in: if it is not |
35 | * System V, assume it is SunOS 4. | 28 | * System V, assume it is SunOS 4. |
@@ -42,6 +35,11 @@ extern void updwtmp(const char *filename, const struct utmp *ut); | |||
42 | #endif | 35 | #endif |
43 | #endif /* LOGIN_PROCESS */ | 36 | #endif /* LOGIN_PROCESS */ |
44 | 37 | ||
38 | #ifdef SYSV_STYLE | ||
39 | #include <sys/utsname.h> | ||
40 | #include <time.h> | ||
41 | #endif | ||
42 | |||
45 | /* | 43 | /* |
46 | * Things you may want to modify. | 44 | * Things you may want to modify. |
47 | * | 45 | * |
@@ -50,10 +48,7 @@ extern void updwtmp(const char *filename, const struct utmp *ut); | |||
50 | * and for line editing at the same time. | 48 | * and for line editing at the same time. |
51 | */ | 49 | */ |
52 | 50 | ||
53 | #ifdef SYSV_STYLE | 51 | #define _PATH_LOGIN "/bin/login" |
54 | #include <sys/utsname.h> | ||
55 | #include <time.h> | ||
56 | #endif | ||
57 | 52 | ||
58 | /* If ISSUE is not defined, agetty will never display the contents of the | 53 | /* If ISSUE is not defined, agetty will never display the contents of the |
59 | * /etc/issue file. You will not want to spit out large "issue" files at the | 54 | * /etc/issue file. You will not want to spit out large "issue" files at the |
@@ -218,7 +213,7 @@ static char *fakehost = NULL; | |||
218 | #define DEBUGTERM "/dev/ttyp0" | 213 | #define DEBUGTERM "/dev/ttyp0" |
219 | FILE *dbf; | 214 | FILE *dbf; |
220 | #else | 215 | #else |
221 | #define debug(s) /* nothing */ | 216 | #define debug(s) /* nothing */ |
222 | #endif | 217 | #endif |
223 | 218 | ||
224 | 219 | ||
@@ -299,7 +294,7 @@ static void parse_args(int argc, char **argv, struct options *op) | |||
299 | parse_speeds(op, argv[1]); /* baud rate(s) */ | 294 | parse_speeds(op, argv[1]); /* baud rate(s) */ |
300 | } | 295 | } |
301 | 296 | ||
302 | if (argc > 2 && argv[2]) | 297 | if (argv[2]) |
303 | setenv("TERM", argv[2], 1); | 298 | setenv("TERM", argv[2], 1); |
304 | 299 | ||
305 | debug("exiting parseargs\n"); | 300 | debug("exiting parseargs\n"); |
@@ -406,8 +401,8 @@ static void open_tty(char *tty, struct termio *tp, int local) | |||
406 | } | 401 | } |
407 | } | 402 | } |
408 | #else | 403 | #else |
409 | (void) chown(tty, 0, 0); /* root, sys */ | 404 | chown(tty, 0, 0); /* root, sys */ |
410 | (void) chmod(tty, 0622); /* crw--w--w- */ | 405 | chmod(tty, 0622); /* crw--w--w- */ |
411 | #endif | 406 | #endif |
412 | if (chdir_to_root) | 407 | if (chdir_to_root) |
413 | xchdir("/"); | 408 | xchdir("/"); |
@@ -424,7 +419,7 @@ static void termio_init(struct termio *tp, int speed, struct options *op) | |||
424 | */ | 419 | */ |
425 | #ifdef __linux__ | 420 | #ifdef __linux__ |
426 | /* flush input and output queues, important for modems! */ | 421 | /* flush input and output queues, important for modems! */ |
427 | (void) ioctl(0, TCFLSH, TCIOFLUSH); | 422 | ioctl(0, TCFLSH, TCIOFLUSH); |
428 | #endif | 423 | #endif |
429 | 424 | ||
430 | tp->c_cflag = CS8 | HUPCL | CREAD | speed; | 425 | tp->c_cflag = CS8 | HUPCL | CREAD | speed; |
@@ -444,7 +439,7 @@ static void termio_init(struct termio *tp, int speed, struct options *op) | |||
444 | tp->c_cflag |= CRTSCTS; | 439 | tp->c_cflag |= CRTSCTS; |
445 | #endif | 440 | #endif |
446 | 441 | ||
447 | (void) ioctl(0, TCSETA, tp); | 442 | ioctl(0, TCSETA, tp); |
448 | 443 | ||
449 | /* go to blocking input even in local mode */ | 444 | /* go to blocking input even in local mode */ |
450 | fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~O_NONBLOCK); | 445 | fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~O_NONBLOCK); |
@@ -486,14 +481,14 @@ static void auto_baud(struct termio *tp) | |||
486 | tp->c_iflag |= ISTRIP; /* enable 8th-bit stripping */ | 481 | tp->c_iflag |= ISTRIP; /* enable 8th-bit stripping */ |
487 | vmin = tp->c_cc[VMIN]; | 482 | vmin = tp->c_cc[VMIN]; |
488 | tp->c_cc[VMIN] = 0; /* don't block if queue empty */ | 483 | tp->c_cc[VMIN] = 0; /* don't block if queue empty */ |
489 | (void) ioctl(0, TCSETA, tp); | 484 | ioctl(0, TCSETA, tp); |
490 | 485 | ||
491 | /* | 486 | /* |
492 | * Wait for a while, then read everything the modem has said so far and | 487 | * Wait for a while, then read everything the modem has said so far and |
493 | * try to extract the speed of the dial-in call. | 488 | * try to extract the speed of the dial-in call. |
494 | */ | 489 | */ |
495 | 490 | ||
496 | (void) sleep(1); | 491 | sleep(1); |
497 | nread = read(0, buf, sizeof(buf) - 1); | 492 | nread = read(0, buf, sizeof(buf) - 1); |
498 | if (nread > 0) { | 493 | if (nread > 0) { |
499 | buf[nread] = '\0'; | 494 | buf[nread] = '\0'; |
@@ -512,7 +507,7 @@ static void auto_baud(struct termio *tp) | |||
512 | 507 | ||
513 | tp->c_iflag = iflag; | 508 | tp->c_iflag = iflag; |
514 | tp->c_cc[VMIN] = vmin; | 509 | tp->c_cc[VMIN] = vmin; |
515 | (void) ioctl(0, TCSETA, tp); | 510 | ioctl(0, TCSETA, tp); |
516 | } | 511 | } |
517 | 512 | ||
518 | /* next_speed - select next baud rate */ | 513 | /* next_speed - select next baud rate */ |
@@ -523,7 +518,7 @@ static void next_speed(struct termio *tp, struct options *op) | |||
523 | baud_index = (baud_index + 1) % op->numspeed; | 518 | baud_index = (baud_index + 1) % op->numspeed; |
524 | tp->c_cflag &= ~CBAUD; | 519 | tp->c_cflag &= ~CBAUD; |
525 | tp->c_cflag |= op->speeds[baud_index]; | 520 | tp->c_cflag |= op->speeds[baud_index]; |
526 | (void) ioctl(0, TCSETA, tp); | 521 | ioctl(0, TCSETA, tp); |
527 | } | 522 | } |
528 | 523 | ||
529 | 524 | ||
@@ -569,8 +564,8 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio | |||
569 | 564 | ||
570 | /* Flush pending input (esp. after parsing or switching the baud rate). */ | 565 | /* Flush pending input (esp. after parsing or switching the baud rate). */ |
571 | 566 | ||
572 | (void) sleep(1); | 567 | sleep(1); |
573 | (void) ioctl(0, TCFLSH, TCIFLUSH); | 568 | ioctl(0, TCFLSH, TCIFLUSH); |
574 | 569 | ||
575 | /* Prompt for and read a login name. */ | 570 | /* Prompt for and read a login name. */ |
576 | 571 | ||
@@ -621,7 +616,7 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio | |||
621 | case '#': | 616 | case '#': |
622 | cp->erase = ascval; /* set erase character */ | 617 | cp->erase = ascval; /* set erase character */ |
623 | if (bp > logname) { | 618 | if (bp > logname) { |
624 | (void) write(1, erase[cp->parity], 3); | 619 | write(1, erase[cp->parity], 3); |
625 | bp--; | 620 | bp--; |
626 | } | 621 | } |
627 | break; | 622 | break; |
@@ -629,7 +624,7 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio | |||
629 | case '@': | 624 | case '@': |
630 | cp->kill = ascval; /* set kill character */ | 625 | cp->kill = ascval; /* set kill character */ |
631 | while (bp > logname) { | 626 | while (bp > logname) { |
632 | (void) write(1, erase[cp->parity], 3); | 627 | write(1, erase[cp->parity], 3); |
633 | bp--; | 628 | bp--; |
634 | } | 629 | } |
635 | break; | 630 | break; |
@@ -641,7 +636,7 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio | |||
641 | } else if (bp - logname >= sizeof(logname) - 1) { | 636 | } else if (bp - logname >= sizeof(logname) - 1) { |
642 | bb_error_msg_and_die("%s: input overrun", op->tty); | 637 | bb_error_msg_and_die("%s: input overrun", op->tty); |
643 | } else { | 638 | } else { |
644 | (void) write(1, &c, 1); /* echo the character */ | 639 | write(1, &c, 1); /* echo the character */ |
645 | *bp++ = ascval; /* and store it */ | 640 | *bp++ = ascval; /* and store it */ |
646 | } | 641 | } |
647 | break; | 642 | break; |
@@ -789,9 +784,11 @@ int getty_main(int argc, char **argv) | |||
789 | { | 784 | { |
790 | int nullfd; | 785 | int nullfd; |
791 | char *logname = NULL; /* login name, given to /bin/login */ | 786 | char *logname = NULL; /* login name, given to /bin/login */ |
787 | // TODO: we can merge these into "struct local" | ||
788 | // (will reduce parameter passing) | ||
792 | struct chardata chardata; /* set by get_logname() */ | 789 | struct chardata chardata; /* set by get_logname() */ |
793 | struct termio termio; /* terminal mode bits */ | 790 | struct termio termio; /* terminal mode bits */ |
794 | static struct options options = { | 791 | struct options options = { |
795 | 0, /* show /etc/issue (SYSV_STYLE) */ | 792 | 0, /* show /etc/issue (SYSV_STYLE) */ |
796 | 0, /* no timeout */ | 793 | 0, /* no timeout */ |
797 | _PATH_LOGIN, /* default login program */ | 794 | _PATH_LOGIN, /* default login program */ |
@@ -886,7 +883,7 @@ int getty_main(int argc, char **argv) | |||
886 | 883 | ||
887 | /* Set the optional timer. */ | 884 | /* Set the optional timer. */ |
888 | if (options.timeout) | 885 | if (options.timeout) |
889 | (void) alarm(options.timeout); | 886 | alarm(options.timeout); |
890 | 887 | ||
891 | /* optionally wait for CR or LF before writing /etc/issue */ | 888 | /* optionally wait for CR or LF before writing /etc/issue */ |
892 | if (options.flags & F_WAITCRLF) { | 889 | if (options.flags & F_WAITCRLF) { |
@@ -916,7 +913,7 @@ int getty_main(int argc, char **argv) | |||
916 | /* Disable timer. */ | 913 | /* Disable timer. */ |
917 | 914 | ||
918 | if (options.timeout) | 915 | if (options.timeout) |
919 | (void) alarm(0); | 916 | alarm(0); |
920 | 917 | ||
921 | /* Finalize the termio settings. */ | 918 | /* Finalize the termio settings. */ |
922 | 919 | ||
@@ -924,10 +921,10 @@ int getty_main(int argc, char **argv) | |||
924 | 921 | ||
925 | /* Now the newline character should be properly written. */ | 922 | /* Now the newline character should be properly written. */ |
926 | 923 | ||
927 | (void) write(1, "\n", 1); | 924 | write(1, "\n", 1); |
928 | 925 | ||
929 | /* Let the login program take care of password validation. */ | 926 | /* Let the login program take care of password validation. */ |
930 | 927 | ||
931 | (void) execl(options.login, options.login, "--", logname, (char *) 0); | 928 | execl(options.login, options.login, "--", logname, (char *) 0); |
932 | bb_error_msg_and_die("%s: can't exec %s", options.tty, options.login); | 929 | bb_error_msg_and_die("%s: can't exec %s", options.tty, options.login); |
933 | } | 930 | } |