- Timestamp:
- May 25, 2020 1:36:55 PM (5 years ago)
- Location:
- trunk/src/VBox/Additions/x11/VBoxClient
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
r84480 r84501 45 45 seamless.cpp \ 46 46 seamless-x11.cpp \ 47 logging.cpp \ 47 48 hostversion.cpp 48 49 -
trunk/src/VBox/Additions/x11/VBoxClient/VBoxClient.h
r83218 r84501 30 30 void VBClLogError(const char *pszFormat, ...); 31 31 void VBClLogFatalError(const char *pszFormat, ...); 32 void VBClLogDestroy(void); 33 int VBClLogCreate(const char *pszLogFile); 32 34 33 35 /** Call clean-up for the current service and exit. */ -
trunk/src/VBox/Additions/x11/VBoxClient/main.cpp
r83717 r84501 20 20 * Header Files * 21 21 *********************************************************************************************************************************/ 22 #include <sys/types.h>23 22 #include <sys/wait.h> 24 23 #include <stdlib.h> /* For exit */ 25 #include <stdio.h>26 #include <string.h>27 #include <unistd.h>28 #include <errno.h>29 #include <poll.h>30 #include <signal.h>31 32 24 #include <X11/Xlib.h> 33 #include <X11/Xatom.h>34 35 #include <package-generated.h>36 25 #include "product-generated.h" 37 38 26 #include <iprt/buildconfig.h> 39 27 #include <iprt/critsect.h> 40 #include <iprt/env.h>41 #include <iprt/file.h>42 28 #include <iprt/getopt.h> 43 29 #include <iprt/initterm.h> 44 30 #include <iprt/message.h> 45 31 #include <iprt/path.h> 46 #include <iprt/param.h>47 #include <iprt/process.h>48 32 #include <iprt/stream.h> 49 #include <iprt/string.h>50 #include <iprt/system.h>51 #include <iprt/types.h>52 33 #include <VBox/VBoxGuestLib.h> 53 34 #include <VBox/err.h> 54 #include <VBox/log.h>55 56 35 #include "VBoxClient.h" 57 36 … … 91 70 static RTCRITSECT g_critSect; 92 71 /** Counter of how often our daemon has been respawned. */ 93 staticunsigned g_cRespawn = 0;72 unsigned g_cRespawn = 0; 94 73 /** Logging verbosity level. */ 95 staticunsigned g_cVerbosity = 0;74 unsigned g_cVerbosity = 0; 96 75 static char g_szLogFile[RTPATH_MAX + 128] = ""; 97 /** Logging parameters. */ 98 /** @todo Make this configurable later. */ 99 static PRTLOGGER g_pLoggerRelease = NULL; 100 static uint32_t g_cHistory = 10; /* Enable log rotation, 10 files. */ 101 static uint32_t g_uHistoryFileTime = RT_SEC_1DAY; /* Max 1 day per file. */ 102 static uint64_t g_uHistoryFileSize = 100 * _1M; /* Max 100MB per file. */ 103 104 /** 105 * Notifies the desktop environment with a message. 106 * 107 * @param pszMessage Message to notify desktop environment with. 108 */ 109 int vbclLogNotify(const char *pszMessage) 110 { 111 AssertPtrReturn(pszMessage, VERR_INVALID_POINTER); 112 113 int rc = VINF_SUCCESS; 114 115 if (g_cRespawn == 0) 116 { 117 char *pszCommand = RTStrAPrintf2("notify-send \"VBoxClient: %s\"", pszMessage); 118 if (pszCommand) 119 { 120 int status = system(pszCommand); 121 122 RTStrFree(pszCommand); 123 124 if (WEXITSTATUS(status) != 0) /* Utility or extension not available. */ 125 { 126 pszCommand = RTStrAPrintf2("xmessage -buttons OK:0 -center \"VBoxClient: %s\"", 127 pszMessage); 128 if (pszCommand) 129 { 130 status = system(pszCommand); 131 if (WEXITSTATUS(status) != 0) /* Utility or extension not available. */ 132 { 133 RTPrintf("VBoxClient: %s", pszMessage); 134 } 135 136 RTStrFree(pszCommand); 137 } 138 else 139 rc = VERR_NO_MEMORY; 140 } 141 } 142 else 143 rc = VERR_NO_MEMORY; 144 } 145 146 return rc; 147 } 148 149 /** 150 * Logs a fatal error, notifies the desktop environment via a message and 151 * exits the application immediately. 152 * 153 * @param pszFormat Format string to log. 154 * @param ... Variable arguments for format string. Optional. 155 */ 156 void VBClLogFatalError(const char *pszFormat, ...) 157 { 158 va_list args; 159 va_start(args, pszFormat); 160 char *psz = NULL; 161 RTStrAPrintfV(&psz, pszFormat, args); 162 va_end(args); 163 164 AssertPtr(psz); 165 LogFlowFunc(("%s", psz)); 166 LogRel(("%s", psz)); 167 168 vbclLogNotify(psz); 169 170 RTStrFree(psz); 171 } 172 173 /** 174 * Logs an error message to the (release) logging instance. 175 * 176 * @param pszFormat Format string to log. 177 */ 178 void VBClLogError(const char *pszFormat, ...) 179 { 180 va_list args; 181 va_start(args, pszFormat); 182 char *psz = NULL; 183 RTStrAPrintfV(&psz, pszFormat, args); 184 va_end(args); 185 186 AssertPtr(psz); 187 LogFlowFunc(("%s", psz)); 188 LogRel(("%s", psz)); 189 190 RTStrFree(psz); 191 } 192 193 /** 194 * Logs an info message to the (release) logging instance. 195 * 196 * @param pszFormat Format string to log. 197 */ 198 void VBClLogInfo(const char *pszFormat, ...) 199 { 200 va_list args; 201 va_start(args, pszFormat); 202 char *psz = NULL; 203 RTStrAPrintfV(&psz, pszFormat, args); 204 va_end(args); 205 206 AssertPtr(psz); 207 LogFlowFunc(("%s", psz)); 208 LogRel(("%s", psz)); 209 210 RTStrFree(psz); 211 } 212 213 /** 214 * @callback_method_impl{FNRTLOGPHASE, Release logger callback} 215 */ 216 static DECLCALLBACK(void) vbClLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog) 217 { 218 /* Some introductory information. */ 219 static RTTIMESPEC s_TimeSpec; 220 char szTmp[256]; 221 if (enmPhase == RTLOGPHASE_BEGIN) 222 RTTimeNow(&s_TimeSpec); 223 RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp)); 224 225 switch (enmPhase) 226 { 227 case RTLOGPHASE_BEGIN: 228 { 229 pfnLog(pLoggerRelease, 230 "VBoxClient %s r%s (verbosity: %u) %s (%s %s) release log\n" 231 "Log opened %s\n", 232 RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity, VBOX_BUILD_TARGET, 233 __DATE__, __TIME__, szTmp); 234 235 int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp)); 236 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) 237 pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp); 238 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp)); 239 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) 240 pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp); 241 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp)); 242 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) 243 pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp); 244 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp)); 245 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) 246 pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp); 247 248 /* the package type is interesting for Linux distributions */ 249 char szExecName[RTPATH_MAX]; 250 char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName)); 251 pfnLog(pLoggerRelease, 252 "Executable: %s\n" 253 "Process ID: %u\n" 254 "Package type: %s" 255 #ifdef VBOX_OSE 256 " (OSE)" 257 #endif 258 "\n", 259 pszExecName ? pszExecName : "unknown", 260 RTProcSelf(), 261 VBOX_PACKAGE_STRING); 262 break; 263 } 264 265 case RTLOGPHASE_PREROTATE: 266 pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp); 267 break; 268 269 case RTLOGPHASE_POSTROTATE: 270 pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp); 271 break; 272 273 case RTLOGPHASE_END: 274 pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp); 275 break; 276 277 default: 278 /* nothing */ 279 break; 280 } 281 } 282 283 /** 284 * Creates the default release logger outputting to the specified file. 285 * 286 * Pass NULL to disabled logging. 287 * 288 * @return IPRT status code. 289 * @param pszLogFile Filename for log output. NULL disables custom handling. 290 */ 291 int VBClLogCreate(const char *pszLogFile) 292 { 293 if (!pszLogFile) 294 return VINF_SUCCESS; 295 296 /* Create release logger (stdout + file). */ 297 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; 298 RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME; 299 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 300 fFlags |= RTLOGFLAGS_USECRLF; 301 #endif 302 int rc = RTLogCreateEx(&g_pLoggerRelease, fFlags, "all", 303 #ifdef DEBUG 304 "VBOXCLIENT_LOG", 305 #else 306 "VBOXCLIENT_RELEASE_LOG", 307 #endif 308 RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX /*cMaxEntriesPerGroup*/, 309 RTLOGDEST_STDOUT | RTLOGDEST_USER, 310 vbClLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime, 311 NULL /*pErrInfo*/, "%s", pszLogFile ? pszLogFile : ""); 312 if (RT_SUCCESS(rc)) 313 { 314 /* register this logger as the release logger */ 315 RTLogRelSetDefaultInstance(g_pLoggerRelease); 316 317 /* Explicitly flush the log in case of VBOXSERVICE_RELEASE_LOG=buffered. */ 318 RTLogFlush(g_pLoggerRelease); 319 } 320 321 return rc; 322 } 323 324 /** 325 * Destroys the currently active logging instance. 326 */ 327 void VBClLogDestroy(void) 328 { 329 RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); 330 } 76 331 77 332 78 /**
Note:
See TracChangeset
for help on using the changeset viewer.