package w3m
tag 206605 patch
thanks
On Wed, May 10, 2006 at 10:26:50AM +0100, [EMAIL PROTECTED] wrote:
> Karsten Schoelzel wrote:
> >Here is a patch which solves the problem by:
> >If there is a short write in save2tmp stop trying and return with a error
> >code.
> >In the main program examine the return code of child processes on SIGCHLD.
> >If an error occured say so in the Download List Panel.
>
> It's a shame you can't propagate the actual error code through, but
> this is definitely better than the previous code :-)
>
> >@@ -6400,7 +6407,9 @@ DownloadListBuffer(void)
> > if (d->ok) {
> > Strcat(src, Sprintf("<input type=submit name=ok%d value=OK>",
> > d->pid));
> >- if (size < d->size)
> >+ if (d->err)
> >+ Strcat_charp(src, " Error while saving file");
> >+ else if (size < d->size)
> > Strcat_charp(src, " Download incompleted");
> > else
> > Strcat_charp(src, " Download completed");
>
> While you're changing this bit you might as well fix the grammar error:
> "Download incompleted" is definitely wrong; "Download in progress" is
> better (though I am making assumptions about when it's printed).
>
I have rewritten the patch a bit and hopefully the error messages are a
bit better now and the error number is properly propagated.
Regards,
--
Karsten Schölzel | Email: [EMAIL PROTECTED]
Väderleden 9 4:98 | Jabber: [EMAIL PROTECTED]
97633 Luleå | VoIP: sip:[EMAIL PROTECTED]
Sweden | sip:[EMAIL PROTECTED]
| Tel: +4918015855857712
diff --git a/file.c b/file.c
index 3318681..a9874ad 100644
--- a/file.c
+++ b/file.c
@@ -7510,7 +7510,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);
}
@@ -7835,11 +7841,15 @@ doFileSave(URLFile uf, char *defstr)
flush_tty();
pid = fork();
if (!pid) {
+ int err;
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 --git a/fm.h b/fm.h
index 288426a..1077522 100644
--- a/fm.h
+++ b/fm.h
@@ -507,7 +507,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 --git a/main.c b/main.c
index 24201a9..638771d 100644
--- a/main.c
+++ b/main.c
@@ -314,21 +314,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;
}
@@ -6307,7 +6312,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)
@@ -6327,7 +6333,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;
@@ -6367,15 +6373,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;
}
}
@@ -6394,7 +6401,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)));
@@ -6405,20 +6412,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>",
@@ -6470,7 +6485,7 @@ stopDownload(void)
if (!FirstDL)
return;
for (d = FirstDL; d != NULL; d = d->next) {
- if (d->ok)
+ if (!d->running)
continue;
kill(d->pid, SIGKILL);
unlink(d->lock);