VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/process-posix.cpp@ 34147

Last change on this file since 34147 was 33602, checked in by vboxsync, 14 years ago

IPRT/r3/posix: Split out RTPathUserHome and the process creation APIs into separate files to avoid linker warnings on linux when linking statically.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/* $Id: process-posix.cpp 33602 2010-10-29 12:39:54Z vboxsync $ */
2/** @file
3 * IPRT - Process, POSIX.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28
29/*******************************************************************************
30* Header Files *
31*******************************************************************************/
32#define LOG_GROUP RTLOGGROUP_PROCESS
33#include <unistd.h>
34#include <stdlib.h>
35#include <errno.h>
36#include <sys/types.h>
37#include <sys/stat.h>
38#include <sys/wait.h>
39#include <signal.h>
40
41#include <iprt/process.h>
42#include "internal/iprt.h"
43
44#include <iprt/assert.h>
45#include <iprt/env.h>
46#include <iprt/err.h>
47#include <iprt/file.h>
48#include <iprt/pipe.h>
49#include <iprt/socket.h>
50#include <iprt/string.h>
51#include <iprt/mem.h>
52#include "internal/process.h"
53
54
55RTR3DECL(int) RTProcWait(RTPROCESS Process, unsigned fFlags, PRTPROCSTATUS pProcStatus)
56{
57 int rc;
58 do rc = RTProcWaitNoResume(Process, fFlags, pProcStatus);
59 while (rc == VERR_INTERRUPTED);
60 return rc;
61}
62
63
64RTR3DECL(int) RTProcWaitNoResume(RTPROCESS Process, unsigned fFlags, PRTPROCSTATUS pProcStatus)
65{
66 /*
67 * Validate input.
68 */
69 if (Process <= 0)
70 {
71 AssertMsgFailed(("Invalid Process=%d\n", Process));
72 return VERR_INVALID_PARAMETER;
73 }
74 if (fFlags & ~(RTPROCWAIT_FLAGS_NOBLOCK | RTPROCWAIT_FLAGS_BLOCK))
75 {
76 AssertMsgFailed(("Invalid flags %#x\n", fFlags));
77 return VERR_INVALID_PARAMETER;
78 }
79
80 /*
81 * Perform the wait.
82 */
83 int iStatus = 0;
84 int rc = waitpid(Process, &iStatus, fFlags & RTPROCWAIT_FLAGS_NOBLOCK ? WNOHANG : 0);
85 if (rc > 0)
86 {
87 /*
88 * Fill in the status structure.
89 */
90 if (pProcStatus)
91 {
92 if (WIFEXITED(iStatus))
93 {
94 pProcStatus->enmReason = RTPROCEXITREASON_NORMAL;
95 pProcStatus->iStatus = WEXITSTATUS(iStatus);
96 }
97 else if (WIFSIGNALED(iStatus))
98 {
99 pProcStatus->enmReason = RTPROCEXITREASON_SIGNAL;
100 pProcStatus->iStatus = WTERMSIG(iStatus);
101 }
102 else
103 {
104 Assert(!WIFSTOPPED(iStatus));
105 pProcStatus->enmReason = RTPROCEXITREASON_ABEND;
106 pProcStatus->iStatus = iStatus;
107 }
108 }
109 return VINF_SUCCESS;
110 }
111
112 /*
113 * Child running?
114 */
115 if (!rc)
116 {
117 Assert(fFlags & RTPROCWAIT_FLAGS_NOBLOCK);
118 return VERR_PROCESS_RUNNING;
119 }
120
121 /*
122 * Figure out which error to return.
123 */
124 int iErr = errno;
125 if (iErr == ECHILD)
126 return VERR_PROCESS_NOT_FOUND;
127 return RTErrConvertFromErrno(iErr);
128}
129
130
131RTR3DECL(int) RTProcTerminate(RTPROCESS Process)
132{
133 if (!kill(Process, SIGKILL))
134 return VINF_SUCCESS;
135 return RTErrConvertFromErrno(errno);
136}
137
138
139RTR3DECL(uint64_t) RTProcGetAffinityMask(void)
140{
141 /// @todo
142 return 1;
143}
144
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette