xref: /illumos-gate/usr/src/lib/libwrap/clean_exit.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate  /*
7*7c478bd9Sstevel@tonic-gate   * clean_exit() cleans up and terminates the program. It should be called
8*7c478bd9Sstevel@tonic-gate   * instead of exit() when for some reason the real network daemon will not or
9*7c478bd9Sstevel@tonic-gate   * cannot be run. Reason: in the case of a datagram-oriented service we must
10*7c478bd9Sstevel@tonic-gate   * discard the not-yet received data from the client. Otherwise, inetd will
11*7c478bd9Sstevel@tonic-gate   * see the same datagram again and again, and go into a loop.
12*7c478bd9Sstevel@tonic-gate   *
13*7c478bd9Sstevel@tonic-gate   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
14*7c478bd9Sstevel@tonic-gate   */
15*7c478bd9Sstevel@tonic-gate 
16*7c478bd9Sstevel@tonic-gate #ifndef lint
17*7c478bd9Sstevel@tonic-gate static char sccsid[] = "@(#) clean_exit.c 1.4 94/12/28 17:42:19";
18*7c478bd9Sstevel@tonic-gate #endif
19*7c478bd9Sstevel@tonic-gate 
20*7c478bd9Sstevel@tonic-gate #include <stdio.h>
21*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
22*7c478bd9Sstevel@tonic-gate #include <unistd.h>
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate extern void exit();
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #include "tcpd.h"
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate /* clean_exit - clean up and exit */
29*7c478bd9Sstevel@tonic-gate 
clean_exit(request)30*7c478bd9Sstevel@tonic-gate void    clean_exit(request)
31*7c478bd9Sstevel@tonic-gate struct request_info *request;
32*7c478bd9Sstevel@tonic-gate {
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate     /*
35*7c478bd9Sstevel@tonic-gate      * In case of unconnected protocols we must eat up the not-yet received
36*7c478bd9Sstevel@tonic-gate      * data or inetd will loop.
37*7c478bd9Sstevel@tonic-gate      */
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate     if (request->sink)
40*7c478bd9Sstevel@tonic-gate 	request->sink(request->fd);
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate     /*
43*7c478bd9Sstevel@tonic-gate      * Be kind to the inetd. We already reported the problem via the syslogd,
44*7c478bd9Sstevel@tonic-gate      * and there is no need for additional garbage in the logfile.
45*7c478bd9Sstevel@tonic-gate      */
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate     sleep(5);
48*7c478bd9Sstevel@tonic-gate     exit(0);
49*7c478bd9Sstevel@tonic-gate }
50