Re: timeout fix for linux
Keresztfalvi Laszlo <[email protected]> Fri, 19 Jan 2007 14:37:12 +0100
| Newsgroups | gmane.comp.security.forensics.tct |
|---|---|
| Message-ID | <[email protected]> |
The man timeout page says: "timeout's exit status is the exit status of the specified command or 1 in case of a usage error." My problem was that the executed command failed with exit value other than 0 (eg. sqlplus and 174) in time. But timeout returned 0, so the script assumed the call was successful. I only touched the code of the returned value surrounding status with the appropriate macro. Sure, it may interfere when the command also returns -1 or 255 but these values usually means fatal, unknown errors without useful meanings. I think this is not a problem (at least the problem remains problem), while reporting success instead of failure is danger. That's all. I thought others may also assume the above operation.. Feel free to include or drop. BR, Laszlo Wietse Venema wrote: > Keresztfalvi Laszlo: >> Hello, >> >> since I did not find other address to send a patch, here it is: >> >> in src/misc/timeout.c (at least on Linux): > > This patch does not correctly report that the process was killed > by a signal. > > Wietse > >> #include <sys/wait.h> and returning WEXITSTATUS(status) is required to correctly return the executed command's >> exit value. >> >> Best regards, >> Laszlo > > [ text/x-patch is unsupported, treating like TEXT/PLAIN ] > >> diff -ru tct-1.16/src/misc/timeout.c tct-1.16-fixed/src/misc/timeout.c >> --- tct-1.16/src/misc/timeout.c 2004-10-18 16:59:31.000000000 +0200 >> +++ tct-1.16-fixed/src/misc/timeout.c 2007-01-19 11:03:58.000000000 +0100 >> @@ -34,6 +34,7 @@ >> /* System libraries. */ >> >> #include <sys/types.h> >> +#include <sys/wait.h> >> #include <signal.h> >> #include <stdlib.h> >> #include <unistd.h> >> @@ -107,6 +108,6 @@ >> alarm(time_to_run); >> while ((pid = wait(&status)) != -1 && pid != child_pid) >> /* void */ ; >> - return (pid == child_pid ? status : -1); >> + return (pid == child_pid ? WEXITSTATUS(status) : -1); >> } >> } >