/* mgetaline.c -- getaline with timeout, split from the NNTP server Written by Arnt Gulbrandsen and copyright 1995 Troll Tech AS, Postboks 6133 Etterstad, 0602 Oslo, Norway, fax +47 22646949. Modified by Cornelius Krasel and Randolf Skerka . Copyright of the modifications 1997. Modified by Kent Robotti . Copyright of the modifications 1998. Modified by Markus Enzenberger . Copyright of the modifications 1998. Modified by Cornelius Krasel and Kazushi (Jam) Marukawa . Copyright of the modifications 1998, 1999. Modified by Ralf Wildenhues Copyright of the modifications 2002. Modified by Richard van der Hoff Copyright of the modifications 2002. Modified by Matthias Andree Copyright of the modifications 2000 - 2003. See file COPYING for restrictions on the use of this software. */ #include "leafnode.h" #include "mysigact.h" #include #include #include #include #include #include static unsigned int timeout_secs; sigjmp_buf timeout; RETSIGTYPE timer(int sig) { siglongjmp(timeout, 1); exit(sig); /* not reached */ } /* * call getaline with config specified timeout */ /*@dependent@*/ char * mgetaline(FILE * f) { char *l; if (sigsetjmp(timeout,1)) { if (debug) syslog(LOG_DEBUG, "< (ERROR: timeout - no response in %u s)", timeout_secs); return NULL; } mysigact(SIGALRM, SA_RESETHAND, timer, 0); (void)alarm(timeout_secs); l = getaline(f); (void)alarm(0U); mysigact(SIGALRM, 0, SIG_DFL, 0); return l; } void mgetaline_settimeout(unsigned int t) { timeout_secs = t; }