VBoxService-solaris.cpp revision 6d8ddfc2d0a8ef9330eb5bc2de92fdeeb1309577
/** $Id$ */
/** @file
* VBoxService - Guest Additions Service Skeleton.
*/
/*
* Copyright (C) 2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
/**
* Solaris daemon() call uses libdaemon.
*
* @returns 0 on success
*/
{
if (pid < 0)
{
return -1;
}
if (pid)
exit(0);
daemon_close_all(-1);
return 0;
#if 0
return -1;
if (pid < 0) /* The fork() failed. Bad. */
return -1;
if (pid > 0) /* Quit parent process */
exit(0);
/*
* The orphaned child becomes a daemon after attaching to init. We need to get
* rid of signals, file descriptors & other stuff we inherited from the parent.
*/
setsid();
int size = getdtablesize();
if (size < 0)
size = 2;
for (int i = size; i >= 0; i--)
close(i);
/* Switch our current directory to root */
if (!nochdir)
/* Set file permission to something secure. */
umask(027);
if (noclose) /* Presuming this means ignore SIGTERM, SIGHUP... */
{
}
return 0;
#endif
}