1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
Description: Tell a download failure when full disk
Origin: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=185006#22
Author: Karsten Schoelzel <kuser@gmx.de>
Bug-Debian: http://bugs.debian.org/185006
diff -urNp w3m-0.5.2.orig/file.c w3m-0.5.2/file.c
--- w3m-0.5.2.orig/file.c 2007-05-24 00:06:05.000000000 +0900
+++ w3m-0.5.2/file.c 2010-07-07 22:12:03.000000000 +0900
@@ -7749,7 +7749,13 @@ save2tmp(URLFile uf, char *tmpf)
{
Str buf = Strnew_size(SAVE_BUF_SIZE);
while (UFread(&uf, buf, SAVE_BUF_SIZE)) {
- Strfputs(buf, ff);
+ if (Strfputs(buf, ff) != buf->length) {
+ bcopy(env_bak, AbortLoading, sizeof(JMP_BUF));
+ TRAP_OFF;
+ fclose(ff);
+ current_content_length = 0;
+ return -2;
+ }
linelen += buf->length;
showProgress(&linelen, &trbyte);
}
@@ -8078,16 +8084,20 @@ doFileSave(URLFile uf, char *defstr)
flush_tty();
pid = fork();
if (!pid) {
+ int err;
if ((uf.content_encoding != CMP_NOCOMPRESS) && AutoUncompress) {
uncompress_stream(&uf, &tmpf);
if (tmpf)
unlink(tmpf);
}
setup_child(FALSE, 0, UFfileno(&uf));
- if (!save2tmp(uf, p) && PreserveTimestamp && uf.modtime != -1)
+ err = save2tmp(uf, p);
+ if (err == 0 && PreserveTimestamp && uf.modtime != -1)
setModtime(p, uf.modtime);
UFclose(&uf);
unlink(lock);
+ if (err != 0)
+ exit(-err);
exit(0);
}
addDownloadList(pid, uf.url, p, lock, current_content_length);
diff -urNp w3m-0.5.2.orig/fm.h w3m-0.5.2/fm.h
--- w3m-0.5.2.orig/fm.h 2007-05-30 13:47:24.000000000 +0900
+++ w3m-0.5.2/fm.h 2010-07-07 21:51:07.000000000 +0900
@@ -517,7 +517,8 @@ typedef struct _DownloadList {
char *lock;
clen_t size;
time_t time;
- int ok;
+ int running;
+ int err;
struct _DownloadList *next;
struct _DownloadList *prev;
} DownloadList;
diff -urNp w3m-0.5.2.orig/main.c w3m-0.5.2/main.c
--- w3m-0.5.2.orig/main.c 2007-05-31 10:19:50.000000000 +0900
+++ w3m-0.5.2/main.c 2010-07-07 21:51:07.000000000 +0900
@@ -323,21 +323,26 @@ static void
sig_chld(int signo)
{
int p_stat;
-#ifdef HAVE_WAITPID
pid_t pid;
+#ifdef HAVE_WAITPID
while ((pid = waitpid(-1, &p_stat, WNOHANG)) > 0) {
- ;
- }
#elif HAVE_WAIT3
- int pid;
-
while ((pid = wait3(&p_stat, WNOHANG, NULL)) > 0) {
- ;
- }
#else
- wait(&p_stat);
+ if ((pid = wait(&p_stat)) > 0) {
#endif
+ DownloadList *d;
+
+ if (WIFEXITED(p_stat)) {
+ for (d = FirstDL; d != NULL; d = d->next) {
+ if (d->pid == pid) {
+ d->err = WEXITSTATUS(p_stat);
+ break;
+ }
+ }
+ }
+ }
mySignal(SIGCHLD, sig_chld);
return;
}
@@ -6355,7 +6360,8 @@ addDownloadList(pid_t pid, char *url, ch
d->lock = lock;
d->size = size;
d->time = time(0);
- d->ok = FALSE;
+ d->running = TRUE;
+ d->err = 0;
d->next = NULL;
d->prev = LastDL;
if (LastDL)
@@ -6375,7 +6381,7 @@ checkDownloadList(void)
if (!FirstDL)
return FALSE;
for (d = FirstDL; d != NULL; d = d->next) {
- if (!d->ok && !lstat(d->lock, &st))
+ if (d->running && !lstat(d->lock, &st))
return TRUE;
}
return FALSE;
@@ -6415,15 +6421,16 @@ DownloadListBuffer(void)
"<form method=internal action=download><hr>\n");
for (d = LastDL; d != NULL; d = d->prev) {
if (lstat(d->lock, &st))
- d->ok = TRUE;
+ d->running = FALSE;
Strcat_charp(src, "<pre>\n");
Strcat(src, Sprintf("%s\n --> %s\n ", html_quote(d->url),
html_quote(conv_from_system(d->save))));
duration = cur_time - d->time;
if (!stat(d->save, &st)) {
size = st.st_size;
- if (d->ok) {
- d->size = size;
+ if (!d->running) {
+ if (!d->err)
+ d->size = size;
duration = st.st_mtime - d->time;
}
}
@@ -6442,7 +6449,7 @@ DownloadListBuffer(void)
Strcat_char(src, '_');
Strcat_char(src, '\n');
}
- if (!d->ok && size < d->size)
+ if ((d->running || d->err) && size < d->size)
Strcat(src, Sprintf(" %s / %s bytes (%d%%)",
convert_size3(size), convert_size3(d->size),
(int)(100.0 * size / d->size)));
@@ -6453,20 +6460,28 @@ DownloadListBuffer(void)
Strcat(src, Sprintf(" %02d:%02d:%02d rate %s/sec",
duration / (60 * 60), (duration / 60) % 60,
duration % 60, convert_size(rate, 1)));
- if (!d->ok && size < d->size && rate) {
+ if (d->running && size < d->size && rate) {
eta = (d->size - size) / rate;
Strcat(src, Sprintf(" eta %02d:%02d:%02d", eta / (60 * 60),
(eta / 60) % 60, eta % 60));
}
}
Strcat_char(src, '\n');
- if (d->ok) {
+ if (!d->running) {
Strcat(src, Sprintf("<input type=submit name=ok%d value=OK>",
d->pid));
- if (size < d->size)
- Strcat_charp(src, " Download incompleted");
- else
- Strcat_charp(src, " Download completed");
+ switch (d->err) {
+ case 0: if (size < d->size)
+ Strcat_charp(src, " Download ended but probably not complete");
+ else
+ Strcat_charp(src, " Download complete");
+ break;
+ case 1: Strcat_charp(src, " Error: could not open destination file");
+ break;
+ case 2: Strcat_charp(src, " Error: could not write to file (disk full)");
+ break;
+ default: Strcat_charp(src, " Error: unknown reason");
+ }
}
else
Strcat(src, Sprintf("<input type=submit name=stop%d value=STOP>",
@@ -6520,7 +6535,7 @@ stopDownload(void)
if (!FirstDL)
return;
for (d = FirstDL; d != NULL; d = d->next) {
- if (d->ok)
+ if (!d->running)
continue;
#ifndef __MINGW32_VERSION
kill(d->pid, SIGKILL);
|