aboutsummaryrefslogtreecommitdiff
path: root/networking/tftp.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/tftp.c')
-rw-r--r--networking/tftp.c39
1 files changed, 12 insertions, 27 deletions
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 */ 108static void tftp_progress_update(void)
109static 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}
133static void tftp_progress_init(void) 112static void tftp_progress_init(void)
134{ 113{
135 progress_meter(-1); 114 bb_progress_init(&G.pmt);
115 tftp_progress_update();
136} 116}
137static void tftp_progress_done(void) 117static 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 }