leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

mgetaline.c
Go to the documentation of this file.
1/*
2mgetaline.c -- getaline with timeout, split from the NNTP server
3
4Written by Arnt Gulbrandsen <agulbra@troll.no> and copyright 1995
5Troll Tech AS, Postboks 6133 Etterstad, 0602 Oslo, Norway, fax +47
622646949.
7Modified by Cornelius Krasel <krasel@wpxx02.toxi.uni-wuerzburg.de>
8and Randolf Skerka <Randolf.Skerka@gmx.de>.
9Copyright of the modifications 1997.
10Modified by Kent Robotti <robotti@erols.com>. Copyright of the
11modifications 1998.
12Modified by Markus Enzenberger <enz@cip.physik.uni-muenchen.de>.
13Copyright of the modifications 1998.
14Modified by Cornelius Krasel <krasel@wpxx02.toxi.uni-wuerzburg.de>
15and Kazushi (Jam) Marukawa <jam@pobox.com>.
16Copyright of the modifications 1998, 1999.
17Modified by Ralf Wildenhues <ralf.wildenhues@gmx.de>
18Copyright of the modifications 2002.
19Modified by Richard van der Hoff <richard@rvanderhoff.org.uk>
20Copyright of the modifications 2002.
21Modified by Matthias Andree <matthias.andree@gmx.de>
22Copyright of the modifications 2000 - 2010.
23
24See file COPYING for restrictions on the use of this software.
25*/
26
27#include "leafnode.h"
28#include "mysigact.h"
29
30#include <sys/types.h>
31#include <signal.h>
32#include <stdlib.h>
33#include <unistd.h>
34#include <setjmp.h>
35#include <stdio.h>
36
37static unsigned int timeout_secs;
38
39sigjmp_buf timeout;
40
41void timer(int sig)
42{
43 siglongjmp(timeout, 1);
44 exit(sig); /* not reached */
45}
46
47/*
48 * call getaline with config specified timeout
49 */
50/*@dependent@*/ char *
51mgetaline(FILE * f)
52{
53 char *l;
54
55 if (sigsetjmp(timeout,1)) {
56 if (debug)
57 syslog(LOG_DEBUG, "< (ERROR: timeout - no response in %u s)", timeout_secs);
58 return NULL;
59 }
60 mysigact(SIGALRM, SA_RESETHAND, timer, 0);
61 (void)alarm(timeout_secs);
62 l = getaline(f);
63 (void)alarm(0U);
64 mysigact(SIGALRM, 0, SIG_DFL, 0);
65 return l;
66}
67
68void
69mgetaline_settimeout(unsigned int t) {
70 timeout_secs = t;
71}
int debug
Definition: applyfilter.c:30
char * getaline(FILE *f)
Definition: getaline.c:84
char * mgetaline(FILE *f)
Definition: mgetaline.c:51
static unsigned int timeout_secs
Definition: mgetaline.c:37
void mgetaline_settimeout(unsigned int t)
Definition: mgetaline.c:69
sigjmp_buf timeout
Definition: mgetaline.c:39
void timer(int sig)
Definition: mgetaline.c:41
int mysigact(int sig, int flags, void(*func)(int), int blockthis)
Definition: mysigact.c:9