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