Beispiel #1
0
/**
 * Displays a verbose message.
 *
 * @param   iLevel      Minimum log level required to display this message.
 * @param   pszFormat   The message text.
 * @param   ...         Format arguments.
 */
void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...)
{
    if (iLevel <= g_cVerbosity)
    {
#ifdef DEBUG
        int rc = RTCritSectEnter(&g_csLog);
        if (RT_SUCCESS(rc))
        {
#endif
            va_list args;
            va_start(args, pszFormat);
            char *psz = NULL;
            RTStrAPrintfV(&psz, pszFormat, args);
            va_end(args);

            AssertPtr(psz);
            LogRel(("%s", psz));

            RTStrFree(psz);
#ifdef DEBUG
            RTCritSectLeave(&g_csLog);
        }
#endif
    }
}
/**
 * Used by ComPtr and friends to log details about reference counting.
 * @param pcszFormat
 */
void LogRef(const char *pcszFormat, ...)
{
    char *pszNewMsg;
    va_list args;
    va_start(args, pcszFormat);
    RTStrAPrintfV(&pszNewMsg, pcszFormat, args);
    LogDJ((pszNewMsg));
    RTStrFree(pszNewMsg);
    va_end(args);
}
Beispiel #3
0
/**
 * Formats a string and writes it to the SCM stream.
 *
 * @returns The number of bytes written (>= 0). Negative value are IPRT error
 *          status codes.
 * @param   pStream             The stream to write to.
 * @param   pszFormat           The format string.
 * @param   va                  The arguments to format.
 */
ssize_t ScmStreamPrintfV(PSCMSTREAM pStream, const char *pszFormat, va_list va)
{
    char   *psz;
    ssize_t cch = RTStrAPrintfV(&psz, pszFormat, va);
    if (cch)
    {
        int rc = ScmStreamWrite(pStream, psz, cch);
        RTStrFree(psz);
        if (RT_FAILURE(rc))
            cch = rc;
    }
    return cch;
}
Beispiel #4
0
EIPRTFailure::EIPRTFailure(int aRC, const char *pcszContext, ...)
    : RuntimeError(NULL),
      mRC(aRC)
{
    char *pszContext2;
    va_list args;
    va_start(args, pcszContext);
    RTStrAPrintfV(&pszContext2, pcszContext, args);
    char *newMsg;
    RTStrAPrintf(&newMsg, "%s: %d (%s)", pszContext2, aRC, RTErrGetShort(aRC));
    setWhat(newMsg);
    RTStrFree(newMsg);
    RTStrFree(pszContext2);
}
Beispiel #5
0
/**
 * Logs the message to the appropriate system log.
 *
 * In debug builds this will also put it in the debug log.
 *
 * @param   pszFormat   The log string. No trailing newline.
 * @param   ...         Format arguments.
 *
 * @todo    This should later be replaced by the release logger and callback destination(s).
 */
void supSvcLogErrorV(const char *pszFormat, va_list va)
{
    if (*pszFormat)
    {
        char *pszMsg = NULL;
        if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
        {
            supSvcLogErrorStr(pszMsg);
            RTStrFree(pszMsg);
        }
        else
            supSvcLogErrorStr(pszFormat);
    }
}
/**
 * Displays an error message.
 *
 * @param   hPAM                    PAM handle.
 * @param   pszFormat               The message text.
 * @param   ...                     Format arguments.
 */
static void pam_vbox_error(pam_handle_t *hPAM, const char *pszFormat, ...)
{
    RT_NOREF1(hPAM);
    va_list va;
    char *buf;
    va_start(va, pszFormat);
    if (RT_SUCCESS(RTStrAPrintfV(&buf, pszFormat, va)))
    {
        LogRel(("%s: Error: %s", VBOX_MODULE_NAME, buf));
        pam_vbox_writesyslog(buf);
        RTStrFree(buf);
    }
    va_end(va);
}
Beispiel #7
0
/**
 * Displays an error message.
 *
 * @returns RTEXITCODE_FAILURE.
 * @param   pszFormat   The message text.
 * @param   ...         Format arguments.
 */
RTEXITCODE VBoxServiceError(const char *pszFormat, ...)
{
    va_list args;
    va_start(args, pszFormat);
    char *psz = NULL;
    RTStrAPrintfV(&psz, pszFormat, args);
    va_end(args);

    AssertPtr(psz);
    LogRel(("Error: %s", psz));

    RTStrFree(psz);

    return RTEXITCODE_FAILURE;
}
static int rtMsgWorker(PRTSTREAM pDst, const char *pszPrefix, const char *pszFormat, va_list va)
{
    if (   !*pszFormat
        || !strcmp(pszFormat, "\n"))
        RTStrmPrintf(pDst, "\n");
    else
    {
        const char *pszProgName = g_pszProgName;
        if (!pszProgName)
            g_pszProgName = pszProgName = &g_szrtProcExePath[g_offrtProcName];

        char *pszMsg;
        ssize_t cch = RTStrAPrintfV(&pszMsg, pszFormat, va);
        if (cch >= 0)
        {
            /* print it line by line. */
            char *psz = pszMsg;
            do
            {
                char *pszEnd = strchr(psz, '\n');
                if (!pszEnd)
                {
                    RTStrmPrintf(pDst, "%s: %s%s\n", pszProgName, pszPrefix, psz);
                    break;
                }
                if (pszEnd == psz)
                    RTStrmPrintf(pDst, "\n");
                else
                {
                    *pszEnd = '\0';
                    RTStrmPrintf(pDst, "%s: %s%s\n", pszProgName, pszPrefix, psz);
                }
                psz = pszEnd + 1;
            } while (*psz);
            RTStrFree(pszMsg);
        }
        else
        {
            /* Simple fallback for handling out-of-memory conditions. */
            RTStrmPrintf(pDst, "%s: %s", pszProgName, pszPrefix);
            RTStrmPrintfV(pDst, pszFormat, va);
            if (!strchr(pszFormat, '\n'))
                RTStrmPrintf(pDst, "\n");
        }
    }

    return VINF_SUCCESS;
}
Beispiel #9
0
/**
 * Displays a verbose message.
 *
 * @param   iLevel      Minimum log level required to display this message.
 * @param   pszFormat   The message text.
 * @param   ...         Format arguments.
 */
void VBoxGINAVerbose(DWORD dwLevel, const char *pszFormat, ...)
{
    if (dwLevel <= g_dwVerbosity)
    {
        va_list args;
        va_start(args, pszFormat);
        char *psz = NULL;
        RTStrAPrintfV(&psz, pszFormat, args);
        va_end(args);

        AssertPtr(psz);
        LogRel(("%s", psz));

        RTStrFree(psz);
    }
}
Beispiel #10
0
/**
 * Allocating string printf.
 *
 * @returns Pointer to the string.
 * @param   pUVM        Pointer to the user mode VM structure.
 * @param   enmTag      The statistics tag.
 * @param   pszFormat   The format string.
 * @param   va          Format arguments.
 */
VMMR3DECL(char *)    MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va)
{
    /*
     * The lazy bird way.
     */
    char *psz;
    int cch = RTStrAPrintfV(&psz, pszFormat, va);
    if (cch < 0)
        return NULL;
    Assert(psz[cch] == '\0');
    char *pszRet = (char *)MMR3HeapAllocU(pUVM, enmTag, cch + 1);
    if (pszRet)
        memcpy(pszRet, psz, cch + 1);
    RTStrFree(psz);
    return pszRet;
}
Beispiel #11
0
/**
 * Displays a verbose message.
 *
 * @param   iLevel      Minimum log level required to display this message.
 * @param   pszFormat   The message text.
 * @param   ...         Format arguments.
 */
void VBoxClientVerbose(int iLevel, const char *pszFormat, ...)
{
    if (iLevel > g_cVerbosity)
        return;

    va_list args;
    va_start(args, pszFormat);
    char *psz = NULL;
    RTStrAPrintfV(&psz, pszFormat, args);
    va_end(args);

    AssertPtr(psz);
    LogRel(("%s", psz));

    RTStrFree(psz);
}
Beispiel #12
0
/**
 * Logs a verbose message.
 *
 * @param   pszFormat   The message text.
 * @param   va          Format arguments.
 */
void VGSvcLogV(const char *pszFormat, va_list va)
{
#ifdef DEBUG
    int rc = RTCritSectEnter(&g_csLog);
    if (RT_SUCCESS(rc))
    {
#endif
        char *psz = NULL;
        RTStrAPrintfV(&psz, pszFormat, va);

        AssertPtr(psz);
        LogRel(("%s", psz));

        RTStrFree(psz);
#ifdef DEBUG
        RTCritSectLeave(&g_csLog);
    }
#endif
}
/**
 * Displays a debug message.
 *
 * @param   hPAM                    PAM handle.
 * @param   pszFormat               The message text.
 * @param   ...                     Format arguments.
 */
static void pam_vbox_log(pam_handle_t *hPAM, const char *pszFormat, ...)
{
    RT_NOREF1(hPAM);
    if (g_verbosity)
    {
        va_list va;
        char *buf;
        va_start(va, pszFormat);
        if (RT_SUCCESS(RTStrAPrintfV(&buf, pszFormat, va)))
        {
            /* Only do normal logging in debug mode; could contain
             * sensitive data! */
            LogRel(("%s: %s", VBOX_MODULE_NAME, buf));
            /* Log to syslog */
            pam_vbox_writesyslog(buf);
            RTStrFree(buf);
        }
        va_end(va);
    }
}