Exemplo n.º 1
0
size_t
LwGetErrorString(
    DWORD  dwError,
    PSTR   pszBuffer,
    size_t stBufSize
    )
{
    size_t sRequiredLen = 0;
    PCSTR pszDesc = LwWin32ExtErrorToDescription(dwError);

    if (pszBuffer && stBufSize) {
       memset(pszBuffer, 0, stBufSize);
    }

    if (!pszDesc)
    {
        pszDesc = "Unknown error";
    }

    sRequiredLen = strlen(pszDesc) + 1;
    if (stBufSize >= sRequiredLen)
    {
        strcpy(pszBuffer, pszDesc);
    }
    return sRequiredLen;
}
Exemplo n.º 2
0
void
LWRaise(
    LWException** dest, 
    DWORD code
    )
{
    DWORD ceError;
    char *shortMsg;
    char *longMsg;
    const char* desc = LwWin32ExtErrorToName(code);
    const char* help = LwWin32ExtErrorToDescription(code);

    if (!desc)
    {
        shortMsg = "Undocumented exception";
    }
    if ((ceError = CTAllocateString(desc, &shortMsg)))
    {
	*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
	return;
    }

    if (!help)
    {
        longMsg = "An undocumented exception has occurred. Please contact Likewise technical support and use the error code to identify this exception.";
    }
    if ((ceError = CTAllocateString(help, &longMsg)))
    {
	*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
	return;
    }
    
    *dest = CreateException(code, NULL, 0, shortMsg, longMsg);
}
Exemplo n.º 3
0
static
PCSTR
GetErrorString(
    IN DWORD dwError
    )
{
    PCSTR pszError = LwWin32ExtErrorToDescription(dwError);
    if (!pszError)
    {
        pszError = LwWin32ExtErrorToName(dwError);
    }
    if (!pszError)
    {
        pszError = "UNKNOWN";
    }
    return pszError;
}
Exemplo n.º 4
0
PVOID
UmnSrvPollerThreadRoutine(
    IN PVOID pUnused
    )
{
    DWORD dwError = 0;

    struct timeval now;
    struct timespec periodStart, periodUsed, nextWake, pushWait = {0};
    DWORD dwPeriodSecs = 0;
    
    char regErrMsg[256] = {0};
    char fqdn[1024] = {0};

    BOOLEAN bMutexLocked = FALSE;

    UMN_LOG_INFO("User poller thread started");
    dwError = pthread_mutex_lock(&gSignalPollerMutex);
    BAIL_ON_UMN_ERROR(dwError);
    bMutexLocked = TRUE;

    dwError = UmnSrvNow(&periodStart, &now);
    BAIL_ON_UMN_ERROR(dwError);

    while (!gbPollerThreadShouldExit)
    {
        dwError = UmnSrvGetCheckInterval(&dwPeriodSecs);
        BAIL_ON_UMN_ERROR(dwError);
        pushWait.tv_sec = dwPeriodSecs;

        UmnSrvTimespecAdd(
            &nextWake,
            &periodStart,
            &pushWait);

        UMN_LOG_INFO("User poller sleeping for %f seconds",
                pushWait.tv_sec + pushWait.tv_nsec /
                (double)NANOSECS_PER_SECOND);

        while (!gbPollerThreadShouldExit && !gbPollerRefresh)
        {
            BOOLEAN bWaitElapsed = FALSE;

            dwError = pthread_cond_timedwait(
                        &gSignalPoller,
                        &gSignalPollerMutex,
                        &nextWake);

            if (dwError == EINTR)
            {
                UMN_LOG_DEBUG("User poller cond wait interrupted; continuing.");
                continue;
            }

            if (dwError == ETIMEDOUT)
            {
                UMN_LOG_DEBUG("User poller cond wait completed.");
                dwError = 0;
                break;
            }

            if (dwError != 0) 
            {
                UMN_LOG_ERROR("Timed wait error: error %s (%d).", 
                      ErrnoToName(dwError), dwError);
                BAIL_ON_UMN_ERROR(dwError);
            }

            dwError = UmnSrvTimespecElapsed(&nextWake, &bWaitElapsed);
            if (dwError == 0 && bWaitElapsed == TRUE) 
            {
                break;
            }
        }

        gbPollerRefresh = FALSE;

        if (!gbPollerThreadShouldExit)
        {
            dwError = UmnSrvNow(&periodStart, &now);
            BAIL_ON_UMN_ERROR(dwError);

            // obtain the fully qualified domain name and use it throughout this iteration
            UmnEvtFreeEventComputerName();
            UmnEvtGetFQDN(fqdn, sizeof(fqdn));
            UmnEvtSetEventComputerName(fqdn);

            dwError = UmnSrvUpdateAccountInfo(now.tv_sec);
            if (dwError == ERROR_CANCELLED)
            {
                UMN_LOG_INFO("User poller cancelled iteration");
                dwError = 0;
                break;
            }

            // simply log other errors and attempt to continue
            if (dwError != LW_ERROR_SUCCESS) 
            {
                if (LwRegIsRegistrySpecificError(dwError))
                {
                    LwRegGetErrorString(dwError, regErrMsg, sizeof(regErrMsg) - 1);
                    UMN_LOG_ERROR("Failed updating account info, registry error = %d  %s. Continuing.",
                            dwError, regErrMsg);
                }
                else 
                {
                    UMN_LOG_ERROR("Failed updating account info, error = %d symbol = %s %s. Continuing.", 
                        dwError,
                        LwWin32ExtErrorToName(dwError), 
                        LwWin32ExtErrorToDescription(dwError));
                }
                dwError = 0;
            }

            // periodUsed = now - periodStart
            dwError = UmnSrvNow(&periodUsed, &now);
            BAIL_ON_UMN_ERROR(dwError);

            UmnSrvTimespecSubtract(
                &periodUsed,
                &periodUsed,
                &periodStart);

            UMN_LOG_DEBUG("Account activity update took %f seconds",
                    periodUsed.tv_sec + periodUsed.tv_nsec /
                    (double)NANOSECS_PER_SECOND);
        }
    }

    UMN_LOG_INFO("User poller thread stopped");

cleanup:
    if (bMutexLocked)
    {
        pthread_mutex_unlock(&gSignalPollerMutex);
    }

    if (dwError != 0)
    {
        UMN_LOG_ERROR(
                "User monitor polling thread exiting with code %d",
                dwError);
        kill(getpid(), SIGTERM);
    }

    return NULL;

error:
    goto cleanup;
}
Exemplo n.º 5
0
void
LWRaiseEx(
    LWException** dest,
    DWORD code,
    const char* file,
    unsigned int line,
    const char* _shortMsg,
    const char* fmt,
    ...
    )
{
    if (dest)
    {
	DWORD ceError;
	char* shortMsg;
	char* longMsg;
	va_list ap;
	
	va_start(ap, fmt);
	
	if (!_shortMsg)
	{
	    _shortMsg = LwWin32ExtErrorToName(code);
	}
        if (!_shortMsg)
        {
            _shortMsg = "Undocumented exception";
        }

	if (!fmt)
	{
	    fmt = LwWin32ExtErrorToDescription(code);
	}
        if (!fmt)
        {
            fmt = "An undocumented exception has occurred. Please contact Likewise technical support and use the error code to identify this exception.";
        }

	if (_shortMsg)
	{
	    if ((ceError = CTAllocateString(_shortMsg, &shortMsg)))
	    {
		*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
		return;
	    }
	}
	else
	{
	    shortMsg = NULL;
	}
	    
	if (fmt)
	{
	    if ((ceError = CTAllocateStringPrintfV(&longMsg, fmt, ap)))
	    {
		CTFreeString(shortMsg);
		*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
		return;
	    }
	}
	else
	{
	    longMsg = NULL;
	}

	*dest = CreateException(code, file, line, shortMsg, longMsg);
    }
}