Bernhard Reutner-Fischer | c2cb0f3 | 2006-04-13 12:45:04 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 2 | /* |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 3 | * Copyright: Copyright (C) 2001, Hewlett-Packard Company |
| 4 | * Author: Christopher Hoover <ch@hpl.hp.com> |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Description: xmodem functionality for uploading of kernels |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 6 | * and the like |
| 7 | * Created at: Thu Dec 20 01:58:08 PST 2001 |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 8 | * |
| 9 | * xmodem functionality for uploading of kernels and the like |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 10 | * |
| 11 | * Copyright (C) 2001 Hewlett-Packard Laboratories |
| 12 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 13 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 14 | * |
| 15 | * This was originally written for blob and then adapted for busybox. |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 18 | //usage:#define rx_trivial_usage |
| 19 | //usage: "FILE" |
| 20 | //usage:#define rx_full_usage "\n\n" |
| 21 | //usage: "Receive a file using the xmodem protocol" |
| 22 | //usage: |
| 23 | //usage:#define rx_example_usage |
| 24 | //usage: "$ rx /tmp/foo\n" |
| 25 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 26 | #include "libbb.h" |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 27 | |
| 28 | #define SOH 0x01 |
| 29 | #define STX 0x02 |
| 30 | #define EOT 0x04 |
| 31 | #define ACK 0x06 |
| 32 | #define NAK 0x15 |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 33 | #define BS 0x08 |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 34 | #define PAD 0x1A |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 35 | |
| 36 | /* |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 37 | Cf: |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 38 | http://www.textfiles.com/apple/xmodem |
| 39 | http://www.phys.washington.edu/~belonis/xmodem/docxmodem.txt |
| 40 | http://www.phys.washington.edu/~belonis/xmodem/docymodem.txt |
| 41 | http://www.phys.washington.edu/~belonis/xmodem/modmprot.col |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 42 | */ |
| 43 | |
| 44 | #define TIMEOUT 1 |
| 45 | #define TIMEOUT_LONG 10 |
| 46 | #define MAXERRORS 10 |
| 47 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 48 | #define read_fd STDIN_FILENO |
| 49 | #define write_fd STDOUT_FILENO |
| 50 | |
| 51 | static int read_byte(unsigned timeout) |
Denis Vlasenko | ac678ec | 2007-04-16 22:32:04 +0000 | [diff] [blame] | 52 | { |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 53 | unsigned char buf; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 54 | int n; |
| 55 | |
| 56 | alarm(timeout); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 57 | /* NOT safe_read! We want ALRM to interrupt us */ |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 58 | n = read(read_fd, &buf, 1); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 59 | alarm(0); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 60 | if (n == 1) |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 61 | return buf; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 62 | return -1; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 65 | static int receive(/*int read_fd, */int file_fd) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 66 | { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 67 | unsigned char blockBuf[1024]; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 68 | unsigned blockLength = 0; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 69 | unsigned errors = 0; |
| 70 | unsigned wantBlockNo = 1; |
| 71 | unsigned length = 0; |
| 72 | int do_crc = 1; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 73 | char reply_char; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 74 | unsigned timeout = TIMEOUT_LONG; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 75 | |
Rob Landley | 399d45f | 2006-06-21 01:49:17 +0000 | [diff] [blame] | 76 | /* Flush pending input */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 77 | tcflush(read_fd, TCIFLUSH); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 78 | |
| 79 | /* Ask for CRC; if we get errors, we will go with checksum */ |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 80 | reply_char = 'C'; |
| 81 | full_write(write_fd, &reply_char, 1); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 82 | |
| 83 | for (;;) { |
| 84 | int blockBegin; |
| 85 | int blockNo, blockNoOnesCompl; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 86 | int cksum_or_crc; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 87 | int expected; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 88 | int i, j; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 89 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 90 | blockBegin = read_byte(timeout); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 91 | if (blockBegin < 0) |
| 92 | goto timeout; |
| 93 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 94 | /* If last block, remove padding */ |
| 95 | if (blockBegin == EOT) { |
| 96 | /* Data blocks can be padded with ^Z characters */ |
| 97 | /* This code tries to detect and remove them */ |
| 98 | if (blockLength >= 3 |
| 99 | && blockBuf[blockLength - 1] == PAD |
| 100 | && blockBuf[blockLength - 2] == PAD |
| 101 | && blockBuf[blockLength - 3] == PAD |
| 102 | ) { |
| 103 | while (blockLength |
| 104 | && blockBuf[blockLength - 1] == PAD |
| 105 | ) { |
| 106 | blockLength--; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | /* Write previously received block */ |
| 111 | if (blockLength) { |
| 112 | errno = 0; |
| 113 | if (full_write(file_fd, blockBuf, blockLength) != blockLength) { |
| 114 | bb_perror_msg("can't write to file"); |
| 115 | goto fatal; |
| 116 | } |
| 117 | } |
| 118 | |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 119 | timeout = TIMEOUT; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 120 | reply_char = NAK; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 121 | |
| 122 | switch (blockBegin) { |
| 123 | case SOH: |
| 124 | case STX: |
| 125 | break; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 126 | case EOT: |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 127 | reply_char = ACK; |
| 128 | full_write(write_fd, &reply_char, 1); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 129 | return length; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 130 | default: |
| 131 | goto error; |
| 132 | } |
| 133 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 134 | /* Block no */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 135 | blockNo = read_byte(TIMEOUT); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 136 | if (blockNo < 0) |
| 137 | goto timeout; |
| 138 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 139 | /* Block no, in one's complement form */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 140 | blockNoOnesCompl = read_byte(TIMEOUT); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 141 | if (blockNoOnesCompl < 0) |
| 142 | goto timeout; |
| 143 | |
| 144 | if (blockNo != (255 - blockNoOnesCompl)) { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 145 | bb_error_msg("bad block ones compl"); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 146 | goto error; |
| 147 | } |
| 148 | |
| 149 | blockLength = (blockBegin == SOH) ? 128 : 1024; |
| 150 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 151 | for (i = 0; i < blockLength; i++) { |
| 152 | int cc = read_byte(TIMEOUT); |
| 153 | if (cc < 0) |
| 154 | goto timeout; |
| 155 | blockBuf[i] = cc; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 158 | if (do_crc) { |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 159 | cksum_or_crc = read_byte(TIMEOUT); |
| 160 | if (cksum_or_crc < 0) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 161 | goto timeout; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 162 | cksum_or_crc = (cksum_or_crc << 8) | read_byte(TIMEOUT); |
| 163 | if (cksum_or_crc < 0) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 164 | goto timeout; |
| 165 | } else { |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 166 | cksum_or_crc = read_byte(TIMEOUT); |
| 167 | if (cksum_or_crc < 0) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 168 | goto timeout; |
| 169 | } |
| 170 | |
| 171 | if (blockNo == ((wantBlockNo - 1) & 0xff)) { |
| 172 | /* a repeat of the last block is ok, just ignore it. */ |
| 173 | /* this also ignores the initial block 0 which is */ |
| 174 | /* meta data. */ |
| 175 | goto next; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 176 | } |
| 177 | if (blockNo != (wantBlockNo & 0xff)) { |
| 178 | bb_error_msg("unexpected block no, 0x%08x, expecting 0x%08x", blockNo, wantBlockNo); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 179 | goto error; |
| 180 | } |
| 181 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 182 | expected = 0; |
| 183 | if (do_crc) { |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 184 | for (i = 0; i < blockLength; i++) { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 185 | expected = expected ^ blockBuf[i] << 8; |
| 186 | for (j = 0; j < 8; j++) { |
| 187 | if (expected & 0x8000) |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 188 | expected = (expected << 1) ^ 0x1021; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 189 | else |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 190 | expected = (expected << 1); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 191 | } |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 192 | } |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 193 | expected &= 0xffff; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 194 | } else { |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 195 | for (i = 0; i < blockLength; i++) |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 196 | expected += blockBuf[i]; |
| 197 | expected &= 0xff; |
| 198 | } |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 199 | if (cksum_or_crc != expected) { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 200 | bb_error_msg(do_crc ? "crc error, expected 0x%04x, got 0x%04x" |
| 201 | : "checksum error, expected 0x%02x, got 0x%02x", |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 202 | expected, cksum_or_crc); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 203 | goto error; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | wantBlockNo++; |
| 207 | length += blockLength; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 208 | next: |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 209 | errors = 0; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 210 | reply_char = ACK; |
| 211 | full_write(write_fd, &reply_char, 1); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 212 | continue; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 213 | error: |
| 214 | timeout: |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 215 | errors++; |
| 216 | if (errors == MAXERRORS) { |
| 217 | /* Abort */ |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 218 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 219 | /* If were asking for crc, try again w/o crc */ |
| 220 | if (reply_char == 'C') { |
| 221 | reply_char = NAK; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 222 | errors = 0; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 223 | do_crc = 0; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 224 | goto timeout; |
| 225 | } |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 226 | bb_error_msg("too many errors; giving up"); |
| 227 | fatal: |
| 228 | /* 5 CAN followed by 5 BS. Don't try too hard... */ |
| 229 | safe_write(write_fd, "\030\030\030\030\030\010\010\010\010\010", 10); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 230 | return -1; |
| 231 | } |
| 232 | |
Rob Landley | 399d45f | 2006-06-21 01:49:17 +0000 | [diff] [blame] | 233 | /* Flush pending input */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 234 | tcflush(read_fd, TCIFLUSH); |
Rob Landley | 399d45f | 2006-06-21 01:49:17 +0000 | [diff] [blame] | 235 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 236 | full_write(write_fd, &reply_char, 1); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 237 | } /* for (;;) */ |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 240 | static void sigalrm_handler(int UNUSED_PARAM signum) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 241 | { |
| 242 | } |
| 243 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 244 | int rx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 245 | int rx_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 246 | { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 247 | struct termios tty, orig_tty; |
| 248 | int termios_err; |
| 249 | int file_fd; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 250 | int n; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 251 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 252 | /* Disabled by vda: |
| 253 | * why we can't receive from stdin? Why we *require* |
| 254 | * controlling tty?? */ |
| 255 | /*read_fd = xopen(CURRENT_TTY, O_RDWR);*/ |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 256 | file_fd = xopen(single_argv(argv), O_RDWR|O_CREAT|O_TRUNC); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 257 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 258 | termios_err = tcgetattr(read_fd, &tty); |
| 259 | if (termios_err == 0) { |
| 260 | orig_tty = tty; |
| 261 | cfmakeraw(&tty); |
| 262 | tcsetattr(read_fd, TCSAFLUSH, &tty); |
| 263 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 264 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 265 | /* No SA_RESTART: we want ALRM to interrupt read() */ |
Denis Vlasenko | 8e2cfec | 2008-03-12 23:19:35 +0000 | [diff] [blame] | 266 | signal_no_SA_RESTART_empty_mask(SIGALRM, sigalrm_handler); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 267 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 268 | n = receive(file_fd); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 269 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 270 | if (termios_err == 0) |
| 271 | tcsetattr(read_fd, TCSAFLUSH, &orig_tty); |
| 272 | if (ENABLE_FEATURE_CLEAN_UP) |
| 273 | close(file_fd); |
| 274 | fflush_stdout_and_exit(n >= 0); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 275 | } |