diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2011-01-10 12:51:44 +0100 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2011-01-10 12:51:44 +0100 |
| commit | 84dba9c5bbd99cb80c0e201bbffa27a51766c63f (patch) | |
| tree | d872deb94f11d7c7104ffa00d48c0e3dae126541 | |
| parent | 7b305646e12536e9aa62d2768d48bf2d2d78caa5 (diff) | |
| download | busybox-w32-84dba9c5bbd99cb80c0e201bbffa27a51766c63f.tar.gz busybox-w32-84dba9c5bbd99cb80c0e201bbffa27a51766c63f.tar.bz2 busybox-w32-84dba9c5bbd99cb80c0e201bbffa27a51766c63f.zip | |
tftp: fix bad interaction betweel poll() and alarm(). Closes bug 3061
This was breaking timeout handling.
function old new delta
tftp_progress_update - 45 +45
tftp_progress_done - 32 +32
tftp_protocol 1839 1858 +19
tftp_progress_init 9 15 +6
tftp_main 298 286 -12
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/1 up/down: 102/-12) Total: 90 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
| -rw-r--r-- | libbb/progress.c | 2 | ||||
| -rw-r--r-- | networking/tftp.c | 39 |
2 files changed, 13 insertions, 28 deletions
diff --git a/libbb/progress.c b/libbb/progress.c index 4c2763c53..74e80a39e 100644 --- a/libbb/progress.c +++ b/libbb/progress.c | |||
| @@ -78,7 +78,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
| 78 | /* Do not update on every call | 78 | /* Do not update on every call |
| 79 | * (we can be called on every network read!) */ | 79 | * (we can be called on every network read!) */ |
| 80 | if (since_last_update == 0 && !totalsize) | 80 | if (since_last_update == 0 && !totalsize) |
| 81 | return; | 81 | return; |
| 82 | 82 | ||
| 83 | beg_and_transferred = beg_range + transferred; | 83 | beg_and_transferred = beg_range + transferred; |
| 84 | ratio = 100; | 84 | ratio = 100; |
diff --git a/networking/tftp.c b/networking/tftp.c index 04c8f0ebb..fcd933f6a 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
| @@ -105,39 +105,22 @@ struct BUG_G_too_big { | |||
| 105 | #define error_pkt_str (error_pkt + 4) | 105 | #define error_pkt_str (error_pkt + 4) |
| 106 | 106 | ||
| 107 | #if ENABLE_FEATURE_TFTP_PROGRESS_BAR | 107 | #if ENABLE_FEATURE_TFTP_PROGRESS_BAR |
| 108 | /* SIGALRM logic nicked from the wget applet */ | 108 | static void tftp_progress_update(void) |
| 109 | static void progress_meter(int flag) | ||
| 110 | { | 109 | { |
| 111 | /* We can be called from signal handler */ | ||
| 112 | int save_errno = errno; | ||
| 113 | |||
| 114 | if (flag == -1) { /* first call to progress_meter */ | ||
| 115 | bb_progress_init(&G.pmt); | ||
| 116 | } | ||
| 117 | |||
| 118 | bb_progress_update(&G.pmt, G.file, 0, G.pos, G.size); | 110 | bb_progress_update(&G.pmt, G.file, 0, G.pos, G.size); |
| 119 | |||
| 120 | if (flag == 0) { | ||
| 121 | /* last call to progress_meter */ | ||
| 122 | alarm(0); | ||
| 123 | bb_putchar_stderr('\n'); | ||
| 124 | } else { | ||
| 125 | if (flag == -1) { /* first call to progress_meter */ | ||
| 126 | signal_SA_RESTART_empty_mask(SIGALRM, progress_meter); | ||
| 127 | } | ||
| 128 | alarm(1); | ||
| 129 | } | ||
| 130 | |||
| 131 | errno = save_errno; | ||
| 132 | } | 111 | } |
| 133 | static void tftp_progress_init(void) | 112 | static void tftp_progress_init(void) |
| 134 | { | 113 | { |
| 135 | progress_meter(-1); | 114 | bb_progress_init(&G.pmt); |
| 115 | tftp_progress_update(); | ||
| 136 | } | 116 | } |
| 137 | static void tftp_progress_done(void) | 117 | static void tftp_progress_done(void) |
| 138 | { | 118 | { |
| 139 | if (G.pmt.inited) | 119 | if (G.pmt.inited) { |
| 140 | progress_meter(0); | 120 | tftp_progress_update(); |
| 121 | bb_putchar_stderr('\n'); | ||
| 122 | G.pmt.inited = 0; | ||
| 123 | } | ||
| 141 | } | 124 | } |
| 142 | #else | 125 | #else |
| 143 | # define tftp_progress_init() ((void)0) | 126 | # define tftp_progress_init() ((void)0) |
| @@ -460,9 +443,10 @@ static int tftp_protocol( | |||
| 460 | xsendto(socket_fd, xbuf, send_len, &peer_lsa->u.sa, peer_lsa->len); | 443 | xsendto(socket_fd, xbuf, send_len, &peer_lsa->u.sa, peer_lsa->len); |
| 461 | 444 | ||
| 462 | #if ENABLE_FEATURE_TFTP_PROGRESS_BAR | 445 | #if ENABLE_FEATURE_TFTP_PROGRESS_BAR |
| 463 | if (ENABLE_TFTP && remote_file) { /* tftp */ | 446 | if (ENABLE_TFTP && remote_file) /* tftp */ |
| 464 | G.pos = (block_nr - 1) * (uoff_t)blksize; | 447 | G.pos = (block_nr - 1) * (uoff_t)blksize; |
| 465 | } | 448 | if (G.pmt.inited) |
| 449 | tftp_progress_update(); | ||
| 466 | #endif | 450 | #endif |
| 467 | /* Was it final ACK? then exit */ | 451 | /* Was it final ACK? then exit */ |
| 468 | if (finished && (opcode == TFTP_ACK)) | 452 | if (finished && (opcode == TFTP_ACK)) |
| @@ -479,6 +463,7 @@ static int tftp_protocol( | |||
| 479 | case 0: | 463 | case 0: |
| 480 | retries--; | 464 | retries--; |
| 481 | if (retries == 0) { | 465 | if (retries == 0) { |
| 466 | tftp_progress_done(); | ||
| 482 | bb_error_msg("timeout"); | 467 | bb_error_msg("timeout"); |
| 483 | goto ret; /* no err packet sent */ | 468 | goto ret; /* no err packet sent */ |
| 484 | } | 469 | } |
