本文整理汇总了C++中RTErrConvertFromErrno函数的典型用法代码示例。如果您正苦于以下问题:C++ RTErrConvertFromErrno函数的具体用法?C++ RTErrConvertFromErrno怎么用?C++ RTErrConvertFromErrno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTErrConvertFromErrno函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: RTDECL
RTDECL(int) RTFileAioReqGetRC(RTFILEAIOREQ hReq, size_t *pcbTransfered)
{
PRTFILEAIOREQINTERNAL pReqInt = hReq;
RTFILEAIOREQ_VALID_RETURN(pReqInt);
RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, PREPARED, VERR_FILE_AIO_NOT_SUBMITTED);
AssertPtrNull(pcbTransfered);
int rcSol = aio_error(&pReqInt->AioCB);
Assert(rcSol != EINPROGRESS); /* Handled by our own state handling. */
if (rcSol == 0)
{
if (pcbTransfered)
*pcbTransfered = aio_return(&pReqInt->AioCB);
return VINF_SUCCESS;
}
/* An error occurred. */
return RTErrConvertFromErrno(rcSol);
}
开发者ID:svn2github,项目名称:virtualbox,代码行数:21,代码来源:fileaio-solaris.cpp
示例2: RTR3DECL
/**
* Rewinds the stream.
*
* Stream errors will be reset on success.
*
* @returns IPRT status code.
*
* @param pStream The stream.
*
* @remarks Not all streams are rewindable and that behavior is currently
* undefined for those.
*/
RTR3DECL(int) RTStrmRewind(PRTSTREAM pStream)
{
AssertPtrReturn(pStream, VERR_INVALID_HANDLE);
AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_HANDLE);
int rc;
clearerr(pStream->pFile);
errno = 0;
if (!fseek(pStream->pFile, 0, SEEK_SET))
{
ASMAtomicWriteS32(&pStream->i32Error, VINF_SUCCESS);
rc = VINF_SUCCESS;
}
else
{
rc = RTErrConvertFromErrno(errno);
ASMAtomicWriteS32(&pStream->i32Error, rc);
}
return rc;
}
开发者ID:eaas-framework,项目名称:virtualbox,代码行数:33,代码来源:stream.cpp
示例3: RTR3DECL
RTR3DECL(int) RTThreadSetAffinity(PCRTCPUSET pCpuSet)
{
/* convert */
cpu_set_t LnxCpuSet;
CPU_ZERO(&LnxCpuSet);
if (!pCpuSet)
for (unsigned iCpu = 0; iCpu < CPU_SETSIZE; iCpu++)
CPU_SET(iCpu, &LnxCpuSet);
else
for (unsigned iCpu = 0; iCpu < RT_MIN(CPU_SETSIZE, RTCPUSET_MAX_CPUS); iCpu++)
if (RTCpuSetIsMemberByIndex(pCpuSet, iCpu))
CPU_SET(iCpu, &LnxCpuSet);
int rc = pthread_setaffinity_np(pthread_self(), sizeof(LnxCpuSet), &LnxCpuSet);
if (!rc)
return VINF_SUCCESS;
rc = errno;
if (rc == ENOENT)
return VERR_CPU_NOT_FOUND;
return RTErrConvertFromErrno(errno);
}
开发者ID:miguelinux,项目名称:vbox,代码行数:21,代码来源:thread-affinity-linux.cpp
示例4: DECLCALLBACK
/**
* @interface_method_impl{PDMIBASE,pfnRead}
*/
static DECLCALLBACK(int) drvHostParallelRead(PPDMIHOSTPARALLELCONNECTOR pInterface, void *pvBuf, size_t cbRead, PDMPARALLELPORTMODE enmMode)
{
PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
int rc = VINF_SUCCESS;
# ifndef VBOX_WITH_WIN_PARPORT_SUP
int rcLnx = 0;
LogFlowFunc(("pvBuf=%#p cbRead=%d\n", pvBuf, cbRead));
rc = drvHostParallelSetMode(pThis, enmMode);
if (RT_FAILURE(rc))
return rc;
if (enmMode == PDM_PARALLEL_PORT_MODE_SPP)
{
/* Set the data lines directly. */
rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWDATA, pvBuf);
}
else
{
/* Use write interface. */
rcLnx = read(RTFileToNative(pThis->hFileDevice), pvBuf, cbRead);
}
if (RT_UNLIKELY(rcLnx < 0))
rc = RTErrConvertFromErrno(errno);
# else /* VBOX_WITH_WIN_PARPORT_SUP */
if (pThis->fParportAvail)
{
*((uint8_t*)(pvBuf)) = 0; /* Initialize the buffer. */
for (size_t i = 0; i < cbRead; i++)
{
LogFlowFunc(("calling R0 to read from parallel port\n"));
int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0);
AssertRC(rc);
*((uint8_t *)pvBuf + i) = (uint8_t)pThis->u8ReadIn;
}
}
# endif /* VBOX_WITH_WIN_PARPORT_SUP */
return rc;
}
开发者ID:Klanly,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:43,代码来源:DrvHostParallel.cpp
示例5: drvHostParallelSetMode
/**
* Changes the current mode of the host parallel port.
*
* @returns VBox status code.
* @param pThis The host parallel port instance data.
* @param enmMode The mode to change the port to.
*/
static int drvHostParallelSetMode(PDRVHOSTPARALLEL pThis, PDMPARALLELPORTMODE enmMode)
{
int iMode = 0;
int rc = VINF_SUCCESS;
LogFlowFunc(("mode=%d\n", enmMode));
# ifndef VBOX_WITH_WIN_PARPORT_SUP
int rcLnx;
if (pThis->enmModeCur != enmMode)
{
switch (enmMode)
{
case PDM_PARALLEL_PORT_MODE_SPP:
iMode = IEEE1284_MODE_COMPAT;
break;
case PDM_PARALLEL_PORT_MODE_EPP_DATA:
iMode = IEEE1284_MODE_EPP | IEEE1284_DATA;
break;
case PDM_PARALLEL_PORT_MODE_EPP_ADDR:
iMode = IEEE1284_MODE_EPP | IEEE1284_ADDR;
break;
case PDM_PARALLEL_PORT_MODE_ECP:
case PDM_PARALLEL_PORT_MODE_INVALID:
default:
return VERR_NOT_SUPPORTED;
}
rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPSETMODE, &iMode);
if (RT_UNLIKELY(rcLnx < 0))
rc = RTErrConvertFromErrno(errno);
else
pThis->enmModeCur = enmMode;
}
return rc;
# else /* VBOX_WITH_WIN_PARPORT_SUP */
return VINF_SUCCESS;
# endif /* VBOX_WITH_WIN_PARPORT_SUP */
}
开发者ID:Klanly,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:46,代码来源:DrvHostParallel.cpp
示例6: RTR3DECL
RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties)
{
/*
* Validate.
*/
AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
AssertMsgReturn(VALID_PTR(pProperties), ("%p", pProperties), VERR_INVALID_PARAMETER);
/*
* Convert the path and query the information.
*/
char const *pszNativeFsPath;
int rc = rtPathToNative(&pszNativeFsPath, pszFsPath, NULL);
if (RT_SUCCESS(rc))
{
struct statvfs StatVFS;
RT_ZERO(StatVFS);
if (!statvfs(pszNativeFsPath, &StatVFS))
{
/*
* Calc/fake the returned values.
*/
pProperties->cbMaxComponent = StatVFS.f_namemax;
pProperties->fCaseSensitive = true;
pProperties->fCompressed = false;
pProperties->fFileCompression = false;
pProperties->fReadOnly = !!(StatVFS.f_flag & ST_RDONLY);
pProperties->fRemote = false;
pProperties->fSupportsUnicode = true;
}
else
rc = RTErrConvertFromErrno(errno);
rtPathFreeNative(pszNativeFsPath, pszFsPath);
}
LogFlow(("RTFsQueryProperties(%p:{%s}, %p:{.cbMaxComponent=%u, .fCaseSensitive=%RTbool}): returns %Rrc\n",
pszFsPath, pszFsPath, pProperties, pProperties->cbMaxComponent, pProperties->fReadOnly));
return VINF_SUCCESS;
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:39,代码来源:fs-posix.cpp
示例7: RTDECL
RTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq)
{
PRTFILEAIOREQINTERNAL pReqInt = hReq;
RTFILEAIOREQ_VALID_RETURN(pReqInt);
RTFILEAIOREQ_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_NOT_SUBMITTED);
ASMAtomicXchgBool(&pReqInt->fCanceled, true);
int rcPosix = aio_cancel(pReqInt->AioCB.aio_fildes, &pReqInt->AioCB);
if (rcPosix == AIO_CANCELED)
{
PRTFILEAIOCTXINTERNAL pCtxInt = pReqInt->pCtxInt;
/*
* Notify the waiting thread that the request was canceled.
*/
AssertMsg(VALID_PTR(pCtxInt),
("Invalid state. Request was canceled but wasn't submitted\n"));
Assert(!pCtxInt->pReqToCancel);
ASMAtomicWritePtr(&pCtxInt->pReqToCancel, pReqInt);
rtFileAioCtxWakeup(pCtxInt);
/* Wait for acknowledge. */
int rc = RTSemEventWait(pCtxInt->SemEventCancel, RT_INDEFINITE_WAIT);
AssertRC(rc);
ASMAtomicWriteNullPtr(&pCtxInt->pReqToCancel);
pReqInt->Rc = VERR_FILE_AIO_CANCELED;
RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
return VINF_SUCCESS;
}
else if (rcPosix == AIO_ALLDONE)
return VERR_FILE_AIO_COMPLETED;
else if (rcPosix == AIO_NOTCANCELED)
return VERR_FILE_AIO_IN_PROGRESS;
else
return RTErrConvertFromErrno(errno);
}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:39,代码来源:fileaio-posix.cpp
示例8: RTDECL
RTDECL(int) RTEnvSetBad(const char *pszVar, const char *pszValue)
{
AssertMsgReturn(strchr(pszVar, '=') == NULL, ("'%s'\n", pszVar), VERR_ENV_INVALID_VAR_NAME);
/* make a local copy and feed it to putenv. */
const size_t cchVar = strlen(pszVar);
const size_t cchValue = strlen(pszValue);
char *pszTmp = (char *)alloca(cchVar + cchValue + 2 + !*pszValue);
memcpy(pszTmp, pszVar, cchVar);
pszTmp[cchVar] = '=';
if (*pszValue)
memcpy(pszTmp + cchVar + 1, pszValue, cchValue + 1);
else
{
pszTmp[cchVar + 1] = ' '; /* wrong, but putenv will remove it otherwise. */
pszTmp[cchVar + 2] = '\0';
}
if (!putenv(pszTmp))
return 0;
return RTErrConvertFromErrno(errno);
}
开发者ID:svn2github,项目名称:virtualbox,代码行数:22,代码来源:env-win.cpp
示例9: DECLCALLBACK
/**
* interface_method_impl{SUPDRVTRACERREG,pfnProviderRegister}
*/
static DECLCALLBACK(int) vboxDtTOps_ProviderRegister(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore)
{
LOG_DTRACE(("%s: %p %s/%s\n", __FUNCTION__, pThis, pCore->pszModName, pCore->pszName));
AssertReturn(pCore->TracerData.DTrace.idProvider == 0, VERR_INTERNAL_ERROR_3);
PVTGDESCPROVIDER pDesc = pCore->pDesc;
dtrace_pattr_t DtAttrs;
vboxDtVtgConvAttr(&DtAttrs.dtpa_provider, &pDesc->AttrSelf);
vboxDtVtgConvAttr(&DtAttrs.dtpa_mod, &pDesc->AttrModules);
vboxDtVtgConvAttr(&DtAttrs.dtpa_func, &pDesc->AttrFunctions);
vboxDtVtgConvAttr(&DtAttrs.dtpa_name, &pDesc->AttrNames);
vboxDtVtgConvAttr(&DtAttrs.dtpa_args, &pDesc->AttrArguments);
/* Note! DTrace may call us back before dtrace_register returns, so we
have to point it to pCore->TracerData.DTrace.idProvider. */
AssertCompile(sizeof(dtrace_provider_id_t) == sizeof(pCore->TracerData.DTrace.idProvider));
int rc = dtrace_register(pCore->pszName,
&DtAttrs,
DTRACE_PRIV_KERNEL,
NULL /* cred */,
&g_vboxDtVtgProvOps,
pCore,
&pCore->TracerData.DTrace.idProvider);
if (!rc)
{
LOG_DTRACE(("%s: idProvider=%p\n", __FUNCTION__, pCore->TracerData.DTrace.idProvider));
AssertPtr(pCore->TracerData.DTrace.idProvider);
rc = VINF_SUCCESS;
}
else
{
pCore->TracerData.DTrace.idProvider = 0;
rc = RTErrConvertFromErrno(FIX_UEK_RC(rc));
}
LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc));
return rc;
}
开发者ID:bayasist,项目名称:vbox,代码行数:41,代码来源:SUPDrv-dtrace.cpp
示例10: RTDECL
RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
{
LogFlow(("RTThreadSleep: cMillies=%d\n", cMillies));
if (!cMillies)
{
/* pthread_yield() isn't part of SuS, thus this fun. */
#ifdef RT_OS_DARWIN
pthread_yield_np();
#elif defined(RT_OS_FREEBSD) /* void pthread_yield */
pthread_yield();
#elif defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU)
sched_yield();
#else
if (!pthread_yield())
#endif
{
LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", VINF_SUCCESS, cMillies));
return VINF_SUCCESS;
}
}
else
{
struct timespec ts;
struct timespec tsrem = {0,0};
ts.tv_nsec = (cMillies % 1000) * 1000000;
ts.tv_sec = cMillies / 1000;
if (!nanosleep(&ts, &tsrem))
{
LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", VINF_SUCCESS, cMillies));
return VINF_SUCCESS;
}
}
int rc = RTErrConvertFromErrno(errno);
LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", rc, cMillies));
return rc;
}
开发者ID:bayasist,项目名称:vbox,代码行数:38,代码来源:thread2-posix.cpp
示例11: RTR3DECL
RTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
{
/*
* We can only set AccessTime and ModificationTime, so if neither
* are specified we can return immediately.
*/
if (!pAccessTime && !pModificationTime)
return VINF_SUCCESS;
/*
* Convert the input to timeval, getting the missing one if necessary,
* and call the API which does the change.
*/
struct timeval aTimevals[2];
if (pAccessTime && pModificationTime)
{
RTTimeSpecGetTimeval(pAccessTime, &aTimevals[0]);
RTTimeSpecGetTimeval(pModificationTime, &aTimevals[1]);
}
else
{
RTFSOBJINFO ObjInfo;
int rc = RTFileQueryInfo(hFile, &ObjInfo, RTFSOBJATTRADD_UNIX);
if (RT_FAILURE(rc))
return rc;
RTTimeSpecGetTimeval(pAccessTime ? pAccessTime : &ObjInfo.AccessTime, &aTimevals[0]);
RTTimeSpecGetTimeval(pModificationTime ? pModificationTime : &ObjInfo.ModificationTime, &aTimevals[1]);
}
if (futimes(RTFileToNative(hFile), aTimevals))
{
int rc = RTErrConvertFromErrno(errno);
Log(("RTFileSetTimes(%RTfile,%p,%p,,): returns %Rrc\n", hFile, pAccessTime, pModificationTime, rc));
return rc;
}
return VINF_SUCCESS;
}
开发者ID:virendramishra,项目名称:VirtualBox4.1.18,代码行数:38,代码来源:fileio2-posix.cpp
示例12: DECLHIDDEN
DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThread, PRTNATIVETHREAD pNativeThread)
{
/*
* Default stack size.
*/
if (!pThread->cbStack)
pThread->cbStack = 512*1024;
/*
* Create the thread.
*/
int iThreadId = _beginthread(rtThreadNativeMain, NULL, pThread->cbStack, pThread);
if (iThreadId > 0)
{
#ifdef fibGetTidPid
*pNativeThread = iThreadId | (fibGetPid() << 16);
#else
*pNativeThread = iThreadId;
#endif
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:23,代码来源:thread-os2.cpp
示例13: RTR3DECL
RTR3DECL(int) RTFileQueryFsSizes(RTFILE hFile, PRTFOFF pcbTotal, RTFOFF *pcbFree,
uint32_t *pcbBlock, uint32_t *pcbSector)
{
struct statvfs StatVFS;
RT_ZERO(StatVFS);
if (fstatvfs(RTFileToNative(hFile), &StatVFS))
return RTErrConvertFromErrno(errno);
/*
* Calc the returned values.
*/
if (pcbTotal)
*pcbTotal = (RTFOFF)StatVFS.f_blocks * StatVFS.f_frsize;
if (pcbFree)
*pcbFree = (RTFOFF)StatVFS.f_bavail * StatVFS.f_frsize;
if (pcbBlock)
*pcbBlock = StatVFS.f_frsize;
/* no idea how to get the sector... */
if (pcbSector)
*pcbSector = 512;
return VINF_SUCCESS;
}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:23,代码来源:RTFileQueryFsSizes-posix.cpp
示例14: RTDECL
RTDECL(int) RTKrnlModLoadedQueryInfo(const char *pszName, PRTKRNLMODINFO phKrnlModInfo)
{
AssertPtrReturn(pszName, VERR_INVALID_POINTER);
AssertPtrReturn(phKrnlModInfo, VERR_INVALID_POINTER);
int rc = VERR_NOT_FOUND;
int iId = -1;
struct modinfo ModInfo;
ModInfo.mi_info = MI_INFO_ALL | MI_INFO_CNT;
ModInfo.mi_id = iId;
ModInfo.mi_nextid = iId;
do
{
int rcSol = modctl(MODINFO, iId, &ModInfo);
if (rcSol < 0)
{
rc = RTErrConvertFromErrno(errno);
break;
}
if (ModInfo.mi_id != -1)
{
ModInfo.mi_name[MODMAXNAMELEN - 1] = '\0'; /* Paranoia. */
if (!RTStrCmp(pszName, &ModInfo.mi_name[0]))
{
rc = rtKrnlModSolInfoCreate(&ModInfo, phKrnlModInfo);
break;
}
}
iId = ModInfo.mi_id;
} while (iId != -1);
return rc;
}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:36,代码来源:krnlmod-solaris.cpp
示例15: DECL_FORCE_INLINE
//.........这里部分代码省略.........
ts.tv_nsec = (cMillies % 1000) * UINT32_C(1000000);
u64End = RTTimeSystemNanoTS() + cMillies * UINT64_C(1000000);
pTimeout = &ts;
}
/*
* Lock the mutex.
* Optimize for the uncontended case (makes 1-2 ns difference).
*/
if (RT_UNLIKELY(!ASMAtomicCmpXchgS32(&pThis->iState, 1, 0)))
{
for (;;)
{
int32_t iOld = ASMAtomicXchgS32(&pThis->iState, 2);
/*
* Was the lock released in the meantime? This is unlikely (but possible)
*/
if (RT_UNLIKELY(iOld == 0))
break;
/*
* Go to sleep.
*/
if (pTimeout && ( pTimeout->tv_sec || pTimeout->tv_nsec ))
{
#ifdef RTSEMMUTEX_STRICT
int rc9 = RTLockValidatorRecExclCheckBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true,
cMillies, RTTHREADSTATE_MUTEX, true);
if (RT_FAILURE(rc9))
return rc9;
#else
RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX, true);
#endif
}
long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 2, pTimeout, NULL, 0);
RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_MUTEX);
if (RT_UNLIKELY(pThis->u32Magic != RTSEMMUTEX_MAGIC))
return VERR_SEM_DESTROYED;
/*
* Act on the wakup code.
*/
if (rc == -ETIMEDOUT)
{
Assert(pTimeout);
return VERR_TIMEOUT;
}
if (rc == 0)
/* we'll leave the loop now unless another thread is faster */;
else if (rc == -EWOULDBLOCK)
/* retry with new value. */;
else if (rc == -EINTR)
{
if (!fAutoResume)
return VERR_INTERRUPTED;
}
else
{
/* this shouldn't happen! */
AssertMsgFailed(("rc=%ld errno=%d\n", rc, errno));
return RTErrConvertFromErrno(rc);
}
/* adjust the relative timeout */
if (pTimeout)
{
int64_t i64Diff = u64End - RTTimeSystemNanoTS();
if (i64Diff < 1000)
{
rc = VERR_TIMEOUT;
break;
}
ts.tv_sec = (uint64_t)i64Diff / UINT32_C(1000000000);
ts.tv_nsec = (uint64_t)i64Diff % UINT32_C(1000000000);
}
}
/*
* When leaving this loop, iState is set to 2. This means that we gained the
* lock and there are _possibly_ some waiters. We don't know exactly as another
* thread might entered this loop at nearly the same time. Therefore we will
* call futex_wakeup once too often (if _no_ other thread entered this loop).
* The key problem is the simple futex_wait test for x != y (iState != 2) in
* our case).
*/
}
/*
* Set the owner and nesting.
*/
pThis->Owner = Self;
ASMAtomicWriteU32(&pThis->cNestings, 1);
#ifdef RTSEMMUTEX_STRICT
RTLockValidatorRecExclSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true);
#endif
return VINF_SUCCESS;
}
开发者ID:miguelinux,项目名称:vbox,代码行数:101,代码来源:semmutex-linux.cpp
示例16: VBGLR3DECL
//.........这里部分代码省略.........
/* VBoxServiceError("DosExecPgm failed with rc=%d and szObj='%s'\n", rc, szObj); */
return RTErrConvertFromOS2(rc);
}
DosExit(EXIT_PROCESS, 0);
return VERR_GENERAL_FAILURE;
#elif defined(RT_OS_WINDOWS)
# error "PORTME"
#else /* the unices */
/*
* Fork the child process in a new session and quit the parent.
*
* - fork once and create a new session (setsid). This will detach us
* from the controlling tty meaning that we won't receive the SIGHUP
* (or any other signal) sent to that session.
* - The SIGHUP signal is ignored because the session/parent may throw
* us one before we get to the setsid.
* - When the parent exit(0) we will become an orphan and re-parented to
* the init process.
* - Because of the Linux / System V semantics of assigning the controlling
* tty automagically when a session leader first opens a tty, we will
* fork() once more on Linux to get rid of the session leadership role.
*/
struct sigaction OldSigAct;
struct sigaction SigAct;
RT_ZERO(SigAct);
SigAct.sa_handler = SIG_IGN;
int rcSigAct = sigaction(SIGHUP, &SigAct, &OldSigAct);
pid_t pid = fork();
if (pid == -1)
return RTErrConvertFromErrno(errno);
if (pid != 0)
exit(0);
/*
* The orphaned child becomes is reparented to the init process.
* We create a new session for it (setsid), point the standard
* file descriptors to /dev/null, and change to the root directory.
*/
pid_t newpgid = setsid();
int SavedErrno = errno;
if (rcSigAct != -1)
sigaction(SIGHUP, &OldSigAct, NULL);
if (newpgid == -1)
return RTErrConvertFromErrno(SavedErrno);
if (!fNoClose)
{
/* Open stdin(0), stdout(1) and stderr(2) as /dev/null. */
int fd = open("/dev/null", O_RDWR);
if (fd == -1) /* paranoia */
{
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
fd = open("/dev/null", O_RDWR);
}
if (fd != -1)
{
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
if (fd > 2)
开发者ID:bhanug,项目名称:virtualbox,代码行数:67,代码来源:VBoxGuestR3LibDaemonize.cpp
示例17: DECLCALLBACK
/**
* Run once function that initializes the kstats we need here.
*
* @returns IPRT status code.
* @param pvUser Unused.
*/
static DECLCALLBACK(int) rtMpSolarisOnce(void *pvUser)
{
int rc = VINF_SUCCESS;
NOREF(pvUser);
/*
* Open kstat and find the cpu_info entries for each of the CPUs.
*/
g_pKsCtl = kstat_open();
if (g_pKsCtl)
{
g_capCpuInfo = RTMpGetCount();
g_papCpuInfo = (kstat_t **)RTMemAllocZ(g_capCpuInfo * sizeof(kstat_t *));
if (g_papCpuInfo)
{
g_cu64CoreIds = g_capCpuInfo;
g_pu64CoreIds = (uint64_t *)RTMemAllocZ(g_cu64CoreIds * sizeof(uint64_t));
if (g_pu64CoreIds)
{
rc = RTCritSectInit(&g_MpSolarisCritSect);
if (RT_SUCCESS(rc))
{
RTCPUID i = 0;
for (kstat_t *pKsp = g_pKsCtl->kc_chain; pKsp != NULL; pKsp = pKsp->ks_next)
{
if (!RTStrCmp(pKsp->ks_module, "cpu_info"))
{
AssertBreak(i < g_capCpuInfo);
g_papCpuInfo[i++] = pKsp;
/** @todo ks_instance == cpu_id (/usr/src/uts/common/os/cpu.c)? Check this and fix it ASAP. */
}
}
rc = rtMpSolarisGetCoreIds();
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
else
Log(("rtMpSolarisGetCoreIds failed. rc=%Rrc\n", rc));
}
RTMemFree(g_pu64CoreIds);
g_pu64CoreIds = NULL;
}
else
rc = VERR_NO_MEMORY;
/* bail out, we failed. */
RTMemFree(g_papCpuInfo);
g_papCpuInfo = NULL;
}
else
rc = VERR_NO_MEMORY;
kstat_close(g_pKsCtl);
g_pKsCtl = NULL;
}
else
{
rc = RTErrConvertFromErrno(errno);
if (RT_SUCCESS(rc))
rc = VERR_INTERNAL_ERROR;
Log(("kstat_open() -> %d (%Rrc)\n", errno, rc));
}
return rc;
}
开发者ID:sobomax,项目名称:virtualbox_64bit_edd,代码行数:71,代码来源:mp-solaris.cpp
示例18: RTR3DECL
RTR3DECL(int) RTProcDaemonizeUsingFork(bool fNoChDir, bool fNoClose, const char *pszPidfile)
{
/*
* Fork the child process in a new session and quit the parent.
*
* - fork once and create a new session (setsid). This will detach us
* from the controlling tty meaning that we won't receive the SIGHUP
* (or any other signal) sent to that session.
* - The SIGHUP signal is ignored because the session/parent may throw
* us one before we get to the setsid.
* - When the parent exit(0) we will become an orphan and re-parented to
* the init process.
* - Because of the sometimes unexpected semantics of assigning the
* controlling tty automagically when a session leader first opens a tty,
* we will fork() once more to get rid of the session leadership role.
*/
/* We start off by opening the pidfile, so that we can fail straight away
* if it already exists. */
int fdPidfile = -1;
if (pszPidfile != NULL)
{
/* @note the exclusive create is not guaranteed on all file
* systems (e.g. NFSv2) */
if ((fdPidfile = open(pszPidfile, O_RDWR | O_CREAT | O_EXCL, 0644)) == -1)
return RTErrConvertFromErrno(errno);
}
/* Ignore SIGHUP straight away. */
struct sigaction OldSigAct;
struct sigaction SigAct;
memset(&SigAct, 0, sizeof(SigAct));
SigAct.sa_handler = SIG_IGN;
int rcSigAct = sigaction(SIGHUP, &SigAct, &OldSigAct);
/* First fork, to become independent process. */
pid_t pid = fork();
if (pid == -1)
{
if (fdPidfile != -1)
close(fdPidfile);
return RTErrConvertFromErrno(errno);
}
if (pid != 0)
{
/* Parent exits, no longer necessary. The child gets reparented
* to the init process. */
exit(0);
}
/* Create new session, fix up the standard file descriptors and the
* current working directory. */
/** @todo r=klaus the webservice uses this function and assumes that the
* contract id of the daemon is the same as that of the original process.
* Whenever this code is changed this must still remain possible. */
pid_t newpgid = setsid();
int SavedErrno = errno;
if (rcSigAct != -1)
sigaction(SIGHUP, &OldSigAct, NULL);
if (newpgid == -1)
{
if (fdPidfile != -1)
close(fdPidfile);
return RTErrConvertFromErrno(SavedErrno);
}
if (!fNoClose)
{
/* Open stdin(0), stdout(1) and stderr(2) as /dev/null. */
int fd = open("/dev/null", O_RDWR);
if (fd == -1) /* paranoia */
{
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
fd = open("/dev/null", O_RDWR);
}
if (fd != -1)
{
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
if (fd > 2)
close(fd);
}
}
if (!fNoChDir)
{
int rcIgnored = chdir("/");
NOREF(rcIgnored);
}
/* Second fork to lose session leader status. */
pid = fork();
if (pid == -1)
{
if (fdPidfile != -1)
close(fdPidfile);
return RTErrConvertFromErrno(errno);
//.........这里部分代码省略.........
开发者ID:miguelinux,项目名称:vbox,代码行数:101,代码来源:process-creation-posix.cpp
注:本文中的RTErrConvertFromErrno函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论