xref: /illumos-gate/usr/src/lib/libwrap/clean_exit.c (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate  /*
77c478bd9Sstevel@tonic-gate   * clean_exit() cleans up and terminates the program. It should be called
87c478bd9Sstevel@tonic-gate   * instead of exit() when for some reason the real network daemon will not or
97c478bd9Sstevel@tonic-gate   * cannot be run. Reason: in the case of a datagram-oriented service we must
107c478bd9Sstevel@tonic-gate   * discard the not-yet received data from the client. Otherwise, inetd will
117c478bd9Sstevel@tonic-gate   * see the same datagram again and again, and go into a loop.
12*1da57d55SToomas Soome   *
137c478bd9Sstevel@tonic-gate   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
147c478bd9Sstevel@tonic-gate   */
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate #ifndef lint
177c478bd9Sstevel@tonic-gate static char sccsid[] = "@(#) clean_exit.c 1.4 94/12/28 17:42:19";
187c478bd9Sstevel@tonic-gate #endif
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #include <stdio.h>
217c478bd9Sstevel@tonic-gate #include <stdlib.h>
227c478bd9Sstevel@tonic-gate #include <unistd.h>
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate extern void exit();
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include "tcpd.h"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /* clean_exit - clean up and exit */
297c478bd9Sstevel@tonic-gate 
clean_exit(request)307c478bd9Sstevel@tonic-gate void    clean_exit(request)
317c478bd9Sstevel@tonic-gate struct request_info *request;
327c478bd9Sstevel@tonic-gate {
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate     /*
357c478bd9Sstevel@tonic-gate      * In case of unconnected protocols we must eat up the not-yet received
367c478bd9Sstevel@tonic-gate      * data or inetd will loop.
377c478bd9Sstevel@tonic-gate      */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate     if (request->sink)
407c478bd9Sstevel@tonic-gate 	request->sink(request->fd);
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate     /*
437c478bd9Sstevel@tonic-gate      * Be kind to the inetd. We already reported the problem via the syslogd,
447c478bd9Sstevel@tonic-gate      * and there is no need for additional garbage in the logfile.
457c478bd9Sstevel@tonic-gate      */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate     sleep(5);
487c478bd9Sstevel@tonic-gate     exit(0);
497c478bd9Sstevel@tonic-gate }
50