diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-21 09:22:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-21 09:22:28 +0000 |
commit | 1101d1c98068d7a49942d6e9e11ca2e789a9cdba (patch) | |
tree | 8fcf79323f16e9e29ad0e257184ce4714b29c23b | |
parent | 84c8daa11f4c656bb4ba50b6e1c6d3b34c0f1b39 (diff) | |
download | busybox-w32-1101d1c98068d7a49942d6e9e11ca2e789a9cdba.tar.gz busybox-w32-1101d1c98068d7a49942d6e9e11ca2e789a9cdba.tar.bz2 busybox-w32-1101d1c98068d7a49942d6e9e11ca2e789a9cdba.zip |
telnet: shrink
telnetd: shrink, and fix issue file printing
test: better and shorter usage text
function old new delta
putiac2 51 50 -1
putiac 24 20 -4
handlenetoutput 95 91 -4
telnet_main 1480 1475 -5
iacflush 37 32 -5
make_new_session 436 421 -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-34) Total: -34 bytes
-rw-r--r-- | include/usage.h | 8 | ||||
-rw-r--r-- | networking/telnet.c | 32 | ||||
-rw-r--r-- | networking/telnetd.c | 11 |
3 files changed, 24 insertions, 27 deletions
diff --git a/include/usage.h b/include/usage.h index dbee32eb2..c3ad216d3 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -4015,8 +4015,8 @@ | |||
4015 | #define telnet_full_usage "\n\n" \ | 4015 | #define telnet_full_usage "\n\n" \ |
4016 | "Connect to telnet server\n" \ | 4016 | "Connect to telnet server\n" \ |
4017 | "\nOptions:" \ | 4017 | "\nOptions:" \ |
4018 | "\n -a Attempt an automatic login with USER variable" \ | 4018 | "\n -a Automatic login with $USER variable" \ |
4019 | "\n -l USER Attempt an automatic login with USER argument" \ | 4019 | "\n -l USER Automatic login as USER" \ |
4020 | 4020 | ||
4021 | #else | 4021 | #else |
4022 | #define telnet_trivial_usage \ | 4022 | #define telnet_trivial_usage \ |
@@ -4047,8 +4047,8 @@ | |||
4047 | #define test_trivial_usage \ | 4047 | #define test_trivial_usage \ |
4048 | "EXPRESSION ]" | 4048 | "EXPRESSION ]" |
4049 | #define test_full_usage "\n\n" \ | 4049 | #define test_full_usage "\n\n" \ |
4050 | "Check file types and compares values returning an exit code\n" \ | 4050 | "Check file types, compare values etc. Return a 0/1 exit code\n" \ |
4051 | "determined by the value of EXPRESSION" | 4051 | "depending on logical value of EXPRESSION" |
4052 | #define test_example_usage \ | 4052 | #define test_example_usage \ |
4053 | "$ test 1 -eq 2\n" \ | 4053 | "$ test 1 -eq 2\n" \ |
4054 | "$ echo $?\n" \ | 4054 | "$ echo $?\n" \ |
diff --git a/networking/telnet.c b/networking/telnet.c index aaaa2648f..63ee38088 100644 --- a/networking/telnet.c +++ b/networking/telnet.c | |||
@@ -52,9 +52,10 @@ enum { | |||
52 | 52 | ||
53 | typedef unsigned char byte; | 53 | typedef unsigned char byte; |
54 | 54 | ||
55 | enum { netfd = 3 }; | ||
56 | |||
55 | struct globals { | 57 | struct globals { |
56 | int netfd; /* console fd:s are 0 and 1 (and 2) */ | 58 | int iaclen; /* could even use byte, but it's a loss on x86 */ |
57 | short iaclen; /* could even use byte */ | ||
58 | byte telstate; /* telnet negotiation state from network input */ | 59 | byte telstate; /* telnet negotiation state from network input */ |
59 | byte telwish; /* DO, DONT, WILL, WONT */ | 60 | byte telwish; /* DO, DONT, WILL, WONT */ |
60 | byte charmode; | 61 | byte charmode; |
@@ -95,7 +96,7 @@ static int subneg(byte c); | |||
95 | 96 | ||
96 | static void iacflush(void) | 97 | static void iacflush(void) |
97 | { | 98 | { |
98 | write(G.netfd, G.iacbuf, G.iaclen); | 99 | write(netfd, G.iacbuf, G.iaclen); |
99 | G.iaclen = 0; | 100 | G.iaclen = 0; |
100 | } | 101 | } |
101 | 102 | ||
@@ -191,7 +192,7 @@ static void handlenetoutput(int len) | |||
191 | outbuf[j++] = 0x00; | 192 | outbuf[j++] = 0x00; |
192 | } | 193 | } |
193 | if (j > 0) | 194 | if (j > 0) |
194 | write(G.netfd, outbuf, j); | 195 | write(netfd, outbuf, j); |
195 | } | 196 | } |
196 | 197 | ||
197 | static void handlenetinput(int len) | 198 | static void handlenetinput(int len) |
@@ -545,7 +546,7 @@ static void cookmode(void) | |||
545 | #define USE_POLL 1 | 546 | #define USE_POLL 1 |
546 | 547 | ||
547 | int telnet_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 548 | int telnet_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
548 | int telnet_main(int argc, char **argv) | 549 | int telnet_main(int argc UNUSED_PARAM, char **argv) |
549 | { | 550 | { |
550 | char *host; | 551 | char *host; |
551 | int port; | 552 | int port; |
@@ -573,9 +574,6 @@ int telnet_main(int argc, char **argv) | |||
573 | cfmakeraw(&G.termios_raw); | 574 | cfmakeraw(&G.termios_raw); |
574 | } | 575 | } |
575 | 576 | ||
576 | if (argc < 2) | ||
577 | bb_show_usage(); | ||
578 | |||
579 | #if ENABLE_FEATURE_TELNET_AUTOLOGIN | 577 | #if ENABLE_FEATURE_TELNET_AUTOLOGIN |
580 | if (1 & getopt32(argv, "al:", &G.autologin)) | 578 | if (1 & getopt32(argv, "al:", &G.autologin)) |
581 | G.autologin = getenv("USER"); | 579 | G.autologin = getenv("USER"); |
@@ -590,20 +588,20 @@ int telnet_main(int argc, char **argv) | |||
590 | if (*argv) /* extra params?? */ | 588 | if (*argv) /* extra params?? */ |
591 | bb_show_usage(); | 589 | bb_show_usage(); |
592 | 590 | ||
593 | G.netfd = create_and_connect_stream_or_die(host, port); | 591 | xmove_fd(create_and_connect_stream_or_die(host, port), netfd); |
594 | 592 | ||
595 | setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); | 593 | setsockopt(netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); |
596 | 594 | ||
597 | signal(SIGINT, fgotsig); | 595 | signal(SIGINT, fgotsig); |
598 | 596 | ||
599 | #ifdef USE_POLL | 597 | #ifdef USE_POLL |
600 | ufds[0].fd = 0; ufds[1].fd = G.netfd; | 598 | ufds[0].fd = 0; ufds[1].fd = netfd; |
601 | ufds[0].events = ufds[1].events = POLLIN; | 599 | ufds[0].events = ufds[1].events = POLLIN; |
602 | #else | 600 | #else |
603 | FD_ZERO(&readfds); | 601 | FD_ZERO(&readfds); |
604 | FD_SET(STDIN_FILENO, &readfds); | 602 | FD_SET(STDIN_FILENO, &readfds); |
605 | FD_SET(G.netfd, &readfds); | 603 | FD_SET(netfd, &readfds); |
606 | maxfd = G.netfd + 1; | 604 | maxfd = netfd + 1; |
607 | #endif | 605 | #endif |
608 | 606 | ||
609 | while (1) { | 607 | while (1) { |
@@ -642,17 +640,17 @@ int telnet_main(int argc, char **argv) | |||
642 | #ifdef USE_POLL | 640 | #ifdef USE_POLL |
643 | if (ufds[1].revents) /* well, should check POLLIN, but ... */ | 641 | if (ufds[1].revents) /* well, should check POLLIN, but ... */ |
644 | #else | 642 | #else |
645 | if (FD_ISSET(G.netfd, &rfds)) | 643 | if (FD_ISSET(netfd, &rfds)) |
646 | #endif | 644 | #endif |
647 | { | 645 | { |
648 | len = read(G.netfd, G.buf, DATABUFSIZE); | 646 | len = read(netfd, G.buf, DATABUFSIZE); |
649 | if (len <= 0) { | 647 | if (len <= 0) { |
650 | write_str(1, "Connection closed by foreign host\r\n"); | 648 | write_str(1, "Connection closed by foreign host\r\n"); |
651 | doexit(EXIT_FAILURE); | 649 | doexit(EXIT_FAILURE); |
652 | } | 650 | } |
653 | TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len)); | 651 | TRACE(0, ("Read netfd (%d): %d\n", netfd, len)); |
654 | handlenetinput(len); | 652 | handlenetinput(len); |
655 | } | 653 | } |
656 | } | 654 | } |
657 | } | 655 | } /* while (1) */ |
658 | } | 656 | } |
diff --git a/networking/telnetd.c b/networking/telnetd.c index 22ecb3ca8..7f748641b 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -229,11 +229,10 @@ make_new_session( | |||
229 | /* open the child's side of the tty. */ | 229 | /* open the child's side of the tty. */ |
230 | /* NB: setsid() disconnects from any previous ctty's. Therefore | 230 | /* NB: setsid() disconnects from any previous ctty's. Therefore |
231 | * we must open child's side of the tty AFTER setsid! */ | 231 | * we must open child's side of the tty AFTER setsid! */ |
232 | fd = xopen(tty_name, O_RDWR); /* becomes our ctty */ | 232 | close(0); |
233 | dup2(fd, 0); | 233 | xopen(tty_name, O_RDWR); /* becomes our ctty */ |
234 | dup2(fd, 1); | 234 | xdup2(0, 1); |
235 | dup2(fd, 2); | 235 | xdup2(0, 2); |
236 | while (fd > 2) close(fd--); | ||
237 | tcsetpgrp(0, getpid()); /* switch this tty's process group to us */ | 236 | tcsetpgrp(0, getpid()); /* switch this tty's process group to us */ |
238 | 237 | ||
239 | /* The pseudo-terminal allocated to the client is configured to operate in | 238 | /* The pseudo-terminal allocated to the client is configured to operate in |
@@ -252,7 +251,7 @@ make_new_session( | |||
252 | * issue files, and they may block writing to fd 1, | 251 | * issue files, and they may block writing to fd 1, |
253 | * (parent is supposed to read it, but parent waits | 252 | * (parent is supposed to read it, but parent waits |
254 | * for vforked child to exec!) */ | 253 | * for vforked child to exec!) */ |
255 | print_login_issue(issuefile, NULL); | 254 | print_login_issue(issuefile, tty_name); |
256 | 255 | ||
257 | /* Exec shell / login / whatever */ | 256 | /* Exec shell / login / whatever */ |
258 | login_argv[0] = loginpath; | 257 | login_argv[0] = loginpath; |