1 | /* $Id: VBoxLogRelCreate.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * MS COM / XPCOM Abstraction Layer - VBoxLogRelCreate.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2005-2022 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 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include <VBox/com/utils.h>
|
---|
23 |
|
---|
24 | #include <iprt/buildconfig.h>
|
---|
25 | #include <iprt/param.h>
|
---|
26 | #include <iprt/string.h>
|
---|
27 | #include <iprt/system.h>
|
---|
28 | #include <iprt/process.h>
|
---|
29 | #include <iprt/time.h>
|
---|
30 |
|
---|
31 | #include <iprt/errcore.h>
|
---|
32 | #include <VBox/log.h>
|
---|
33 | #include <VBox/version.h>
|
---|
34 | #include "package-generated.h"
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | namespace com
|
---|
39 | {
|
---|
40 |
|
---|
41 | static const char *g_pszLogEntity = NULL;
|
---|
42 |
|
---|
43 | static DECLCALLBACK(void) vboxHeaderFooter(PRTLOGGER pReleaseLogger, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
|
---|
44 | {
|
---|
45 | /* some introductory information */
|
---|
46 | static RTTIMESPEC s_TimeSpec;
|
---|
47 | char szTmp[256];
|
---|
48 | if (enmPhase == RTLOGPHASE_BEGIN)
|
---|
49 | RTTimeNow(&s_TimeSpec);
|
---|
50 | RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
|
---|
51 |
|
---|
52 | switch (enmPhase)
|
---|
53 | {
|
---|
54 | case RTLOGPHASE_BEGIN:
|
---|
55 | {
|
---|
56 | bool fOldBuffered = RTLogSetBuffering(pReleaseLogger, true /*fBuffered*/);
|
---|
57 | pfnLog(pReleaseLogger,
|
---|
58 | "VirtualBox %s %s r%u %s (%s %s) release log\n"
|
---|
59 | #ifdef VBOX_BLEEDING_EDGE
|
---|
60 | "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n"
|
---|
61 | #endif
|
---|
62 | "Log opened %s\n",
|
---|
63 | g_pszLogEntity, VBOX_VERSION_STRING, RTBldCfgRevision(),
|
---|
64 | RTBldCfgTargetDotArch(), __DATE__, __TIME__, szTmp);
|
---|
65 |
|
---|
66 | pfnLog(pReleaseLogger, "Build Type: %s\n", KBUILD_TYPE);
|
---|
67 | int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
|
---|
68 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
69 | pfnLog(pReleaseLogger, "OS Product: %s\n", szTmp);
|
---|
70 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
|
---|
71 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
72 | pfnLog(pReleaseLogger, "OS Release: %s\n", szTmp);
|
---|
73 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
|
---|
74 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
75 | pfnLog(pReleaseLogger, "OS Version: %s\n", szTmp);
|
---|
76 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
|
---|
77 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
78 | pfnLog(pReleaseLogger, "OS Service Pack: %s\n", szTmp);
|
---|
79 |
|
---|
80 | vrc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szTmp, sizeof(szTmp));
|
---|
81 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
82 | pfnLog(pReleaseLogger, "DMI Product Name: %s\n", szTmp);
|
---|
83 | vrc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_VERSION, szTmp, sizeof(szTmp));
|
---|
84 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
85 | pfnLog(pReleaseLogger, "DMI Product Version: %s\n", szTmp);
|
---|
86 |
|
---|
87 | RTSYSFWTYPE enmType;
|
---|
88 | vrc = RTSystemQueryFirmwareType(&enmType);
|
---|
89 | if (RT_SUCCESS(vrc))
|
---|
90 | {
|
---|
91 | pfnLog(pReleaseLogger, "Firmware type: %s\n", RTSystemFirmwareTypeName(enmType));
|
---|
92 | if (enmType == RTSYSFWTYPE_UEFI)
|
---|
93 | {
|
---|
94 | bool fValue;
|
---|
95 | vrc = RTSystemQueryFirmwareBoolean(RTSYSFWBOOL_SECURE_BOOT, &fValue);
|
---|
96 | if (RT_SUCCESS(vrc))
|
---|
97 | pfnLog(pReleaseLogger, "Secure Boot: %s\n", fValue ? "Enabled" : "Disabled");
|
---|
98 | else
|
---|
99 | pfnLog(pReleaseLogger, "Secure Boot: %Rrc\n", vrc);
|
---|
100 | }
|
---|
101 | }
|
---|
102 | else
|
---|
103 | pfnLog(pReleaseLogger, "Firmware type: failed - %Rrc\n", vrc);
|
---|
104 |
|
---|
105 | uint64_t cbHostRam = 0, cbHostRamAvail = 0;
|
---|
106 | vrc = RTSystemQueryTotalRam(&cbHostRam);
|
---|
107 | if (RT_SUCCESS(vrc))
|
---|
108 | vrc = RTSystemQueryAvailableRam(&cbHostRamAvail);
|
---|
109 | if (RT_SUCCESS(vrc))
|
---|
110 | {
|
---|
111 | pfnLog(pReleaseLogger, "Host RAM: %lluMB", cbHostRam / _1M);
|
---|
112 | if (cbHostRam > _2G)
|
---|
113 | pfnLog(pReleaseLogger, " (%lld.%lldGB)",
|
---|
114 | cbHostRam / _1G, (cbHostRam % _1G) / (_1G / 10));
|
---|
115 | pfnLog(pReleaseLogger, " total, %lluMB", cbHostRamAvail / _1M);
|
---|
116 | if (cbHostRamAvail > _2G)
|
---|
117 | pfnLog(pReleaseLogger, " (%lld.%lldGB)",
|
---|
118 | cbHostRamAvail / _1G, (cbHostRamAvail % _1G) / (_1G / 10));
|
---|
119 | pfnLog(pReleaseLogger, " available\n");
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* the package type is interesting for Linux distributions */
|
---|
123 | char szExecName[RTPATH_MAX];
|
---|
124 | char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
|
---|
125 | pfnLog(pReleaseLogger,
|
---|
126 | "Executable: %s\n"
|
---|
127 | "Process ID: %u\n"
|
---|
128 | "Package type: %s"
|
---|
129 | #ifdef VBOX_OSE
|
---|
130 | " (OSE)"
|
---|
131 | #endif
|
---|
132 | "\n",
|
---|
133 | pszExecName ? pszExecName : "unknown",
|
---|
134 | RTProcSelf(),
|
---|
135 | VBOX_PACKAGE_STRING);
|
---|
136 | RTLogSetBuffering(pReleaseLogger, fOldBuffered);
|
---|
137 | break;
|
---|
138 | }
|
---|
139 |
|
---|
140 | case RTLOGPHASE_PREROTATE:
|
---|
141 | pfnLog(pReleaseLogger, "Log rotated - Log started %s\n", szTmp);
|
---|
142 | break;
|
---|
143 |
|
---|
144 | case RTLOGPHASE_POSTROTATE:
|
---|
145 | pfnLog(pReleaseLogger, "Log continuation - Log started %s\n", szTmp);
|
---|
146 | break;
|
---|
147 |
|
---|
148 | case RTLOGPHASE_END:
|
---|
149 | pfnLog(pReleaseLogger, "End of log file - Log started %s\n", szTmp);
|
---|
150 | break;
|
---|
151 |
|
---|
152 | default:
|
---|
153 | /* nothing */;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | int VBoxLogRelCreate(const char *pcszEntity, const char *pcszLogFile,
|
---|
158 | uint32_t fFlags, const char *pcszGroupSettings,
|
---|
159 | const char *pcszEnvVarBase, uint32_t fDestFlags,
|
---|
160 | uint32_t cMaxEntriesPerGroup, uint32_t cHistory,
|
---|
161 | uint32_t uHistoryFileTime, uint64_t uHistoryFileSize,
|
---|
162 | PRTERRINFO pErrInfo)
|
---|
163 | {
|
---|
164 | /* create release logger */
|
---|
165 | PRTLOGGER pReleaseLogger;
|
---|
166 | static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
|
---|
167 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
168 | fFlags |= RTLOGFLAGS_USECRLF;
|
---|
169 | #endif
|
---|
170 | g_pszLogEntity = pcszEntity;
|
---|
171 | int vrc = RTLogCreateEx(&pReleaseLogger, pcszEnvVarBase, fFlags, pcszGroupSettings, RT_ELEMENTS(s_apszGroups), s_apszGroups,
|
---|
172 | cMaxEntriesPerGroup, 0 /*cBufDescs*/, NULL /*paBufDescs*/, fDestFlags,
|
---|
173 | vboxHeaderFooter, cHistory, uHistoryFileSize, uHistoryFileTime,
|
---|
174 | pErrInfo, pcszLogFile ? "%s" : NULL, pcszLogFile);
|
---|
175 | if (RT_SUCCESS(vrc))
|
---|
176 | {
|
---|
177 | /* explicitly flush the log, to have some info when buffering */
|
---|
178 | RTLogFlush(pReleaseLogger);
|
---|
179 |
|
---|
180 | /* register this logger as the release logger */
|
---|
181 | RTLogRelSetDefaultInstance(pReleaseLogger);
|
---|
182 | }
|
---|
183 | return vrc;
|
---|
184 | }
|
---|
185 |
|
---|
186 | } /* namespace com */
|
---|