Example #1
0
static int
ReportEventAlt(WORD eventType,
	       DWORD eventId,
	       WORD insertStrCount,
	       char **insertStr,
	       int status)
{
    HANDLE eventLog = NULL;
    BOOL result;

    /* open write handle to the event log */
    eventLog = RegisterEventSource(NULL /* local machine */,
				   AFSREG_SVR_APPLOG_SUBKEY);
    if (eventLog == NULL) {
	return -1;
    }

    /* log the event */
    result = ReportEvent(eventLog, eventType, 0 /* category */, eventId,
			 NULL /* SID */,
			 insertStrCount, (status ? sizeof(status) : 0),
			 insertStr, &status);

    (void) DeregisterEventSource(eventLog);

    return (result ? 0 : -1);
}
Example #2
0
/*   error, or stop the service. */
static VOID
StopService(LPTSTR lpszMsg)
{
  CHAR chMsg[256];
  HANDLE hEventSource;
  LPTSTR lpszStrings[2];

  dwGlobalErr = GetLastError();

  /*  Use event logging to log the error. */
  hEventSource = RegisterEventSource(NULL, THIS_SERVICE);

  sprintf(chMsg, "%s error: %s", THIS_SERVICE, convert_error(dwGlobalErr));
  lpszStrings[0] = chMsg;
  lpszStrings[1] = lpszMsg;

  if (hEventSource) {
    ReportEvent(hEventSource,   /*  handle of event source */
                EVENTLOG_ERROR_TYPE,    /*  event type */
                0,              /*  event category */
                0,              /*  event ID */
                NULL,           /*  current user's SID */
                2,              /*  strings in lpszStrings */
                0,              /*  no bytes of raw data */
                lpszStrings,    /*  array of error strings */
                NULL);          /*  no raw data */

    (VOID) DeregisterEventSource(hEventSource);
  }
  if (threadHandle)
    TerminateThread(threadHandle, 1);
}                               /*  end of StopService */
void
sbWindowsEventLogFinalize()
{
  // Deregister the event source.
  if (gSBWindowsEventLogEventSource)
    DeregisterEventSource(gSBWindowsEventLogEventSource);
}
Example #4
0
void
closelog (void)
{
  if (virt_err_log)
    if (DeregisterEventSource (virt_err_log))
      virt_err_log = (HANDLE) NULL;
}
Example #5
0
void ReportError(BOOL bError, LPCTSTR szError, ...)
{
	static BOOL bEventSourceAdded = FALSE;
	char buf[512];
	const char *bufp = buf;
	va_list va;

	va_start(va,szError);
	vsprintf(buf,szError,va);
	va_end(va);
	if(g_bTestMode)
	{
		printf("%s%s\n",bError?"Error: ":"",buf);
	}
	else
	{
		if(!bEventSourceAdded)
		{
			char szModule[MAX_PATH];
			GetModuleFileName(NULL,szModule,MAX_PATH);
			AddEventSource(SERVICE_NAME,szModule);
			bEventSourceAdded=TRUE;
		}

		HANDLE hEvent = RegisterEventSource(NULL,  SERVICE_NAME);
		ReportEvent(hEvent,bError?EVENTLOG_ERROR_TYPE:EVENTLOG_INFORMATION_TYPE,0,MSG_STRING,NULL,1,0,&bufp,NULL);
		DeregisterEventSource(hEvent);
	}
}
Example #6
0
//
//  FUNCTION: LogEventInfoMessage(LPTSTR lpszMsg)
//
//  PURPOSE: Allows any thread to log an info message
//
//  PARAMETERS:
//    lpszMsg - text for message
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
VOID LogEventInfoMessage(LPTSTR lpszMsg) {
    HANDLE  hEventSource;
    LPTSTR  lpszStrings[2];

    // Use event logging to log the error.
    //
    hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));

    lpszStrings[0] = lpszMsg;
    lpszStrings[1] = '\0';

    if (hEventSource != NULL) {
        ReportEvent(hEventSource, // handle of event source
            EVENTLOG_INFORMATION_TYPE,// event type
            0,                    // event category
            1,                    // event ID
            NULL,                 // current user's SID
            2,                    // strings in lpszStrings
            0,                    // no bytes of raw data
            (LPCSTR*)lpszStrings, // array of error strings
            NULL);                // no raw data

        (VOID) DeregisterEventSource(hEventSource);
    }
}
//
// Purpose: 
//   Logs messages to the event log
//
// Parameters:
//   szFunction - name of function that failed
// 
// Return value:
//   None
//
// Remarks:
//   The service must have an entry in the Application event log.
//
VOID SvcReportEvent(LPTSTR szFunction) 
{ 
	HANDLE hEventSource;
	LPCTSTR lpszStrings[2];
	char Buffer[80];

	hEventSource = RegisterEventSource(NULL, gService->name());

	if( NULL != hEventSource )
	{
		sprintf(Buffer, "%-60s failed with %d", szFunction, GetLastError());

		lpszStrings[0] = gService->name();
		lpszStrings[1] = Buffer;

		ReportEvent(hEventSource,        // event log handle
			EVENTLOG_ERROR_TYPE, // event type
			0,                   // event category
			SVC_ERROR,           // event identifier
			NULL,                // no security identifier
			2,                   // size of lpszStrings array
			0,                   // no binary data
			lpszStrings,         // array of strings
			NULL);               // no binary data

		DeregisterEventSource(hEventSource);
	}
}
Example #8
0
/*
  FUNCTION: smpd_add_error_to_message_log(char *msg)

  PURPOSE: Allows any thread to log an error message

  PARAMETERS:
    lpszMsg - text for message

  RETURN VALUE:
    none

  COMMENTS:
*/
void smpd_add_error_to_message_log(char *msg)
{
    TCHAR   szMsg[256];
    HANDLE  hEventSource;
    LPTSTR  lpszStrings[2];
    DWORD dwErr;

    dwErr = GetLastError();

    /* Use event logging to log the error. */
    hEventSource = RegisterEventSource(NULL, TEXT(SMPD_SERVICE_NAME));

    _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SMPD_SERVICE_NAME), dwErr);
    lpszStrings[0] = szMsg;
    lpszStrings[1] = msg;

    if (hEventSource != NULL) {
	ReportEvent(hEventSource, /* handle of event source */
	    EVENTLOG_ERROR_TYPE,  /* event type */
	    0,                    /* event category */
	    0,                    /* event ID */
	    NULL,                 /* current user's SID */
	    2,                    /* strings in lpszStrings */
	    0,                    /* no bytes of raw data */
	    (LPCTSTR*)lpszStrings,/* array of error strings */
	    NULL);                /* no raw data */

	(VOID) DeregisterEventSource(hEventSource);
    }
}
/*
 * Class:     org_apache_log4j_nt_NTEventLogAppender
 * Method:    reportEvent
 * Signature: (ILjava/lang/String;I)V
 */
JNIEXPORT void JNICALL Java_org_apache_log4j_nt_NTEventLogAppender_reportEvent(
   JNIEnv *env, jobject java_this, jint jhandle, jstring jstr, jint priority) {
  jboolean localHandle = JNI_FALSE;
  HANDLE handle = gEventSources.getHandle(jhandle);
  if (handle == 0) {
    // Client didn't give us a handle so make a local one.
    handle = RegisterEventSourceW(NULL, L"Log4j");
    localHandle = JNI_TRUE;
  }
  
  // convert Java String to character array
  jsize msgLen = env->GetStringLength(jstr);
  jchar* msg = (jchar*) malloc((msgLen + 1) * sizeof(jchar));
  env->GetStringRegion(jstr, 0, msgLen, msg);
  msg[msgLen] = 0;
  
  // This is the only message supported by the package. It is backed by
  // a message resource which consists of just '%1' which is replaced
  // by the string we just created.
  const DWORD messageID = 0x1000;
  ReportEventW(handle, getType(priority), 
	      getCategory(priority), 
	      messageID, NULL, 1, 0, (const wchar_t**) &msg, NULL);
  
  free((void *)msg);
  if (localHandle == JNI_TRUE) {
    // Created the handle here so free it here too.
    DeregisterEventSource(handle);
  }
  return;
}
Example #10
0
VOID
pfCloseEventLog (
)
/*++

Routine Description:

      Closes the handle to the event logger if this is the last caller

Arguments:

      None

Return Value:

      None

--*/
{
    if (hEventLog != NULL) {
        dwLogUsers--;         /* decrement usage */
        if (dwLogUsers <= 0) {    /* and if we're the last, then close up log */
            REPORT_INFORMATION (PFUTIL_CLOSING_LOG, LOG_DEBUG);
            DeregisterEventSource (hEventLog);
        }
    }
}
Example #11
0
static int JK_METHOD jk2_logger_win32_log(jk_env_t *env, jk_logger_t *l,                                 
                                 int level,
                                 const char *what)
{
    HANDLE h=RegisterEventSource(NULL,JAKARTA_EVENT_SOURCE);
    LPCTSTR *Buffer;
    Buffer=&what;
    if( h==NULL ) {
        return JK_ERR;
    }
    if(l && l->level <= level && what) {       
        if( level == JK_LOG_DEBUG_LEVEL ) {
            ReportEvent(h,EVENTLOG_SUCCESS,0,MSG_DEBUG,NULL,1,0,Buffer,NULL);
        } else if( level == JK_LOG_INFO_LEVEL ) {
            ReportEvent(h,EVENTLOG_INFORMATION_TYPE,0,MSG_INFO,NULL,1,0,Buffer,NULL);
        } else if( level == JK_LOG_ERROR_LEVEL ){
            ReportEvent(h,EVENTLOG_WARNING_TYPE,0,MSG_ERROR,NULL,1,0,Buffer,NULL);
        } else if( level == JK_LOG_EMERG_LEVEL ){
            ReportEvent(h,EVENTLOG_ERROR_TYPE,0,MSG_EMERG,NULL,1,0,Buffer,NULL);
        }
    }
    DeregisterEventSource(h);
    
    return JK_OK;
}
DWORD
MsgToEventLog (DWORD flags, LPCTSTR format, ...)
{
  HANDLE hEventSource;
  TCHAR msg[2][256];
  DWORD error = 0;
  LPCTSTR err_msg = TEXT("");
  va_list arglist;

  if (flags & MSG_FLAGS_SYS_CODE)
    {
      error = GetLastError ();
      err_msg = GetLastErrorText ();
    }

  hEventSource = RegisterEventSource (NULL, APPNAME);
  if (hEventSource != NULL)
    {
      openvpn_sntprintf (msg[0], _countof (msg[0]),
                         TEXT("%s%s: %s"), APPNAME,
                         (flags & MSG_FLAGS_ERROR) ? TEXT(" error") : TEXT(""), err_msg);

      va_start (arglist, format);
      openvpn_vsntprintf (msg[1], _countof (msg[1]), format, arglist);
      va_end (arglist);

      const TCHAR *mesg[] = { msg[0], msg[1] };
      ReportEvent (hEventSource, flags & MSG_FLAGS_ERROR ?
                   EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
                   0, 0, NULL, 2, 0, mesg, NULL);
      DeregisterEventSource (hEventSource);
    }

  return error;
}
Example #13
0
void IupLogV(const char* type, const char* format, va_list arglist)
{
  HANDLE EventSource;
  WORD wtype = 0;

  int size;
  char* value = iupStrGetLargeMem(&size);
  vsnprintf(value, size, format, arglist);

  if (iupStrEqualNoCase(type, "DEBUG"))
  {
    OutputDebugStringA(value);
    return;
  }
  else if (iupStrEqualNoCase(type, "ERROR"))
    wtype = EVENTLOG_ERROR_TYPE;
  else if (iupStrEqualNoCase(type, "WARNING"))
    wtype = EVENTLOG_WARNING_TYPE;
  else if (iupStrEqualNoCase(type, "INFO"))
    wtype = EVENTLOG_INFORMATION_TYPE;

  EventSource = RegisterEventSourceA(NULL, "Application");
  if (EventSource)
  {
    ReportEventA(EventSource, wtype, 0, 0, NULL, 1, 0, &value, NULL);
    DeregisterEventSource(EventSource);
  }
}
Example #14
0
void add2MsgLog(TCHAR* log)
{
    TCHAR msg[sizeof(SERVICE_NAME)/sizeof(TCHAR) + 100];
    HANDLE hEventSrouce;
    const TCHAR* logStr[2];
    DWORD dwErr;
    if (!bDebug) {
        dwErr = GetLastError();
        hEventSrouce = RegisterEventSource(NULL, SERVICE_NAME);
        _stprintf_s(msg, sizeof(msg)/sizeof(msg[0]), _T("%s error: %d"), SERVICE_NAME, dwErr);
        logStr[0] = msg;
        logStr[1] = log;

        if (hEventSrouce) {
            ReportEvent(hEventSrouce,
                        EVENTLOG_ERROR_TYPE,
                        0,
                        0,
                        NULL,
                        2,
                        0,
                        logStr,
                        NULL);
            DeregisterEventSource(hEventSrouce);

        }
    }
}
Example #15
0
//
//  FUNCTION: AddToMessageLog(LPTSTR lpszMsg,WORD Type,DWORD  dwError)
//
//  PURPOSE: Allows any thread to log an error message
//
//  PARAMETERS:
//    lpszMsg - text for message
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
VOID AddToMessageLog(LPTSTR lpszStrings[1],WORD NumString,WORD Type,WORD Category,DWORD  EventId)
{
    HANDLE  hEventSource;

    if ( !bDebug )
    {
        // Use event logging to log the error.
        //
        hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));
        if (hEventSource != NULL) 
		{
            ReportEvent(hEventSource, // handle of event source
                Type,                 // event type
                Category,             // event category
                EventId,              // event ID
                NULL,                 // current user's SID
                NumString,            // strings in lpszStrings
                0,                    // no bytes of raw data
                lpszStrings,          // array of error strings
                NULL);                // no raw data

            (VOID) DeregisterEventSource(hEventSource);
        }
    }
}
Example #16
0
void log_exit_platform(void) {
	if (_named_pipe_running) {
		SetEvent(_named_pipe_stop_event);

		thread_join(&_named_pipe_thread);
		thread_destroy(&_named_pipe_thread);
	}

	_named_pipe_connected = false;

	if (_named_pipe != INVALID_HANDLE_VALUE) {
		CloseHandle(_named_pipe);
	}

	if (_named_pipe_stop_event != NULL) {
		CloseHandle(_named_pipe_stop_event);
	}

	if (_named_pipe_write_event != NULL) {
		CloseHandle(_named_pipe_write_event);
	}

	if (_event_log != NULL) {
		DeregisterEventSource(_event_log);
	}

	mutex_destroy(&_named_pipe_write_event_mutex);
}
Example #17
0
//
//  FUNCTION: LogEventErrorMessage(LPTSTR lpszMsg)
//
//  PURPOSE: Allows any thread to log an error message
//
//  PARAMETERS:
//    lpszMsg - text for message
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
VOID LogEventErrorMessage(LPTSTR lpszMsg) {
    TCHAR   szMsg[1024];
    HANDLE  hEventSource;
    LPTSTR  lpszStrings[2];

    dwErr = GetLastError();

    // Use event logging to log the error.
    //
    hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));

    _stprintf_s(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr);
    lpszStrings[0] = szMsg;
    lpszStrings[1] = lpszMsg;

    if (hEventSource != NULL) {
        ReportEvent(hEventSource, // handle of event source
            EVENTLOG_ERROR_TYPE,  // event type
            0,                    // event category
            1,                    // event ID
            NULL,                 // current user's SID
            2,                    // strings in lpszStrings
            0,                    // no bytes of raw data
            (LPCSTR*)lpszStrings, // array of error strings
            NULL                  // no raw data
        );

        (VOID) DeregisterEventSource(hEventSource);
    }
}
Example #18
0
//
//   FUNCTION: ServiceBase::WriteEventLogEntry(PWSTR, WORD)
//
//   PURPOSE: Log a message to the Application event log.
//
//   PARAMETERS:
//   * pszMessage - string message to be logged.
//   * wType - the type of event to be logged. The parameter can be one of 
//     the following values.
//
//     EVENTLOG_SUCCESS
//     EVENTLOG_AUDIT_FAILURE
//     EVENTLOG_AUDIT_SUCCESS
//     EVENTLOG_ERROR_TYPE
//     EVENTLOG_INFORMATION_TYPE
//     EVENTLOG_WARNING_TYPE
//
void ServiceBase::WriteEventLogEntry(PWSTR pszMessage, WORD wType)
{
    HANDLE hEventSource = NULL;
    LPCWSTR lpszStrings[2] = { NULL, NULL };

    hEventSource = RegisterEventSource(NULL, m_name);
    if (hEventSource)
    {
        lpszStrings[0] = m_name;
        lpszStrings[1] = pszMessage;

        ReportEvent(hEventSource,  // Event log handle
            wType,                 // Event type
            0,                     // Event category
            0,                     // Event identifier
            NULL,                  // No security identifier
            2,                     // Size of lpszStrings array
            0,                     // No binary data
            lpszStrings,           // Array of strings
            NULL                   // No binary data
            );

        DeregisterEventSource(hEventSource);
    }
}
Example #19
0
int wmain(int argc, wchar_t *argv[]) {
  if (argc < 3) {
    printf("usage: %ls <pid> (n_args args ...)+\n", argv[0]);
    return 0;
  }

  event_log = RegisterEventSourceW(NULL, PROVIDER_NAME);

  wait_for_parent(argv[1]);

  int arg_index = 2;
  while (arg_index < argc - 1) {
    unsigned long cmd_argc = wcstoul(argv[arg_index++], NULL, 10);
    if (cmd_argc == 0 || cmd_argc > argc - arg_index) {
      log_event(ERR_ARGS, "unexpected '%s' @ %d", argv[arg_index - 1], arg_index - 1);
      break;
    } else {
      wchar_t **cmd_argv = argv + arg_index;
      arg_index += cmd_argc;
      run_command((int)cmd_argc, cmd_argv, arg_index >= argc - 1);
    }
  }

  if (event_log != NULL) {
    DeregisterEventSource(event_log);
  }

  return 0;
}
void WinService::LogEvent(LPCTSTR pFormat, ...)
{
	TCHAR    chMsg[256];
	HANDLE  hEventSource;
	LPTSTR  lpszStrings[1];
	va_list pArg;
	WinService *sv = WinService::GetService();
	va_start(pArg, pFormat);
	vsprintf(chMsg, pFormat, pArg);
	va_end(pArg);
	
	lpszStrings[0] = chMsg;
	if(_isdebug)
	{
		printf("%s\n",chMsg);
	}
	else
	{
		hEventSource = RegisterEventSource(NULL, sv->_servername);
		if (hEventSource != NULL)
		{
			ReportEvent(hEventSource, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
			DeregisterEventSource(hEventSource);
		}
	}
	
}
VOID SvcLogEvent(WORD aType, DWORD aId, LPSTR aText) 
{ 
	HANDLE hEventSource;
	LPCTSTR lpszStrings[3];

	hEventSource = RegisterEventSource(NULL, gService->name());

	if( NULL != hEventSource )
	{
		lpszStrings[0] = gService->name();
		lpszStrings[1] = "\n\n";
		lpszStrings[2] = aText;

		ReportEvent(hEventSource,        // event log handle
			aType, // event type
			0,                   // event category
			aId,           // event identifier
			NULL,                // no security identifier
			3,                   // size of lpszStrings array
			0,                   // no binary data
			lpszStrings,         // array of strings
			NULL);               // no binary data

		DeregisterEventSource(hEventSource);
	}
}
//
// Purpose: 
//   Logs messages to the event log
//
// Parameters:
//   szFunction - name of function that failed
// 
// Return value:
//   None
//
// Remarks:
//   The service must have an entry in the Application event log.
//
VOID SvcReportEvent(LPTSTR szFunction)
{
	HANDLE hEventSource;
	LPCTSTR lpszStrings[2];
	TCHAR Buffer[80];

	hEventSource = RegisterEventSource(NULL, SVCNAME);

	if (NULL != hEventSource)
	{
		StringCchPrintf(Buffer, 80, TEXT("%s failed with %d"), szFunction, GetLastError());

		lpszStrings[0] = SVCNAME;
		lpszStrings[1] = Buffer;

		ReportEvent(hEventSource,        // event log handle
			EVENTLOG_ERROR_TYPE, // event type
			0,                   // event category
			SVC_ERROR,           // event identifier
			NULL,                // no security identifier
			2,                   // size of lpszStrings array
			0,                   // no binary data
			lpszStrings,         // array of strings
			NULL);               // no binary data

		DeregisterEventSource(hEventSource);
	}
}
Example #23
0
VOID
MonCloseEventLog(
   )
/*++

Routine Description:

   Closes the handle to the event logger is this is the last caller.

Arguments:

   None

Return Value:

   None

--*/
{
   if (hEventLog != NULL) {

      dwLogUsers--;

      if (dwLogUsers <= 0) {

	 REPORT_INFORMATION(UTIL_CLOSING_LOG, LOG_DEBUG);

	 DeregisterEventSource(hEventLog);

      }
   }
} // end MonCloseEventLog
Example #24
0
///////////////////////////////////////////////////////////////////////////////////////
// Logging functions
void CServiceModule::LogEvent(LPCTSTR pFormat, ...)
{
    TCHAR    chMsg[256];
    HANDLE  hEventSource;
    LPTSTR  lpszStrings[1];
    va_list pArg;

    va_start(pArg, pFormat);
    _vstprintf(chMsg, pFormat, pArg);
    va_end(pArg);

    lpszStrings[0] = chMsg;

    if (m_bService)
    {
        /* Get a handle to use with ReportEvent(). */
        hEventSource = RegisterEventSource(NULL, m_szServiceName);
        if (hEventSource != NULL)
        {
            /* Write to event log. */
            ReportEvent(hEventSource, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
            DeregisterEventSource(hEventSource);
        }
    }
    else
    {
        // As we are not running as a service, just write the error to the console.
        _putts(chMsg);
    }
}
Example #25
0
///////////////////////////////////////////////////////////////////////////////////////
// Logging functions
int CServiceModule::LogEvent(WORD wType, int id, ...)
{
    CHAR    chMsg[256];
    HANDLE  hEventSource;
    LPSTR  lpszStrings[1];
    va_list pArg;

    va_start(pArg, id);
    _vsnprintf(chMsg, sizeof(chMsg), g_rgszLobbyEvents[id], pArg);
    va_end(pArg);

    lpszStrings[0] = chMsg;
    debugf("%s\n", lpszStrings[0]);

    if (m_bService)
    {
        /* Get a handle to use with ReportEvent(). */
        hEventSource = RegisterEventSourceA(NULL, m_szServiceName);
        if (hEventSource != NULL)
        {
            /* Write to event log. */
            ReportEvent(hEventSource, wType, 0, LobbyEventBaseID + id, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
            DeregisterEventSource(hEventSource);
        }
    }
    else
    {
        // As we are not running as a service, just write the error to the console.
        puts(chMsg);
    }
    return 0;
}
Example #26
0
// Error reporting
void LogErrorMsg(char *message)
{
    char	msgbuff[256];
    HANDLE	heventsrc;
    char *	strings[2];

	// Save the error code
	g_error = GetLastError();

	// Use event logging to log the error
    heventsrc = RegisterEventSource(NULL, VNCSERVICENAME);

	_snprintf(msgbuff, 256, "%s error: %d", VNCSERVICENAME, g_error);
    strings[0] = msgbuff;
    strings[1] = message;

	if (heventsrc != NULL)
	{
		MessageBeep(MB_OK);

		ReportEvent(
			heventsrc,				// handle of event source
			EVENTLOG_ERROR_TYPE,	// event type
			0,						// event category
			0,						// event ID
			NULL,					// current user's SID
			2,						// strings in 'strings'
			0,						// no bytes of raw data
			(const char **)strings,	// array of error strings
			NULL);					// no raw data

		DeregisterEventSource(heventsrc);
	}
}
Example #27
0
VOID
nt_rpc_report(LPTSTR lpszMsg)
{
    CHAR    chMsg[256];
    HANDLE  hEventSource;
    LPTSTR  lpszStrings[2];

    // Use event logging to log the error.
    //
    hEventSource = RegisterEventSource(NULL,
                            TEXT("rpc.dll"));

    sprintf(chMsg, "sunrpc report: %d", GetLastError());
    lpszStrings[0] = chMsg;
    lpszStrings[1] = lpszMsg;

    if (hEventSource != NULL) {
        ReportEvent(hEventSource, // handle of event source
            EVENTLOG_WARNING_TYPE, // event type
            0,                    // event category
            0,                    // event ID
            NULL,                 // current user's SID
            2,                    // strings in lpszStrings
            0,                    // no bytes of raw data
            lpszStrings,          // array of error strings
            NULL);                // no raw data

        (VOID) DeregisterEventSource(hEventSource);
    }
}
Example #28
0
void CNTL_shutdown_service(const TEXT* message)
{
/**************************************
 *
 *	C N T L _ s h u t d o w n _ s e r v i c e
 *
 **************************************
 *
 * Functional description
 *
 **************************************/
	const char* strings[2];
	char buffer[BUFFER_SMALL];

	sprintf(buffer, "%s error: %lu", service_name->c_str(), GetLastError());

	HANDLE event_source = RegisterEventSource(NULL, service_name->c_str());
	if (event_source)
	{
		strings[0] = buffer;
		strings[1] = message;
		ReportEvent(event_source, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 2, 0, strings, NULL);
		DeregisterEventSource(event_source);
	}

	if (stop_event_handle)
		SetEvent(stop_event_handle);
}
Example #29
0
//
//  FUNCTION: AddToMessageLog(LPTSTR lpszMsg)
//
//  PURPOSE: Allows any thread to log an error message
//
//  PARAMETERS:
//    lpszMsg - text for message
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
VOID AddToMessageLog(LPTSTR lpszMsg)
{
   TCHAR szMsg [(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100 ];
   HANDLE  hEventSource;
   LPTSTR  lpszStrings[2];

   if ( !bDebug )
   {
      dwErr = GetLastError();

      // Use event logging to log the error.
      //
      hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));

      _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr);
      lpszStrings[0] = szMsg;
      lpszStrings[1] = lpszMsg;

      if (hEventSource != NULL)
      {
         ReportEvent(hEventSource, // handle of event source
                     EVENTLOG_ERROR_TYPE,  // event type
                     0,                    // event category
                     0,                    // event ID
                     NULL,                 // current user's SID
                     2,                    // strings in lpszStrings
                     0,                    // no bytes of raw data
                     lpszStrings,          // array of error strings
                     NULL);                // no raw data

         (VOID) DeregisterEventSource(hEventSource);
      }
   }
}
Example #30
0
void
LogAnalysis::Reset()
{
  // Tell we closed 'normally'
  if(m_initialised)
  {
    AnalysisLog("Analysis log is:", LogType::LOG_INFO,false,"Closed");
  }
  if(!m_list.empty())
  {
    // Flushing the cache and ending all writing activity
    SetEvent(m_event);
    // Wait max 10 seconds to sync the logfile
    for(unsigned ind = 0; ind < 100; ++ind)
    {
      // Extra context for lock
      {
        AutoCritSec lock(&m_lock);
        if(m_list.empty())
        {
          break;
        }
      }
      Sleep(100);
    }
  }

  // De-initialize and so stopping the thread
  m_initialised = false;
  SetEvent(m_event);

  // Wait for a max of 200ms For the thread to stop
  for(unsigned ind = 0; ind < 10; ++ind)
  {
    if(m_logThread == NULL)
    {
      break;
    }
    Sleep(20);
  }

  // Flush file to disk, after thread has ended
  if(m_file)
  {
    CloseHandle(m_file);
    m_file = NULL;
  }
  // Clear the list (any remains get freed)
  m_list.clear();

  // Close events log
  if(m_eventLog)
  {
    DeregisterEventSource(m_eventLog);
    m_eventLog = NULL;
  }

  // Reset loglevel
  m_logLevel = HLL_NOLOG;
}