static void VMToolsLogWrapper(GLogLevelFlags level, const char *fmt, va_list args) { if (!gLogInitialized && !IS_FATAL(level)) { /* * Avoid logging without initialization because * it leads to spamming of the console output. * Fatal messages are exception. */ return; } VMTools_AcquireLogStateLock(); if (gLoggingStopped) { /* This is to avoid nested logging in vmxLogger */ VMTools_ReleaseLogStateLock(); return; } VMTools_ReleaseLogStateLock(); if (gPanicCount == 0) { char *msg = Str_Vasprintf(NULL, fmt, args); if (msg != NULL) { g_log(gLogDomain, level, "%s", msg); free(msg); } } else { /* Try to avoid malloc() since we're aborting. */ gchar msg[256]; Str_Vsnprintf(msg, sizeof msg, fmt, args); VMToolsLog(gLogDomain, level, msg, gDefaultData); } }
Unicode Unicode_Format(const char *fmt, // IN: the format ...) // IN: the arguments { va_list args; char *p; va_start(args, fmt); p = Str_Vasprintf(NULL, fmt, args); va_end(args); return p; }
void LogV(uint32 unused, const char *fmt, va_list args) { char *str; str = Str_Vasprintf(NULL, fmt, args); if (str != NULL) { fputs(str, stderr); free(str); } }
void Warning(const char *fmt, ...) { char *str; va_list args; va_start(args, fmt); str = Str_Vasprintf(NULL, fmt, args); va_end(args); if (str != NULL) { fputs(str, stderr); } }
char * Str_Asprintf(size_t *length, // OUT const char *format, // IN ...) // IN { va_list arguments; char *result; va_start(arguments, format); result = Str_Vasprintf(length, format, arguments); va_end(arguments); return result; }
void Panic(const char *fmt, ...) // IN { va_list args; char *result; va_start(args, fmt); result = Str_Vasprintf(NULL, fmt, args); va_end(args); if (result) { printk(KERN_EMERG "%s", result); } BUG(); while (1); // Avoid compiler warning. }
void Panic(const char *fmt, ...) { va_list args; va_start(args, fmt); if (gGuestSDKMode) { GuestSDK_Panic(fmt, args); } else { if (gPanicCount == 0) { char *msg = Str_Vasprintf(NULL, fmt, args); if (msg != NULL) { g_log(gLogDomain, G_LOG_LEVEL_ERROR, "%s", msg); free(msg); } /* * In case an user-installed custom handler doesn't panic on error, * force a core dump. Also force a dump in the recursive case. */ VMToolsLogPanic(); } else if (gPanicCount == 1) { /* * Use a stack allocated string since we're in a recursive panic, so * probably already in a weird state. */ gchar msg[1024]; Str_Vsnprintf(msg, sizeof msg, fmt, args); fprintf(stderr, "Recursive panic: %s\n", msg); VMToolsLogPanic(); } else { fprintf(stderr, "Recursive panic, giving up.\n"); exit(-1); } } va_end(args); while (1) ; // avoid compiler warning }
gboolean RpcChannel_SendOne(char **reply, size_t *repLen, char const *reqFmt, ...) { va_list args; gboolean status; char *request; size_t reqLen = 0; status = FALSE; /* Format the request string */ va_start(args, reqFmt); request = Str_Vasprintf(&reqLen, reqFmt, args); va_end(args); /* * If Str_Vasprintf failed, write NULL into the reply if the caller wanted * a reply back. */ if (request == NULL) { goto error; } /* * If the command doesn't contain a space, add one to the end to maintain * compatibility with old VMXs. * * For a long time, the GuestRpc logic in the VMX was wired to expect a * trailing space in every command, even commands without arguments. That is * no longer true, but we must continue to add a trailing space because we * don't know whether we're talking to an old or new VMX. */ if (request[reqLen - 1] != ' ') { char *tmp; tmp = Str_Asprintf(NULL, "%s ", request); free(request); request = tmp; /* * If Str_Asprintf failed, write NULL into reply if the caller wanted * a reply back. */ if (request == NULL) { goto error; } } status = RpcChannel_SendOneRaw(request, reqLen, reply, repLen); free(request); return status; error: if (reply) { *reply = NULL; } if (repLen) { *repLen = 0; } return FALSE; }
Bool RpcOut_sendOne(char **reply, // OUT: Result size_t *repLen, // OUT: Length of the result char const *reqFmt, // IN: RPCI command ...) // Unspecified { va_list args; Bool status; char *request; size_t reqLen = 0; status = FALSE; /* Format the request string */ va_start(args, reqFmt); request = Str_Vasprintf(&reqLen, reqFmt, args); va_end(args); /* * If Str_Vasprintf failed, write NULL into the reply if the caller wanted * a reply back. */ if (request == NULL) { if (reply) { *reply = NULL; } return FALSE; } /* * If the command doesn't contain a space, add one to the end to maintain * compatibility with old VMXs. * * For a long time, the GuestRpc logic in the VMX was wired to expect a * trailing space in every command, even commands without arguments. That is * no longer true, but we must continue to add a trailing space because we * don't know whether we're talking to an old or new VMX. */ if (strchr(request, ' ') == NULL) { char *tmp; tmp = Str_Asprintf(NULL, "%s ", request); free(request); request = tmp; /* * If Str_Asprintf failed, write NULL into reply if the caller wanted * a reply back. */ if (request == NULL) { if (reply != NULL) { *reply = NULL; } return FALSE; } } status = RpcOut_SendOneRaw(request, reqLen, reply, repLen); free(request); return status; }