diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-24 18:25:08 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-24 18:25:08 +0000 |
| commit | a7ce207bd82882d6436d256a73c42ca4c8500ff3 (patch) | |
| tree | cb284f9f3113886936b35f8a64455614e3e3a5a2 | |
| parent | 47ddd01b3cc8d262f6c97b41b4bb480281eeb591 (diff) | |
| download | busybox-w32-a7ce207bd82882d6436d256a73c42ca4c8500ff3.tar.gz busybox-w32-a7ce207bd82882d6436d256a73c42ca4c8500ff3.tar.bz2 busybox-w32-a7ce207bd82882d6436d256a73c42ca4c8500ff3.zip | |
wget: get rid of setitimer
text data bss dec hex filename
5110 1 0 5111 13f7 busybox.t3/networking/wget.o
5056 1 0 5057 13c1 busybox.t4/networking/wget.o
| -rw-r--r-- | networking/wget.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/networking/wget.c b/networking/wget.c index 23a2fa855..5feb539d5 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
| @@ -12,11 +12,11 @@ | |||
| 12 | struct host_info { | 12 | struct host_info { |
| 13 | // May be used if we ever will want to free() all xstrdup()s... | 13 | // May be used if we ever will want to free() all xstrdup()s... |
| 14 | /* char *allocated; */ | 14 | /* char *allocated; */ |
| 15 | char *host; | 15 | char *path; |
| 16 | int port; | 16 | char *user; |
| 17 | char *path; | 17 | char *host; |
| 18 | int is_ftp; | 18 | int port; |
| 19 | char *user; | 19 | smallint is_ftp; |
| 20 | }; | 20 | }; |
| 21 | 21 | ||
| 22 | 22 | ||
| @@ -32,7 +32,7 @@ struct globals { | |||
| 32 | unsigned lastupdate_sec; | 32 | unsigned lastupdate_sec; |
| 33 | unsigned start_sec; | 33 | unsigned start_sec; |
| 34 | #endif | 34 | #endif |
| 35 | bool chunked; /* chunked transfer encoding */ | 35 | smallint chunked; /* chunked transfer encoding */ |
| 36 | }; | 36 | }; |
| 37 | #define G (*(struct globals*)&bb_common_bufsiz1) | 37 | #define G (*(struct globals*)&bb_common_bufsiz1) |
| 38 | struct BUG_G_too_big { | 38 | struct BUG_G_too_big { |
| @@ -62,26 +62,10 @@ static int getttywidth(void) | |||
| 62 | return width; | 62 | return width; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | static void updateprogressmeter(int ignore) | ||
| 66 | { | ||
| 67 | int save_errno = errno; | ||
| 68 | |||
| 69 | progressmeter(0); | ||
| 70 | errno = save_errno; | ||
| 71 | } | ||
| 72 | |||
| 73 | static void alarmtimer(int iwait) | ||
| 74 | { | ||
| 75 | struct itimerval itv; | ||
| 76 | |||
| 77 | itv.it_value.tv_sec = iwait; | ||
| 78 | itv.it_value.tv_usec = 0; | ||
| 79 | itv.it_interval = itv.it_value; | ||
| 80 | setitimer(ITIMER_REAL, &itv, NULL); | ||
| 81 | } | ||
| 82 | |||
| 83 | static void progressmeter(int flag) | 65 | static void progressmeter(int flag) |
| 84 | { | 66 | { |
| 67 | /* We can be called from signal handler */ | ||
| 68 | int save_errno = errno; | ||
| 85 | off_t abbrevsize; | 69 | off_t abbrevsize; |
| 86 | unsigned since_last_update, elapsed; | 70 | unsigned since_last_update, elapsed; |
| 87 | unsigned ratio; | 71 | unsigned ratio; |
| @@ -124,7 +108,6 @@ static void progressmeter(int flag) | |||
| 124 | fprintf(stderr, "%6d%c ", (int)abbrevsize, " kMGTPEZY"[i]); | 108 | fprintf(stderr, "%6d%c ", (int)abbrevsize, " kMGTPEZY"[i]); |
| 125 | 109 | ||
| 126 | // Nuts! Ain't it easier to update progress meter ONLY when we transferred++? | 110 | // Nuts! Ain't it easier to update progress meter ONLY when we transferred++? |
| 127 | // FIXME: get rid of alarmtimer + updateprogressmeter mess | ||
| 128 | 111 | ||
| 129 | elapsed = monotonic_sec(); | 112 | elapsed = monotonic_sec(); |
| 130 | since_last_update = elapsed - lastupdate_sec; | 113 | since_last_update = elapsed - lastupdate_sec; |
| @@ -155,18 +138,24 @@ static void progressmeter(int flag) | |||
| 155 | } | 138 | } |
| 156 | } | 139 | } |
| 157 | 140 | ||
| 158 | if (flag == -1) { /* first call to progressmeter */ | 141 | if (flag == 0) { |
| 159 | struct sigaction sa; | 142 | /* last call to progressmeter */ |
| 160 | sa.sa_handler = updateprogressmeter; | 143 | alarm(0); |
| 161 | sigemptyset(&sa.sa_mask); | ||
| 162 | sa.sa_flags = SA_RESTART; | ||
| 163 | sigaction(SIGALRM, &sa, NULL); | ||
| 164 | alarmtimer(1); | ||
| 165 | } else if (flag == 1) { /* last call to progressmeter */ | ||
| 166 | alarmtimer(0); | ||
| 167 | transferred = 0; | 144 | transferred = 0; |
| 168 | putc('\n', stderr); | 145 | putc('\n', stderr); |
| 146 | } else { | ||
| 147 | if (flag == -1) { | ||
| 148 | /* first call to progressmeter */ | ||
| 149 | struct sigaction sa; | ||
| 150 | sa.sa_handler = progressmeter; | ||
| 151 | sigemptyset(&sa.sa_mask); | ||
| 152 | sa.sa_flags = SA_RESTART; | ||
| 153 | sigaction(SIGALRM, &sa, NULL); | ||
| 154 | } | ||
| 155 | alarm(1); | ||
| 169 | } | 156 | } |
| 157 | |||
| 158 | errno = save_errno; | ||
| 170 | } | 159 | } |
| 171 | /* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff, | 160 | /* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff, |
| 172 | * much of which was blatantly stolen from openssh. */ | 161 | * much of which was blatantly stolen from openssh. */ |
| @@ -566,7 +555,8 @@ int wget_main(int argc, char **argv) | |||
| 566 | * HTTP session | 555 | * HTTP session |
| 567 | */ | 556 | */ |
| 568 | do { | 557 | do { |
| 569 | got_clen = chunked = 0; | 558 | got_clen = 0; |
| 559 | chunked = 0; | ||
| 570 | 560 | ||
| 571 | if (!--try) | 561 | if (!--try) |
| 572 | bb_error_msg_and_die("too many redirections"); | 562 | bb_error_msg_and_die("too many redirections"); |
| @@ -814,7 +804,7 @@ int wget_main(int argc, char **argv) | |||
| 814 | } | 804 | } |
| 815 | 805 | ||
| 816 | if (!(opt & WGET_OPT_QUIET)) | 806 | if (!(opt & WGET_OPT_QUIET)) |
| 817 | progressmeter(1); | 807 | progressmeter(0); |
| 818 | 808 | ||
| 819 | if ((use_proxy == 0) && target.is_ftp) { | 809 | if ((use_proxy == 0) && target.is_ftp) { |
| 820 | fclose(dfp); | 810 | fclose(dfp); |
