xref: /netbsd-src/lib/libwrap/clean_exit.c (revision e1a2f47f1264dd9755e9e747d45ba016dff2334f)
1*e1a2f47fSmatt /*	$NetBSD: clean_exit.c,v 1.5 2012/03/21 10:10:37 matt Exp $	*/
2d6ddaab4Schristos 
3541be36cSmrg  /*
4541be36cSmrg   * clean_exit() cleans up and terminates the program. It should be called
5541be36cSmrg   * instead of exit() when for some reason the real network daemon will not or
6541be36cSmrg   * cannot be run. Reason: in the case of a datagram-oriented service we must
7541be36cSmrg   * discard the not-yet received data from the client. Otherwise, inetd will
8541be36cSmrg   * see the same datagram again and again, and go into a loop.
9541be36cSmrg   *
10541be36cSmrg   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
11541be36cSmrg   */
12541be36cSmrg 
13d6ddaab4Schristos #include <sys/cdefs.h>
14541be36cSmrg #ifndef lint
15d6ddaab4Schristos #if 0
16541be36cSmrg static char sccsid[] = "@(#) clean_exit.c 1.4 94/12/28 17:42:19";
17d6ddaab4Schristos #else
18*e1a2f47fSmatt __RCSID("$NetBSD: clean_exit.c,v 1.5 2012/03/21 10:10:37 matt Exp $");
19d6ddaab4Schristos #endif
20541be36cSmrg #endif
21541be36cSmrg 
22541be36cSmrg #include <stdio.h>
23d6ddaab4Schristos #include <stdlib.h>
24d6ddaab4Schristos #include <unistd.h>
25541be36cSmrg 
26541be36cSmrg #include "tcpd.h"
27541be36cSmrg 
28541be36cSmrg /* clean_exit - clean up and exit */
29541be36cSmrg 
30*e1a2f47fSmatt void
clean_exit(struct request_info * request)31*e1a2f47fSmatt clean_exit(struct request_info *request)
32541be36cSmrg {
33541be36cSmrg 
34541be36cSmrg     /*
35541be36cSmrg      * In case of unconnected protocols we must eat up the not-yet received
36541be36cSmrg      * data or inetd will loop.
37541be36cSmrg      */
38541be36cSmrg 
39541be36cSmrg     if (request->sink)
40541be36cSmrg 	request->sink(request->fd);
41541be36cSmrg 
42541be36cSmrg     /*
43541be36cSmrg      * Be kind to the inetd. We already reported the problem via the syslogd,
44541be36cSmrg      * and there is no need for additional garbage in the logfile.
45541be36cSmrg      */
46541be36cSmrg 
47541be36cSmrg     sleep(5);
48541be36cSmrg     exit(0);
49541be36cSmrg }
50