250a073308fb9258903f57b76eeb2470c6926efeth * CDDL HEADER START
250a073308fb9258903f57b76eeb2470c6926efeth * The contents of this file are subject to the terms of the
250a073308fb9258903f57b76eeb2470c6926efeth * Common Development and Distribution License (the "License").
250a073308fb9258903f57b76eeb2470c6926efeth * You may not use this file except in compliance with the License.
250a073308fb9258903f57b76eeb2470c6926efeth * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
250a073308fb9258903f57b76eeb2470c6926efeth * See the License for the specific language governing permissions
250a073308fb9258903f57b76eeb2470c6926efeth * and limitations under the License.
250a073308fb9258903f57b76eeb2470c6926efeth * When distributing Covered Code, include this CDDL HEADER in each
250a073308fb9258903f57b76eeb2470c6926efeth * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
250a073308fb9258903f57b76eeb2470c6926efeth * If applicable, add the following below this CDDL HEADER, with the
250a073308fb9258903f57b76eeb2470c6926efeth * fields enclosed by brackets "[]" replaced with your own identifying
250a073308fb9258903f57b76eeb2470c6926efeth * information: Portions Copyright [yyyy] [name of copyright owner]
250a073308fb9258903f57b76eeb2470c6926efeth * CDDL HEADER END
250a073308fb9258903f57b76eeb2470c6926efeth * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
250a073308fb9258903f57b76eeb2470c6926efeth * Use is subject to license terms.
250a073308fb9258903f57b76eeb2470c6926efeth/* LINTLIBRARY */
250a073308fb9258903f57b76eeb2470c6926efeth/* PROTOLIB1 */
250a073308fb9258903f57b76eeb2470c6926efeth#pragma ident "%Z%%M% %I% %E% SMI"
250a073308fb9258903f57b76eeb2470c6926efeth/* NFS server */
250a073308fb9258903f57b76eeb2470c6926efeth * The parent never returns from this function. It sits
250a073308fb9258903f57b76eeb2470c6926efeth * and waits for the child to send status on whether it
250a073308fb9258903f57b76eeb2470c6926efeth * loaded or not.
250a073308fb9258903f57b76eeb2470c6926efeth * We do not close down the standard file descriptors until
250a073308fb9258903f57b76eeb2470c6926efeth * we know the child is going to run.
250a073308fb9258903f57b76eeb2470c6926efeth * Block all signals prior to the fork and leave them blocked in the
250a073308fb9258903f57b76eeb2470c6926efeth * parent so we don't get in a situation where the parent gets SIGINT
250a073308fb9258903f57b76eeb2470c6926efeth * and returns non-zero exit status and the child is actually running.
250a073308fb9258903f57b76eeb2470c6926efeth * In the child, restore the signal mask once we've done our setsid().
250a073308fb9258903f57b76eeb2470c6926efeth * We need to do this before we open the pipe - it makes things
250a073308fb9258903f57b76eeb2470c6926efeth * easier in the long run.
250a073308fb9258903f57b76eeb2470c6926efeth if (pid != 0) {
250a073308fb9258903f57b76eeb2470c6926efeth if (read(pfds[0], &status, sizeof (status)) == sizeof (status))
250a073308fb9258903f57b76eeb2470c6926efeth if (waitpid(pid, &status, 0) == pid && WIFEXITED(status))
250a073308fb9258903f57b76eeb2470c6926efeth * All child from here on...
250a073308fb9258903f57b76eeb2470c6926efeth * We are only a daemon if the file descriptor is valid.