process-posix.cpp revision 4258056666cdfa65d5e643f1b8c84e7de176d67e
/* $Id$ */
/** @file
* InnoTek Portable Runtime - Process, POSIX.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_PROCESS
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
# define HAVE_POSIX_SPAWN 1
#endif
#ifdef HAVE_POSIX_SPAWN
# include <spawn.h>
#endif
#ifdef __DARWIN__
#endif
RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, const char * const *papszEnv, unsigned fFlags, PRTPROCESS pProcess)
{
/*
* Validate input.
*/
{
AssertMsgFailed(("no exec\n"));
return VERR_INVALID_PARAMETER;
}
if (fFlags)
{
AssertMsgFailed(("invalid flags!\n"));
return VERR_INVALID_PARAMETER;
}
/* later: path searching. */
/*
* Check for execute access to the file.
*/
{
return rc;
}
#if 0
/*
* Squeeze gdb --args in front of what's being spawned.
*/
unsigned cArgs = 0;
cArgs++;
cArgs += 3;
papszArgsTmp[0] = "/usr/bin/gdb";
for (unsigned i = 1; papszArgs[i]; i++)
pszExec = papszArgsTmp[0];
#endif
/*
* Spawn the child.
*/
#ifdef HAVE_POSIX_SPAWN
/** @todo check if it requires any of those two attributes, don't remember atm. */
if (!rc)
{
if (pProcess)
return VINF_SUCCESS;
}
#else
if (!pid)
{
int rc;
if (papszEnv)
else
exit(127);
}
if (pid > 0)
{
if (pProcess)
return VINF_SUCCESS;
}
#endif
/* failure, errno value in rc. */
return RTErrConvertFromErrno(rc);
}
{
int rc;
while (rc == VERR_INTERRUPTED);
return rc;
}
{
/*
* Validate input.
*/
if (Process <= 0)
{
return VERR_INVALID_PARAMETER;
}
{
return VERR_INVALID_PARAMETER;
}
/*
* Performe the wait.
*/
int iStatus = 0;
if (rc > 0)
{
/*
* Fill in the status structure.
*/
if (pProcStatus)
{
{
}
else if (WIFSIGNALED(iStatus))
{
}
else
{
}
}
return VINF_SUCCESS;
}
/*
* Child running?
*/
if (!rc)
{
return VERR_PROCESS_RUNNING;
}
/*
* Figure out which error to return.
*/
return VERR_PROCESS_NOT_FOUND;
return RTErrConvertFromErrno(iErr);
}
{
return VINF_SUCCESS;
return RTErrConvertFromErrno(errno);
}
{
// @todo
return 1;
}
{
/*
* I don't think there is a posix API for this, but
* because I'm lazy I'm not creating OS specific code
* files and code for this.
*/
#if defined(__LINUX__) || defined(__FREEBSD__)
# ifdef __LINUX__
# else
# endif
{
return pszExecName;
}
return pszExecName;
#elif defined(__DARWIN__)
const char *pszImageName = _dyld_get_image_name(0);
if (pszImageName)
{
if (cchImageName < cchExecName)
}
#else
# error "Port me!"
#endif
return NULL;
}