aboutsummaryrefslogtreecommitdiff
path: root/networking/wget.c
diff options
context:
space:
mode:
authorLauri Kasanen <curaga@operamail.com>2013-10-12 21:47:07 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-10-12 21:47:07 +0200
commitd074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0 (patch)
treeca2227cabe38037276d4b8f270878bd26860a6d8 /networking/wget.c
parent730e4d8b5245502803c9c2335e96d81f70d63012 (diff)
downloadbusybox-w32-d074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0.tar.gz
busybox-w32-d074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0.tar.bz2
busybox-w32-d074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0.zip
wget: add support for connect timeout
function old new delta open_socket 33 64 +31 wget_main 2182 2194 +12 Signed-off-by: Lauri Kasanen <curaga@operamail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/wget.c')
-rw-r--r--networking/wget.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 5dac2b500..a32f85229 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -72,6 +72,7 @@ struct globals {
72 const char *user_agent; /* "User-Agent" header field */ 72 const char *user_agent; /* "User-Agent" header field */
73#if ENABLE_FEATURE_WGET_TIMEOUT 73#if ENABLE_FEATURE_WGET_TIMEOUT
74 unsigned timeout_seconds; 74 unsigned timeout_seconds;
75 bool connecting;
75#endif 76#endif
76 int output_fd; 77 int output_fd;
77 int o_flags; 78 int o_flags;
@@ -87,7 +88,6 @@ struct globals {
87#define G (*ptr_to_globals) 88#define G (*ptr_to_globals)
88#define INIT_G() do { \ 89#define INIT_G() do { \
89 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 90 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
90 IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;) \
91} while (0) 91} while (0)
92 92
93 93
@@ -195,13 +195,27 @@ static char* sanitize_string(char *s)
195 return s; 195 return s;
196} 196}
197 197
198#if ENABLE_FEATURE_WGET_TIMEOUT
199static void alarm_handler(int sig UNUSED_PARAM)
200{
201 /* This is theoretically unsafe (uses stdio and malloc in signal handler) */
202 if (G.connecting)
203 bb_error_msg_and_die("download timed out");
204}
205#endif
206
198static FILE *open_socket(len_and_sockaddr *lsa) 207static FILE *open_socket(len_and_sockaddr *lsa)
199{ 208{
209 int fd;
200 FILE *fp; 210 FILE *fp;
201 211
212 IF_FEATURE_WGET_TIMEOUT(alarm(G.timeout_seconds); G.connecting = 1;)
213 fd = xconnect_stream(lsa);
214 IF_FEATURE_WGET_TIMEOUT(G.connecting = 0;)
215
202 /* glibc 2.4 seems to try seeking on it - ??! */ 216 /* glibc 2.4 seems to try seeking on it - ??! */
203 /* hopefully it understands what ESPIPE means... */ 217 /* hopefully it understands what ESPIPE means... */
204 fp = fdopen(xconnect_stream(lsa), "r+"); 218 fp = fdopen(fd, "r+");
205 if (fp == NULL) 219 if (fp == NULL)
206 bb_perror_msg_and_die(bb_msg_memory_exhausted); 220 bb_perror_msg_and_die(bb_msg_memory_exhausted);
207 221
@@ -209,6 +223,7 @@ static FILE *open_socket(len_and_sockaddr *lsa)
209} 223}
210 224
211/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */ 225/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */
226/* FIXME: does not respect FEATURE_WGET_TIMEOUT and -T N: */
212static char fgets_and_trim(FILE *fp) 227static char fgets_and_trim(FILE *fp)
213{ 228{
214 char c; 229 char c;
@@ -944,7 +959,10 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
944 959
945 INIT_G(); 960 INIT_G();
946 961
947 IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;) 962#if ENABLE_FEATURE_WGET_TIMEOUT
963 G.timeout_seconds = 900;
964 signal(SIGALRM, alarm_handler);
965#endif
948 G.proxy_flag = "on"; /* use proxies if env vars are set */ 966 G.proxy_flag = "on"; /* use proxies if env vars are set */
949 G.user_agent = "Wget"; /* "User-Agent" header field */ 967 G.user_agent = "Wget"; /* "User-Agent" header field */
950 968