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