Fix the thirty second delay properly.
authorDave West <davew@uncensored.citadel.org>
Sat, 3 Nov 2007 23:13:23 +0000 (23:13 +0000)
committerDave West <davew@uncensored.citadel.org>
Sat, 3 Nov 2007 23:13:23 +0000 (23:13 +0000)
Also added a watchdog timer to kill send command if it hangs at some
point due to a dodgy server.
This will prevent bug #231.

citadel/sendcommand.c

index 382e2092760ee2dc1a22b438fc90cad65a068599..c7439dc0dbca681423020307810a64c8ff905f56 100644 (file)
@@ -188,6 +188,10 @@ int main(int argc, char **argv)
                        (int) getpid(),
                        ctdl_home_directory);
        fflush(stderr);
+
+       alarm(5);
+       signal(SIGALRM, nq_cleanup); /* Set up a watchdog type timer in case we hang */
+       
        np_attach_to_server(UDS, ctdl_home_directory);
        fflush(stderr);
        setIPCDeathHook(sendcommand_die);
@@ -203,6 +207,7 @@ int main(int argc, char **argv)
        if (buf[0] == '1') {
                while (CtdlIPC_chat_recv(ipc, buf), strcmp(buf, "000")) {
                        printf("%s\n", buf);
+                       alarm(5); /* Kick the watchdog timer */
                }
        } else if (buf[0] == '4') {
                do {
@@ -242,12 +247,14 @@ int main(int argc, char **argv)
                                        fflush (stdout);
                                }
                        }
+                       alarm(5); /* Kick the watchdog timer */
                } while (strcmp(buf, "000"));
                CtdlIPC_chat_send(ipc, "\n");
                CtdlIPC_chat_send(ipc, "000");
        }
+       alarm(0);       /* Shutdown the watchdog timer */
        fprintf(stderr, "sendcommand: processing ended.\n");
-       if (stricmp(cmd, "DOWN"))
+       if (strcasecmp(cmd, "DOWN"))
                cleanup(0);
        else    /* If we downed the server we can't to do CtdlIPCQuit in cleanup()*/
                nq_cleanup(0);