VirtualBox

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

Last change on this file since 33602 was 33602, checked in by vboxsync, 15 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: 22.3 KB
Line 
1/* $Id: process-creation-posix.cpp 33602 2010-10-29 12:39:54Z vboxsync $ */
2/** @file
3 * IPRT - Process Creation, 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.215389.xyz. 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* Header Files *
30*******************************************************************************/
31#define LOG_GROUP RTLOGGROUP_PROCESS
32#include <unistd.h>
33#include <stdlib.h>
34#include <errno.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <sys/wait.h>
38#include <fcntl.h>
39#include <signal.h>
40#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
41# include <crypt.h>
42# include <pwd.h>
43# include <shadow.h>
44#endif
45#if defined(RT_OS_LINUX) || defined(RT_OS_OS2)
46/* While Solaris has posix_spawn() of course we don't want to use it as
47 * we need to have the child in a different process contract, no matter
48 * whether it is started detached or not. */
49# define HAVE_POSIX_SPAWN 1
50#endif
51#ifdef HAVE_POSIX_SPAWN
52# include <spawn.h>
53#endif
54#ifdef RT_OS_DARWIN
55# include <mach-o/dyld.h>
56#endif
57#ifdef RT_OS_SOLARIS
58# include <limits.h>
59# include <sys/ctfs.h>
60# include <sys/contract/process.h>
61# include <libcontract.h>
62#endif
63
64#include <iprt/process.h>
65#include "internal/iprt.h"
66
67#include <iprt/assert.h>
68#include <iprt/env.h>
69#include <iprt/err.h>
70#include <iprt/file.h>
71#include <iprt/pipe.h>
72#include <iprt/socket.h>
73#include <iprt/string.h>
74#include <iprt/mem.h>
75#include "internal/process.h"
76
77
78/**
79 * Check the credentials and return the gid/uid of user.
80 *
81 * @param pszUser username
82 * @param pszPasswd password
83 * @param gid where to store the GID of the user
84 * @param uid where to store the UID of the user
85 * @returns IPRT status code
86 */
87static int rtCheckCredentials(const char *pszUser, const char *pszPasswd, gid_t *gid, uid_t *uid)
88{
89#if defined(RT_OS_LINUX)
90 struct passwd *pw;
91
92 pw = getpwnam(pszUser);
93 if (!pw)
94 return VERR_PERMISSION_DENIED;
95
96 if (!pszPasswd)
97 pszPasswd = "";
98
99 struct spwd *spwd;
100 /* works only if /etc/shadow is accessible */
101 spwd = getspnam(pszUser);
102 if (spwd)
103 pw->pw_passwd = spwd->sp_pwdp;
104
105 /* be reentrant */
106 struct crypt_data *data = (struct crypt_data*)RTMemTmpAllocZ(sizeof(*data));
107 char *pszEncPasswd = crypt_r(pszPasswd, pw->pw_passwd, data);
108 if (strcmp(pszEncPasswd, pw->pw_passwd))
109 return VERR_PERMISSION_DENIED;
110 RTMemTmpFree(data);
111
112 *gid = pw->pw_gid;
113 *uid = pw->pw_uid;
114 return VINF_SUCCESS;
115
116#elif defined(RT_OS_SOLARIS)
117 struct passwd *ppw, pw;
118 char szBuf[1024];
119
120 if (getpwnam_r(pszUser, &pw, szBuf, sizeof(szBuf), &ppw) != 0 || ppw == NULL)
121 return VERR_PERMISSION_DENIED;
122
123 if (!pszPasswd)
124 pszPasswd = "";
125
126 struct spwd spwd;
127 char szPwdBuf[1024];
128 /* works only if /etc/shadow is accessible */
129 if (getspnam_r(pszUser, &spwd, szPwdBuf, sizeof(szPwdBuf)) != NULL)
130 ppw->pw_passwd = spwd.sp_pwdp;
131
132 char *pszEncPasswd = crypt(pszPasswd, ppw->pw_passwd);
133 if (strcmp(pszEncPasswd, ppw->pw_passwd))
134 return VERR_PERMISSION_DENIED;
135
136 *gid = ppw->pw_gid;
137 *uid = ppw->pw_uid;
138 return VINF_SUCCESS;
139
140#else
141 return VERR_PERMISSION_DENIED;
142#endif
143}
144
145
146#ifdef RT_OS_SOLARIS
147/** @todo the error reporting of the Solaris process contract code could be
148 * a lot better, but essentially it is not meant to run into errors after
149 * the debugging phase. */
150static int rtSolarisContractPreFork(void)
151{
152 int templateFd = open64(CTFS_ROOT "/process/template", O_RDWR);
153 if (templateFd < 0)
154 return -1;
155
156 /* Set template parameters and event sets. */
157 if (ct_pr_tmpl_set_param(templateFd, CT_PR_PGRPONLY))
158 {
159 close(templateFd);
160 return -1;
161 }
162 if (ct_pr_tmpl_set_fatal(templateFd, CT_PR_EV_HWERR))
163 {
164 close(templateFd);
165 return -1;
166 }
167 if (ct_tmpl_set_critical(templateFd, 0))
168 {
169 close(templateFd);
170 return -1;
171 }
172 if (ct_tmpl_set_informative(templateFd, CT_PR_EV_HWERR))
173 {
174 close(templateFd);
175 return -1;
176 }
177
178 /* Make this the active template for the process. */
179 if (ct_tmpl_activate(templateFd))
180 {
181 close(templateFd);
182 return -1;
183 }
184
185 return templateFd;
186}
187
188static void rtSolarisContractPostForkChild(int templateFd)
189{
190 if (templateFd == -1)
191 return;
192
193 /* Clear the active template. */
194 ct_tmpl_clear(templateFd);
195 close(templateFd);
196}
197
198static void rtSolarisContractPostForkParent(int templateFd, pid_t pid)
199{
200 if (templateFd == -1)
201 return;
202
203 /* Clear the active template. */
204 int cleared = ct_tmpl_clear(templateFd);
205 close(templateFd);
206
207 /* If the clearing failed or the fork failed there's nothing more to do. */
208 if (cleared || pid <= 0)
209 return;
210
211 /* Look up the contract which was created by this thread. */
212 int statFd = open64(CTFS_ROOT "/process/latest", O_RDONLY);
213 if (statFd == -1)
214 return;
215 ct_stathdl_t statHdl;
216 if (ct_status_read(statFd, CTD_COMMON, &statHdl))
217 {
218 close(statFd);
219 return;
220 }
221 ctid_t ctId = ct_status_get_id(statHdl);
222 ct_status_free(statHdl);
223 close(statFd);
224 if (ctId < 0)
225 return;
226
227 /* Abandon this contract we just created. */
228 char ctlPath[PATH_MAX];
229 size_t len = snprintf(ctlPath, sizeof(ctlPath),
230 CTFS_ROOT "/process/%d/ctl", ctId);
231 if (len >= sizeof(ctlPath))
232 return;
233 int ctlFd = open64(ctlPath, O_WRONLY);
234 if (statFd == -1)
235 return;
236 if (ct_ctl_abandon(ctlFd) < 0)
237 {
238 close(ctlFd);
239 return;
240 }
241 close(ctlFd);
242}
243
244#endif /* RT_OS_SOLARIS */
245
246
247RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess)
248{
249 return RTProcCreateEx(pszExec, papszArgs, Env, fFlags,
250 NULL, NULL, NULL, /* standard handles */
251 NULL /*pszAsUser*/, NULL /* pszPassword*/,
252 pProcess);
253}
254
255
256RTR3DECL(int) RTProcCreateEx(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags,
257 PCRTHANDLE phStdIn, PCRTHANDLE phStdOut, PCRTHANDLE phStdErr, const char *pszAsUser,
258 const char *pszPassword, PRTPROCESS phProcess)
259{
260 int rc;
261
262 /*
263 * Input validation
264 */
265 AssertPtrReturn(pszExec, VERR_INVALID_POINTER);
266 AssertReturn(*pszExec, VERR_INVALID_PARAMETER);
267 AssertReturn(!(fFlags & ~(RTPROC_FLAGS_DETACHED | RTPROC_FLAGS_SERVICE)), VERR_INVALID_PARAMETER);
268 AssertReturn(!(fFlags & RTPROC_FLAGS_DETACHED) || !phProcess, VERR_INVALID_PARAMETER);
269 AssertReturn(hEnv != NIL_RTENV, VERR_INVALID_PARAMETER);
270 const char * const *papszEnv = RTEnvGetExecEnvP(hEnv);
271 AssertPtrReturn(papszEnv, VERR_INVALID_HANDLE);
272 AssertPtrReturn(papszArgs, VERR_INVALID_PARAMETER);
273 /** @todo search the PATH (add flag for this). */
274 AssertPtrNullReturn(pszAsUser, VERR_INVALID_POINTER);
275 AssertReturn(!pszAsUser || *pszAsUser, VERR_INVALID_PARAMETER);
276 AssertReturn(!pszPassword || pszAsUser, VERR_INVALID_PARAMETER);
277 AssertPtrNullReturn(pszPassword, VERR_INVALID_POINTER);
278
279 /*
280 * Get the file descriptors for the handles we've been passed.
281 */
282 PCRTHANDLE paHandles[3] = { phStdIn, phStdOut, phStdErr };
283 int aStdFds[3] = { -1, -1, -1 };
284 for (int i = 0; i < 3; i++)
285 {
286 if (paHandles[i])
287 {
288 AssertPtrReturn(paHandles[i], VERR_INVALID_POINTER);
289 switch (paHandles[i]->enmType)
290 {
291 case RTHANDLETYPE_FILE:
292 aStdFds[i] = paHandles[i]->u.hFile != NIL_RTFILE
293 ? (int)RTFileToNative(paHandles[i]->u.hFile)
294 : -2 /* close it */;
295 break;
296
297 case RTHANDLETYPE_PIPE:
298 aStdFds[i] = paHandles[i]->u.hPipe != NIL_RTPIPE
299 ? (int)RTPipeToNative(paHandles[i]->u.hPipe)
300 : -2 /* close it */;
301 break;
302
303 case RTHANDLETYPE_SOCKET:
304 aStdFds[i] = paHandles[i]->u.hSocket != NIL_RTSOCKET
305 ? (int)RTSocketToNative(paHandles[i]->u.hSocket)
306 : -2 /* close it */;
307 break;
308
309 default:
310 AssertMsgFailedReturn(("%d: %d\n", i, paHandles[i]->enmType), VERR_INVALID_PARAMETER);
311 }
312 /** @todo check the close-on-execness of these handles? */
313 }
314 }
315
316 for (int i = 0; i < 3; i++)
317 if (aStdFds[i] == i)
318 aStdFds[i] = -1;
319
320 for (int i = 0; i < 3; i++)
321 AssertMsgReturn(aStdFds[i] < 0 || aStdFds[i] > i,
322 ("%i := %i not possible because we're lazy\n", i, aStdFds[i]),
323 VERR_NOT_SUPPORTED);
324
325 /*
326 * Resolve the user id if specified.
327 */
328 uid_t uid = ~(uid_t)0;
329 gid_t gid = ~(gid_t)0;
330 if (pszAsUser)
331 {
332 rc = rtCheckCredentials(pszAsUser, pszPassword, &gid, &uid);
333 if (RT_FAILURE(rc))
334 return rc;
335 }
336
337 /*
338 * Check for execute access to the file.
339 */
340 if (access(pszExec, X_OK))
341 {
342 rc = RTErrConvertFromErrno(errno);
343 AssertMsgFailed(("'%s' %Rrc!\n", pszExec, rc));
344 return rc;
345 }
346
347 pid_t pid = -1;
348
349 /*
350 * Take care of detaching the process.
351 *
352 * HACK ALERT! Put the process into a new process group with pgid = pid
353 * to make sure it differs from that of the parent process to ensure that
354 * the IPRT waitpid call doesn't race anyone (read XPCOM) doing group wide
355 * waits. setsid() includes the setpgid() functionality.
356 * 2010-10-11 XPCOM no longer waits for anything, but it cannot hurt.
357 */
358#ifndef RT_OS_OS2
359 if (fFlags & RTPROC_FLAGS_DETACHED)
360 {
361# ifdef RT_OS_SOLARIS
362 int templateFd = rtSolarisContractPreFork();
363 if (templateFd == -1)
364 return VERR_OPEN_FAILED;
365# endif /* RT_OS_SOLARIS */
366 pid = fork();
367 if (!pid)
368 {
369# ifdef RT_OS_SOLARIS
370 rtSolarisContractPostForkChild(templateFd);
371# endif /* RT_OS_SOLARIS */
372 setsid(); /* see comment above */
373
374 pid = -1;
375 /* Child falls through to the actual spawn code below. */
376 }
377 else
378 {
379#ifdef RT_OS_SOLARIS
380 rtSolarisContractPostForkParent(templateFd, pid);
381#endif /* RT_OS_SOLARIS */
382 if (pid > 0)
383 {
384 /* Must wait for the temporary process to avoid a zombie. */
385 int status = 0;
386 pid_t pidChild = 0;
387
388 /* Restart if we get interrupted. */
389 do
390 {
391 pidChild = waitpid(pid, &status, 0);
392 } while ( pidChild == -1
393 && errno == EINTR);
394
395 /* Assume that something wasn't found. No detailed info. */
396 if (status)
397 return VERR_PROCESS_NOT_FOUND;
398 if (phProcess)
399 *phProcess = 0;
400 return VINF_SUCCESS;
401 }
402 return RTErrConvertFromErrno(errno);
403 }
404 }
405#endif
406
407 /*
408 * Spawn the child.
409 *
410 * Any spawn code MUST not execute any atexit functions if it is for a
411 * detached process. It would lead to running the atexit functions which
412 * make only sense for the parent. libORBit e.g. gets confused by multiple
413 * execution. Remember, there was only a fork() so far, and until exec()
414 * is successfully run there is nothing which would prevent doing anything
415 * silly with the (duplicated) file descriptors.
416 */
417#ifdef HAVE_POSIX_SPAWN
418 /** @todo OS/2: implement DETACHED (BACKGROUND stuff), see VbglR3Daemonize. */
419 if ( uid == ~(uid_t)0
420 && gid == ~(gid_t)0)
421 {
422 /* Spawn attributes. */
423 posix_spawnattr_t Attr;
424 rc = posix_spawnattr_init(&Attr);
425 if (!rc)
426 {
427# ifndef RT_OS_OS2 /* We don't need this on OS/2 and I don't recall if it's actually implemented. */
428 rc = posix_spawnattr_setflags(&Attr, POSIX_SPAWN_SETPGROUP);
429 Assert(rc == 0);
430 if (!rc)
431 {
432 rc = posix_spawnattr_setpgroup(&Attr, 0 /* pg == child pid */);
433 Assert(rc == 0);
434 }
435# endif
436
437 /* File changes. */
438 posix_spawn_file_actions_t FileActions;
439 posix_spawn_file_actions_t *pFileActions = NULL;
440 if (aStdFds[0] != -1 || aStdFds[1] != -1 || aStdFds[2] != -1)
441 {
442 rc = posix_spawn_file_actions_init(&FileActions);
443 if (!rc)
444 {
445 pFileActions = &FileActions;
446 for (int i = 0; i < 3; i++)
447 {
448 int fd = aStdFds[i];
449 if (fd == -2)
450 rc = posix_spawn_file_actions_addclose(&FileActions, i);
451 else if (fd >= 0 && fd != i)
452 {
453 rc = posix_spawn_file_actions_adddup2(&FileActions, fd, i);
454 if (!rc)
455 {
456 for (int j = i + 1; j < 3; j++)
457 if (aStdFds[j] == fd)
458 {
459 fd = -1;
460 break;
461 }
462 if (fd >= 0)
463 rc = posix_spawn_file_actions_addclose(&FileActions, fd);
464 }
465 }
466 if (rc)
467 break;
468 }
469 }
470 }
471
472 if (!rc)
473 rc = posix_spawn(&pid, pszExec, pFileActions, &Attr, (char * const *)papszArgs,
474 (char * const *)papszEnv);
475
476 /* cleanup */
477 int rc2 = posix_spawnattr_destroy(&Attr); Assert(rc2 == 0); NOREF(rc2);
478 if (pFileActions)
479 {
480 rc2 = posix_spawn_file_actions_destroy(pFileActions);
481 Assert(rc2 == 0);
482 }
483
484 /* return on success.*/
485 if (!rc)
486 {
487 /* For a detached process this happens in the temp process, so
488 * it's not worth doing anything as this process must exit. */
489 if (fFlags & RTPROC_FLAGS_DETACHED)
490 _Exit(0);
491 if (phProcess)
492 *phProcess = pid;
493 return VINF_SUCCESS;
494 }
495 }
496 /* For a detached process this happens in the temp process, so
497 * it's not worth doing anything as this process must exit. */
498 if (fFlags & RTPROC_FLAGS_DETACHED)
499 _Exit(124);
500 }
501 else
502#endif
503 {
504#ifdef RT_OS_SOLARIS
505 int templateFd = rtSolarisContractPreFork();
506 if (templateFd == -1)
507 return VERR_OPEN_FAILED;
508#endif /* RT_OS_SOLARIS */
509 pid = fork();
510 if (!pid)
511 {
512#ifdef RT_OS_SOLARIS
513 rtSolarisContractPostForkChild(templateFd);
514#endif /* RT_OS_SOLARIS */
515 if (!(fFlags & RTPROC_FLAGS_DETACHED))
516 setpgid(0, 0); /* see comment above */
517
518 /*
519 * Change group and user if requested.
520 */
521#if 1 /** @todo This needs more work, see suplib/hardening. */
522 if (gid != ~(gid_t)0)
523 {
524 if (setgid(gid))
525 {
526 if (fFlags & RTPROC_FLAGS_DETACHED)
527 _Exit(126);
528 else
529 exit(126);
530 }
531 }
532
533 if (uid != ~(uid_t)0)
534 {
535 if (setuid(uid))
536 {
537 if (fFlags & RTPROC_FLAGS_DETACHED)
538 _Exit(126);
539 else
540 exit(126);
541 }
542 }
543#endif
544
545 /*
546 * Apply changes to the standard file descriptor and stuff.
547 */
548 for (int i = 0; i < 3; i++)
549 {
550 int fd = aStdFds[i];
551 if (fd == -2)
552 close(i);
553 else if (fd >= 0)
554 {
555 int rc2 = dup2(fd, i);
556 if (rc2 != i)
557 {
558 if (fFlags & RTPROC_FLAGS_DETACHED)
559 _Exit(125);
560 else
561 exit(125);
562 }
563 for (int j = i + 1; j < 3; j++)
564 if (aStdFds[j] == fd)
565 {
566 fd = -1;
567 break;
568 }
569 if (fd >= 0)
570 close(fd);
571 }
572 }
573
574 /*
575 * Finally, execute the requested program.
576 */
577 rc = execve(pszExec, (char * const *)papszArgs, (char * const *)papszEnv);
578 if (errno == ENOEXEC)
579 {
580 /* This can happen when trying to start a shell script without the magic #!/bin/sh */
581 RTAssertMsg2Weak("Cannot execute this binary format!\n");
582 }
583 else
584 RTAssertMsg2Weak("execve returns %d errno=%d\n", rc, errno);
585 RTAssertReleasePanic();
586 if (fFlags & RTPROC_FLAGS_DETACHED)
587 _Exit(127);
588 else
589 exit(127);
590 }
591#ifdef RT_OS_SOLARIS
592 rtSolarisContractPostForkParent(templateFd, pid);
593#endif /* RT_OS_SOLARIS */
594 if (pid > 0)
595 {
596 /* For a detached process this happens in the temp process, so
597 * it's not worth doing anything as this process must exit. */
598 if (fFlags & RTPROC_FLAGS_DETACHED)
599 _Exit(0);
600 if (phProcess)
601 *phProcess = pid;
602 return VINF_SUCCESS;
603 }
604 /* For a detached process this happens in the temp process, so
605 * it's not worth doing anything as this process must exit. */
606 if (fFlags & RTPROC_FLAGS_DETACHED)
607 _Exit(124);
608 return RTErrConvertFromErrno(errno);
609 }
610
611 return VERR_NOT_IMPLEMENTED;
612}
613
614
615RTR3DECL(int) RTProcDaemonizeUsingFork(bool fNoChDir, bool fNoClose, const char *pszPidfile)
616{
617 /*
618 * Fork the child process in a new session and quit the parent.
619 *
620 * - fork once and create a new session (setsid). This will detach us
621 * from the controlling tty meaning that we won't receive the SIGHUP
622 * (or any other signal) sent to that session.
623 * - The SIGHUP signal is ignored because the session/parent may throw
624 * us one before we get to the setsid.
625 * - When the parent exit(0) we will become an orphan and re-parented to
626 * the init process.
627 * - Because of the sometimes unexpected semantics of assigning the
628 * controlling tty automagically when a session leader first opens a tty,
629 * we will fork() once more to get rid of the session leadership role.
630 */
631
632 /* We start off by opening the pidfile, so that we can fail straight away
633 * if it already exists. */
634 int fdPidfile = -1;
635 if (pszPidfile != NULL)
636 {
637 /* @note the exclusive create is not guaranteed on all file
638 * systems (e.g. NFSv2) */
639 if ((fdPidfile = open(pszPidfile, O_RDWR | O_CREAT | O_EXCL, 0644)) == -1)
640 return RTErrConvertFromErrno(errno);
641 }
642
643 /* Ignore SIGHUP straight away. */
644 struct sigaction OldSigAct;
645 struct sigaction SigAct;
646 memset(&SigAct, 0, sizeof(SigAct));
647 SigAct.sa_handler = SIG_IGN;
648 int rcSigAct = sigaction(SIGHUP, &SigAct, &OldSigAct);
649
650 /* First fork, to become independent process. */
651 pid_t pid = fork();
652 if (pid == -1)
653 return RTErrConvertFromErrno(errno);
654 if (pid != 0)
655 {
656 /* Parent exits, no longer necessary. The child gets reparented
657 * to the init process. */
658 exit(0);
659 }
660
661 /* Create new session, fix up the standard file descriptors and the
662 * current working directory. */
663 pid_t newpgid = setsid();
664 int SavedErrno = errno;
665 if (rcSigAct != -1)
666 sigaction(SIGHUP, &OldSigAct, NULL);
667 if (newpgid == -1)
668 return RTErrConvertFromErrno(SavedErrno);
669
670 if (!fNoClose)
671 {
672 /* Open stdin(0), stdout(1) and stderr(2) as /dev/null. */
673 int fd = open("/dev/null", O_RDWR);
674 if (fd == -1) /* paranoia */
675 {
676 close(STDIN_FILENO);
677 close(STDOUT_FILENO);
678 close(STDERR_FILENO);
679 fd = open("/dev/null", O_RDWR);
680 }
681 if (fd != -1)
682 {
683 dup2(fd, STDIN_FILENO);
684 dup2(fd, STDOUT_FILENO);
685 dup2(fd, STDERR_FILENO);
686 if (fd > 2)
687 close(fd);
688 }
689 }
690
691 if (!fNoChDir)
692 {
693 int rcChdir = chdir("/");
694 }
695
696 /* Second fork to lose session leader status. */
697 pid = fork();
698 if (pid == -1)
699 return RTErrConvertFromErrno(errno);
700
701 if (pid != 0)
702 {
703 /* Write the pid file, this is done in the parent, before exiting. */
704 if (fdPidfile != -1)
705 {
706 char szBuf[256];
707 size_t cbPid = RTStrPrintf(szBuf, sizeof(szBuf), "%d\n", pid);
708 int rcWrite = write(fdPidfile, szBuf, cbPid);
709 close(fdPidfile);
710 }
711 exit(0);
712 }
713
714 return VINF_SUCCESS;
715}
716
Note: See TracBrowser for help on using the repository browser.

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