diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-12 23:13:50 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-12 23:13:50 +0000 |
| commit | 4cf1d08fc2e50f9abda999d468c5e972ff4995c2 (patch) | |
| tree | 58dd8efdd7d0f0990d30d8b5f5f53cf2ee35d444 /miscutils | |
| parent | 4e6d5117b839cef41cd3919966f95bf25d24d8d9 (diff) | |
| download | busybox-w32-4cf1d08fc2e50f9abda999d468c5e972ff4995c2.tar.gz busybox-w32-4cf1d08fc2e50f9abda999d468c5e972ff4995c2.tar.bz2 busybox-w32-4cf1d08fc2e50f9abda999d468c5e972ff4995c2.zip | |
nc: remove a bit of bloat
inetd: more NOMMU fixes
rx: shrink
devfsd: minor shrink
vlock: shrink
tcpudp: narrow down window where we have no wildcard socket
parse_one_line 1015 1102 +87
init_ring - 53 +53
xzalloc_lsa - 48 +48
read_byte 51 50 -1
rearm_alarm 28 25 -3
nc_main 1028 1000 -28
initring 53 - -53
vlock_main 583 496 -87
reread_config_file 1089 991 -98
rx_main 1046 912 -134
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/6 up/down: 188/-404) Total: -216 bytes
text data bss dec hex filename
800120 661 7428 808209 c5511 busybox_old
799796 661 7428 807885 c53cd busybox_unstripped
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/devfsd.c | 9 | ||||
| -rw-r--r-- | miscutils/rx.c | 232 |
2 files changed, 103 insertions, 138 deletions
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 286f00fd8..50c8203cb 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c | |||
| @@ -386,15 +386,14 @@ int devfsd_main(int argc, char **argv) | |||
| 386 | /* Tell kernel we are special(i.e. we get to see hidden entries) */ | 386 | /* Tell kernel we are special(i.e. we get to see hidden entries) */ |
| 387 | xioctl(fd, DEVFSDIOC_SET_EVENT_MASK, 0); | 387 | xioctl(fd, DEVFSDIOC_SET_EVENT_MASK, 0); |
| 388 | 388 | ||
| 389 | /* Set up SIGHUP and SIGUSR1 handlers */ | ||
| 389 | sigemptyset(&new_action.sa_mask); | 390 | sigemptyset(&new_action.sa_mask); |
| 390 | new_action.sa_flags = 0; | 391 | new_action.sa_flags = 0; |
| 391 | |||
| 392 | /* Set up SIGHUP and SIGUSR1 handlers */ | ||
| 393 | new_action.sa_handler = signal_handler; | 392 | new_action.sa_handler = signal_handler; |
| 394 | if (sigaction(SIGHUP, &new_action, NULL) != 0 || sigaction(SIGUSR1, &new_action, NULL) != 0) | 393 | sigaction(SIGHUP, &new_action, NULL); |
| 395 | bb_error_msg_and_die("sigaction"); | 394 | sigaction(SIGUSR1, &new_action, NULL); |
| 396 | 395 | ||
| 397 | printf("%s v%s started for %s\n",applet_name, DEVFSD_VERSION, mount_point); | 396 | printf("%s v%s started for %s\n", applet_name, DEVFSD_VERSION, mount_point); |
| 398 | 397 | ||
| 399 | /* Set umask so that mknod(2), open(2) and mkdir(2) have complete control over permissions */ | 398 | /* Set umask so that mknod(2), open(2) and mkdir(2) have complete control over permissions */ |
| 400 | umask(0); | 399 | umask(0); |
diff --git a/miscutils/rx.c b/miscutils/rx.c index 8ccea4974..9a8fcaa20 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c | |||
| @@ -16,7 +16,6 @@ | |||
| 16 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 16 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 17 | * | 17 | * |
| 18 | * This was originally written for blob and then adapted for busybox. | 18 | * This was originally written for blob and then adapted for busybox. |
| 19 | * | ||
| 20 | */ | 19 | */ |
| 21 | 20 | ||
| 22 | #include "libbb.h" | 21 | #include "libbb.h" |
| @@ -29,66 +28,59 @@ | |||
| 29 | #define BS 0x08 | 28 | #define BS 0x08 |
| 30 | 29 | ||
| 31 | /* | 30 | /* |
| 32 | |||
| 33 | Cf: | 31 | Cf: |
| 34 | |||
| 35 | http://www.textfiles.com/apple/xmodem | 32 | http://www.textfiles.com/apple/xmodem |
| 36 | http://www.phys.washington.edu/~belonis/xmodem/docxmodem.txt | 33 | http://www.phys.washington.edu/~belonis/xmodem/docxmodem.txt |
| 37 | http://www.phys.washington.edu/~belonis/xmodem/docymodem.txt | 34 | http://www.phys.washington.edu/~belonis/xmodem/docymodem.txt |
| 38 | http://www.phys.washington.edu/~belonis/xmodem/modmprot.col | 35 | http://www.phys.washington.edu/~belonis/xmodem/modmprot.col |
| 39 | |||
| 40 | */ | 36 | */ |
| 41 | 37 | ||
| 42 | #define TIMEOUT 1 | 38 | #define TIMEOUT 1 |
| 43 | #define TIMEOUT_LONG 10 | 39 | #define TIMEOUT_LONG 10 |
| 44 | #define MAXERRORS 10 | 40 | #define MAXERRORS 10 |
| 45 | 41 | ||
| 46 | static int read_byte(int fd, unsigned timeout) | 42 | #define read_fd STDIN_FILENO |
| 43 | #define write_fd STDOUT_FILENO | ||
| 44 | |||
| 45 | static int read_byte(unsigned timeout) | ||
| 47 | { | 46 | { |
| 48 | char buf[1]; | 47 | char buf[1]; |
| 49 | int n; | 48 | int n; |
| 50 | 49 | ||
| 51 | alarm(timeout); | 50 | alarm(timeout); |
| 52 | 51 | /* NOT safe_read! We want ALRM to interrupt us */ | |
| 53 | n = read(fd, &buf, 1); | 52 | n = read(read_fd, buf, 1); |
| 54 | |||
| 55 | alarm(0); | 53 | alarm(0); |
| 56 | |||
| 57 | if (n == 1) | 54 | if (n == 1) |
| 58 | return buf[0] & 0xff; | 55 | return (unsigned char)buf[0]; |
| 59 | else | 56 | return -1; |
| 60 | return -1; | ||
| 61 | } | 57 | } |
| 62 | 58 | ||
| 63 | static int receive(char *error_buf, size_t error_buf_size, | 59 | static int receive(/*int read_fd, */int file_fd) |
| 64 | int ttyfd, int filefd) | ||
| 65 | { | 60 | { |
| 66 | char blockBuf[1024]; | 61 | unsigned char blockBuf[1024]; |
| 67 | unsigned int errors = 0; | 62 | unsigned errors = 0; |
| 68 | unsigned int wantBlockNo = 1; | 63 | unsigned wantBlockNo = 1; |
| 69 | unsigned int length = 0; | 64 | unsigned length = 0; |
| 70 | int docrc = 1; | 65 | int do_crc = 1; |
| 71 | char nak = 'C'; | 66 | char nak = 'C'; |
| 72 | unsigned int timeout = TIMEOUT_LONG; | 67 | unsigned timeout = TIMEOUT_LONG; |
| 73 | |||
| 74 | #define note_error(fmt,args...) \ | ||
| 75 | snprintf(error_buf, error_buf_size, fmt,##args) | ||
| 76 | 68 | ||
| 77 | /* Flush pending input */ | 69 | /* Flush pending input */ |
| 78 | tcflush(ttyfd, TCIFLUSH); | 70 | tcflush(read_fd, TCIFLUSH); |
| 79 | 71 | ||
| 80 | /* Ask for CRC; if we get errors, we will go with checksum */ | 72 | /* Ask for CRC; if we get errors, we will go with checksum */ |
| 81 | write(ttyfd, &nak, 1); | 73 | full_write(write_fd, &nak, 1); |
| 82 | 74 | ||
| 83 | for (;;) { | 75 | for (;;) { |
| 84 | int blockBegin; | 76 | int blockBegin; |
| 85 | int blockNo, blockNoOnesCompl; | 77 | int blockNo, blockNoOnesCompl; |
| 86 | int blockLength; | 78 | int blockLength; |
| 87 | int cksum = 0; | 79 | int cksum_crc; /* cksum OR crc */ |
| 88 | int crcHi = 0; | 80 | int expected; |
| 89 | int crcLo = 0; | 81 | int i,j; |
| 90 | 82 | ||
| 91 | blockBegin = read_byte(ttyfd, timeout); | 83 | blockBegin = read_byte(timeout); |
| 92 | if (blockBegin < 0) | 84 | if (blockBegin < 0) |
| 93 | goto timeout; | 85 | goto timeout; |
| 94 | 86 | ||
| @@ -102,52 +94,47 @@ static int receive(char *error_buf, size_t error_buf_size, | |||
| 102 | 94 | ||
| 103 | case EOT: | 95 | case EOT: |
| 104 | nak = ACK; | 96 | nak = ACK; |
| 105 | write(ttyfd, &nak, 1); | 97 | full_write(write_fd, &nak, 1); |
| 106 | goto done; | 98 | return length; |
| 107 | 99 | ||
| 108 | default: | 100 | default: |
| 109 | goto error; | 101 | goto error; |
| 110 | } | 102 | } |
| 111 | 103 | ||
| 112 | /* block no */ | 104 | /* block no */ |
| 113 | blockNo = read_byte(ttyfd, TIMEOUT); | 105 | blockNo = read_byte(TIMEOUT); |
| 114 | if (blockNo < 0) | 106 | if (blockNo < 0) |
| 115 | goto timeout; | 107 | goto timeout; |
| 116 | 108 | ||
| 117 | /* block no one's compliment */ | 109 | /* block no one's compliment */ |
| 118 | blockNoOnesCompl = read_byte(ttyfd, TIMEOUT); | 110 | blockNoOnesCompl = read_byte(TIMEOUT); |
| 119 | if (blockNoOnesCompl < 0) | 111 | if (blockNoOnesCompl < 0) |
| 120 | goto timeout; | 112 | goto timeout; |
| 121 | 113 | ||
| 122 | if (blockNo != (255 - blockNoOnesCompl)) { | 114 | if (blockNo != (255 - blockNoOnesCompl)) { |
| 123 | note_error("bad block ones compl"); | 115 | bb_error_msg("bad block ones compl"); |
| 124 | goto error; | 116 | goto error; |
| 125 | } | 117 | } |
| 126 | 118 | ||
| 127 | blockLength = (blockBegin == SOH) ? 128 : 1024; | 119 | blockLength = (blockBegin == SOH) ? 128 : 1024; |
| 128 | 120 | ||
| 129 | { | 121 | for (i = 0; i < blockLength; i++) { |
| 130 | int i; | 122 | int cc = read_byte(TIMEOUT); |
| 131 | 123 | if (cc < 0) | |
| 132 | for (i = 0; i < blockLength; i++) { | 124 | goto timeout; |
| 133 | int cc = read_byte(ttyfd, TIMEOUT); | 125 | blockBuf[i] = cc; |
| 134 | if (cc < 0) | ||
| 135 | goto timeout; | ||
| 136 | blockBuf[i] = cc; | ||
| 137 | } | ||
| 138 | } | 126 | } |
| 139 | 127 | ||
| 140 | if (docrc) { | 128 | if (do_crc) { |
| 141 | crcHi = read_byte(ttyfd, TIMEOUT); | 129 | cksum_crc = read_byte(TIMEOUT); |
| 142 | if (crcHi < 0) | 130 | if (cksum_crc < 0) |
| 143 | goto timeout; | 131 | goto timeout; |
| 144 | 132 | cksum_crc = (cksum_crc << 8) | read_byte(TIMEOUT); | |
| 145 | crcLo = read_byte(ttyfd, TIMEOUT); | 133 | if (cksum_crc < 0) |
| 146 | if (crcLo < 0) | ||
| 147 | goto timeout; | 134 | goto timeout; |
| 148 | } else { | 135 | } else { |
| 149 | cksum = read_byte(ttyfd, TIMEOUT); | 136 | cksum_crc = read_byte(TIMEOUT); |
| 150 | if (cksum < 0) | 137 | if (cksum_crc < 0) |
| 151 | goto timeout; | 138 | goto timeout; |
| 152 | } | 139 | } |
| 153 | 140 | ||
| @@ -156,93 +143,74 @@ static int receive(char *error_buf, size_t error_buf_size, | |||
| 156 | /* this also ignores the initial block 0 which is */ | 143 | /* this also ignores the initial block 0 which is */ |
| 157 | /* meta data. */ | 144 | /* meta data. */ |
| 158 | goto next; | 145 | goto next; |
| 159 | } else if (blockNo != (wantBlockNo & 0xff)) { | 146 | } |
| 160 | note_error("unexpected block no, 0x%08x, expecting 0x%08x", blockNo, wantBlockNo); | 147 | if (blockNo != (wantBlockNo & 0xff)) { |
| 148 | bb_error_msg("unexpected block no, 0x%08x, expecting 0x%08x", blockNo, wantBlockNo); | ||
| 161 | goto error; | 149 | goto error; |
| 162 | } | 150 | } |
| 163 | 151 | ||
| 164 | if (docrc) { | 152 | expected = 0; |
| 165 | int crc = 0; | 153 | if (do_crc) { |
| 166 | int i, j; | ||
| 167 | int expectedCrcHi; | ||
| 168 | int expectedCrcLo; | ||
| 169 | |||
| 170 | for (i = 0; i < blockLength; i++) { | 154 | for (i = 0; i < blockLength; i++) { |
| 171 | crc = crc ^ (int) blockBuf[i] << 8; | 155 | expected = expected ^ blockBuf[i] << 8; |
| 172 | for (j = 0; j < 8; j++) | 156 | for (j = 0; j < 8; j++) { |
| 173 | if (crc & 0x8000) | 157 | if (expected & 0x8000) |
| 174 | crc = crc << 1 ^ 0x1021; | 158 | expected = expected << 1 ^ 0x1021; |
| 175 | else | 159 | else |
| 176 | crc = crc << 1; | 160 | expected = expected << 1; |
| 177 | } | 161 | } |
| 178 | |||
| 179 | expectedCrcHi = (crc >> 8) & 0xff; | ||
| 180 | expectedCrcLo = crc & 0xff; | ||
| 181 | |||
| 182 | if ((crcHi != expectedCrcHi) || | ||
| 183 | (crcLo != expectedCrcLo)) { | ||
| 184 | note_error("crc error, expected 0x%02x 0x%02x, got 0x%02x 0x%02x", expectedCrcHi, expectedCrcLo, crcHi, crcLo); | ||
| 185 | goto error; | ||
| 186 | } | 162 | } |
| 163 | expected &= 0xffff; | ||
| 187 | } else { | 164 | } else { |
| 188 | unsigned char expectedCksum = 0; | ||
| 189 | int i; | ||
| 190 | |||
| 191 | for (i = 0; i < blockLength; i++) | 165 | for (i = 0; i < blockLength; i++) |
| 192 | expectedCksum += blockBuf[i]; | 166 | expected += blockBuf[i]; |
| 193 | 167 | expected &= 0xff; | |
| 194 | if (cksum != expectedCksum) { | 168 | } |
| 195 | note_error("checksum error, expected 0x%02x, got 0x%02x", expectedCksum, cksum); | 169 | if (cksum_crc != expected) { |
| 196 | goto error; | 170 | bb_error_msg(do_crc ? "crc error, expected 0x%04x, got 0x%04x" |
| 197 | } | 171 | : "checksum error, expected 0x%02x, got 0x%02x", |
| 172 | expected, cksum_crc); | ||
| 173 | goto error; | ||
| 198 | } | 174 | } |
| 199 | 175 | ||
| 200 | wantBlockNo++; | 176 | wantBlockNo++; |
| 201 | length += blockLength; | 177 | length += blockLength; |
| 202 | 178 | ||
| 203 | if (full_write(filefd, blockBuf, blockLength) < 0) { | 179 | errno = 0; |
| 204 | note_error("write to file failed: %m"); | 180 | if (full_write(file_fd, blockBuf, blockLength) != blockLength) { |
| 181 | bb_perror_msg("can't write to file"); | ||
| 205 | goto fatal; | 182 | goto fatal; |
| 206 | } | 183 | } |
| 207 | 184 | next: | |
| 208 | next: | ||
| 209 | errors = 0; | 185 | errors = 0; |
| 210 | nak = ACK; | 186 | nak = ACK; |
| 211 | write(ttyfd, &nak, 1); | 187 | full_write(write_fd, &nak, 1); |
| 212 | continue; | 188 | continue; |
| 213 | 189 | error: | |
| 214 | error: | 190 | timeout: |
| 215 | timeout: | ||
| 216 | errors++; | 191 | errors++; |
| 217 | if (errors == MAXERRORS) { | 192 | if (errors == MAXERRORS) { |
| 218 | /* Abort */ | 193 | /* Abort */ |
| 219 | 194 | ||
| 220 | // if using crc, try again w/o crc | 195 | /* if were asking for crc, try again w/o crc */ |
| 221 | if (nak == 'C') { | 196 | if (nak == 'C') { |
| 222 | nak = NAK; | 197 | nak = NAK; |
| 223 | errors = 0; | 198 | errors = 0; |
| 224 | docrc = 0; | 199 | do_crc = 0; |
| 225 | goto timeout; | 200 | goto timeout; |
| 226 | } | 201 | } |
| 227 | 202 | bb_error_msg("too many errors; giving up"); | |
| 228 | note_error("too many errors; giving up"); | 203 | fatal: |
| 229 | 204 | /* 5 CAN followed by 5 BS. Don't try too hard... */ | |
| 230 | fatal: | 205 | safe_write(write_fd, "\030\030\030\030\030\010\010\010\010\010", 10); |
| 231 | /* 5 CAN followed by 5 BS */ | ||
| 232 | write(ttyfd, "\030\030\030\030\030\010\010\010\010\010", 10); | ||
| 233 | return -1; | 206 | return -1; |
| 234 | } | 207 | } |
| 235 | 208 | ||
| 236 | /* Flush pending input */ | 209 | /* Flush pending input */ |
| 237 | tcflush(ttyfd, TCIFLUSH); | 210 | tcflush(read_fd, TCIFLUSH); |
| 238 | |||
| 239 | write(ttyfd, &nak, 1); | ||
| 240 | } | ||
| 241 | |||
| 242 | done: | ||
| 243 | return length; | ||
| 244 | 211 | ||
| 245 | #undef note_error | 212 | full_write(write_fd, &nak, 1); |
| 213 | } /* for (;;) */ | ||
| 246 | } | 214 | } |
| 247 | 215 | ||
| 248 | static void sigalrm_handler(int ATTRIBUTE_UNUSED signum) | 216 | static void sigalrm_handler(int ATTRIBUTE_UNUSED signum) |
| @@ -252,40 +220,38 @@ static void sigalrm_handler(int ATTRIBUTE_UNUSED signum) | |||
| 252 | int rx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 220 | int rx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 253 | int rx_main(int argc, char **argv) | 221 | int rx_main(int argc, char **argv) |
| 254 | { | 222 | { |
| 255 | char *fn; | ||
| 256 | int ttyfd, filefd; | ||
| 257 | struct termios tty, orig_tty; | ||
| 258 | struct sigaction act; | 223 | struct sigaction act; |
| 224 | struct termios tty, orig_tty; | ||
| 225 | int termios_err; | ||
| 226 | int file_fd; | ||
| 259 | int n; | 227 | int n; |
| 260 | char error_buf[256]; | ||
| 261 | 228 | ||
| 262 | if (argc != 2) | 229 | if (argc != 2) |
| 263 | bb_show_usage(); | 230 | bb_show_usage(); |
| 264 | 231 | ||
| 265 | fn = argv[1]; | 232 | /* Disabled by vda: |
| 266 | ttyfd = xopen(CURRENT_TTY, O_RDWR); | 233 | * why we can't receive from stdin? Why we *require* |
| 267 | filefd = xopen(fn, O_RDWR|O_CREAT|O_TRUNC); | 234 | * controlling tty?? */ |
| 268 | 235 | /*read_fd = xopen(CURRENT_TTY, O_RDWR);*/ | |
| 269 | if (tcgetattr(ttyfd, &tty) < 0) | 236 | file_fd = xopen(argv[1], O_RDWR|O_CREAT|O_TRUNC); |
| 270 | bb_perror_msg_and_die("tcgetattr"); | 237 | |
| 271 | 238 | termios_err = tcgetattr(read_fd, &tty); | |
| 272 | orig_tty = tty; | 239 | if (termios_err == 0) { |
| 273 | 240 | orig_tty = tty; | |
| 274 | cfmakeraw(&tty); | 241 | cfmakeraw(&tty); |
| 275 | tcsetattr(ttyfd, TCSAFLUSH, &tty); | 242 | tcsetattr(read_fd, TCSAFLUSH, &tty); |
| 243 | } | ||
| 276 | 244 | ||
| 245 | /* No SA_RESTART: we want ALRM to interrupt read() */ | ||
| 277 | memset(&act, 0, sizeof(act)); | 246 | memset(&act, 0, sizeof(act)); |
| 278 | act.sa_handler = sigalrm_handler; | 247 | act.sa_handler = sigalrm_handler; |
| 279 | sigaction(SIGALRM, &act, 0); | 248 | sigaction(SIGALRM, &act, NULL); |
| 280 | |||
| 281 | n = receive(error_buf, sizeof(error_buf), ttyfd, filefd); | ||
| 282 | |||
| 283 | close(filefd); | ||
| 284 | |||
| 285 | tcsetattr(ttyfd, TCSAFLUSH, &orig_tty); | ||
| 286 | 249 | ||
| 287 | if (n < 0) | 250 | n = receive(file_fd); |
| 288 | bb_error_msg_and_die("\nreceive failed:\n %s", error_buf); | ||
| 289 | 251 | ||
| 290 | fflush_stdout_and_exit(EXIT_SUCCESS); | 252 | if (termios_err == 0) |
| 253 | tcsetattr(read_fd, TCSAFLUSH, &orig_tty); | ||
| 254 | if (ENABLE_FEATURE_CLEAN_UP) | ||
| 255 | close(file_fd); | ||
| 256 | fflush_stdout_and_exit(n >= 0); | ||
| 291 | } | 257 | } |
