VirtualBox

source: vbox/trunk/src/VBox/Additions/os2/VBoxService/VBoxService-os2.cpp@ 3669

Last change on this file since 3669 was 3655, checked in by vboxsync, 18 years ago

export

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/** $Id: VBoxService-os2.cpp 3655 2007-07-16 18:47:26Z vboxsync $ */
2/** @file
3 * VBoxService - Guest Additions Service Skeleton.
4 */
5
6/*
7 * Copyright (C) 2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22/*******************************************************************************
23* Global Variables *
24*******************************************************************************/
25#ifdef __OS2__
26# define INCL_BASE
27# define INCL_ERRORS
28# include <os2.h>
29#endif
30#include <errno.h>
31
32#include <iprt/string.h>
33#include <iprt/alloca.h>
34#include <VBox/VBoxGuest.h>
35#include "VBoxServiceInternal.h"
36
37
38/**
39 * OS/2 emulation of the BSD daemon() call.
40 */
41int daemon(int nochdir, int noclose)
42{
43 PPIB pPib;
44 PTIB pTib;
45 DosGetInfoBlocks(&pTib, &pPib);
46
47 /* Get the full path to the executable. */
48 char szExe[CCHMAXPATH];
49 APIRET rc = DosQueryModuleName(pPib->pib_hmte, sizeof(szExe), szExe);
50 if (rc)
51 {
52 errno = EDOOFUS;
53 return -1;
54 }
55
56 /* calc the length of the command line. */
57 char *pch = pPib->pib_pchcmd;
58 size_t cch0 = strlen(pch);
59 pch += cch0 + 1;
60 size_t cch1 = strlen(pch);
61 pch += cch1 + 1;
62 char *pchArgs;
63 if (cch1 && *pch)
64 {
65 do pch = strchr(pch, '\0') + 1;
66 while (*pch);
67
68 size_t cchTotal = pch - pPib->pib_pchcmd;
69 pchArgs = (char *)alloca(cchTotal + sizeof("--daemonized\0\0"));
70 memcpy(pchArgs, pPib->pib_pchcmd, cchTotal - 1);
71 memcpy(pchArgs + cchTotal - 1, "--daemonized\0\0", sizeof("--daemonized\0\0"));
72 }
73 else
74 {
75 size_t cchTotal = pch - pPib->pib_pchcmd + 1;
76 pchArgs = (char *)alloca(cchTotal + sizeof(" --daemonized "));
77 memcpy(pchArgs, pPib->pib_pchcmd, cch0 + 1);
78 pch = pchArgs + cch0 + 1;
79 memcpy(pch, " --daemonized ", sizeof(" --daemonized ") - 1);
80 pch += sizeof(" --daemonized ") - 1;
81 if (cch1)
82 memcpy(pch, pPib->pib_pchcmd + cch0 + 1, cch1 + 2);
83 else
84 pch[0] = pch[1] = '\0';
85 }
86
87 /* spawn a detach process */
88 char szObj[128];
89 RESULTCODES ResCodes = { 0, 0 };
90 szObj[0] = '\0';
91 rc = DosExecPgm(szObj, sizeof(szObj), EXEC_BACKGROUND, (PCSZ)pchArgs, NULL, &ResCodes, (PCSZ)szExe);
92 if (rc)
93 {
94 VBoxServiceError("DosExecPgm failed with rc=%d and szObj='%s'\n", rc, szObj);
95 errno = EDOOFUS;
96 return -1;
97 }
98 DosExit(EXIT_PROCESS, 0);
99 return -1;
100}
101
102
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