diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-25 22:02:24 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-25 22:02:24 +0100 |
commit | bc6d2e142667176dddf9a68e9c5009b9a199ca9d (patch) | |
tree | e5b5dbf2803b95e24b3d98b413f921bd6c5391f1 /tests/service | |
parent | 065315f7fd84f1707626113a1f29de9bc46d4bcd (diff) | |
download | wolfbones-bc6d2e142667176dddf9a68e9c5009b9a199ca9d.tar.gz wolfbones-bc6d2e142667176dddf9a68e9c5009b9a199ca9d.tar.bz2 |
fixed logging to even log of testservice, works
Diffstat (limited to 'tests/service')
-rw-r--r-- | tests/service/Makefile.W32 | 12 | ||||
-rw-r--r-- | tests/service/TODOS | 2 | ||||
-rwxr-xr-x | tests/service/create_testservicemsg.pl | 196 | ||||
-rw-r--r-- | tests/service/testservice.c | 12 | ||||
-rw-r--r-- | tests/service/testservice.mc | 101 | ||||
-rw-r--r-- | tests/service/testservicemsg.mc | 196 |
6 files changed, 410 insertions, 109 deletions
diff --git a/tests/service/Makefile.W32 b/tests/service/Makefile.W32 index 29a0c94..a841462 100644 --- a/tests/service/Makefile.W32 +++ b/tests/service/Makefile.W32 @@ -14,7 +14,7 @@ INCLUDE_LIBS = \ advapi32.lib kernel32.lib LIBRARIES = \ - testservice.dll + testservicemsg.dll TEST_BINS = \ testservice.exe @@ -23,15 +23,15 @@ TEST_BINS = \ test_service.exe: test_service.obj $(TOPDIR)\src\wolf.lib -testservice.dll: testservice.res +testservicemsg.dll: testservicemsg.res $(LINK) /dll /nologo /noentry /MACHINE:x86 /out:$@ $? -testservice.rc: testservice.mc -testservice.res: testservice.rc +testservicemsg.rc: testservicemsg.mc +testservicemsg.res: testservicemsg.rc local_test: $(LIBRARIES) @echo Testing service.. - @copy testservice.dll C:\TEMP >NUL + @copy testservicemsg.dll C:\TEMP >NUL @testservice /install 2>NUL @net start testservice >NUL @net stop testservice >NUL @@ -41,6 +41,6 @@ local_all: local_clean: @-erase testservice.log 2>NUL - @-erase $(LIBRARIES) testservice.h 2>NUL + @-erase $(LIBRARIES) testservicemsg.h 2>NUL local_distclean: diff --git a/tests/service/TODOS b/tests/service/TODOS new file mode 100644 index 0000000..bf45ba7 --- /dev/null +++ b/tests/service/TODOS @@ -0,0 +1,2 @@ +- have a generic message/po-file extractor, the perl script here is + an evil copy! diff --git a/tests/service/create_testservicemsg.pl b/tests/service/create_testservicemsg.pl new file mode 100755 index 0000000..6fea267 --- /dev/null +++ b/tests/service/create_testservicemsg.pl @@ -0,0 +1,196 @@ +#!/usr/bin/perl -w + +use strict; + +# configuration + +my %gettext_lang = ( + "German" => "../po/de.po" +); + +# header declaring the langages +print <<EOF; +;// messages file for wolf messages + +;// language codes for translated messages +;// (409 ist the windows locale for en-US) +;// (see http://msdn.microsoft.com/en-us/library/ms776260.aspx) +LanguageNames = ( + English = 0x0409 : MSG00409 +; German = 0x0407 : MSG00407 +) + +;// Category names come first, the 'CategoryCount' registry entry +;// for the event source must match the number of entries here. +;// Also the numbering must be strictly starting by one and increase +;// by one. Careful: categories MUST be defined here, the message +;// compiler is a little bit flag and context infected. Also make +;// sure they are not longer than 10 characters, the event viewer +;// field is quite small. + +EOF + +# read all gettext translations +my $lang; +my %gettext = (); +foreach $lang ( keys %gettext_lang ) { + my $pofile = $gettext_lang{$lang}; + open PO, "<$pofile"; + my $line; + my $msgid; + my $msgstr; + foreach $line ( <PO> ) { + if( $line =~ /^msgid\s+"(.*)"/ ) { + $msgid = $1; + } elsif( $line =~ /^msgstr\s+"(.*)"/ ) { + $msgstr = $1; + $gettext{"${lang}_${msgid}"} = $msgstr; + } + } + close PO; +} + + +print <<EOF; +MessageId = 0x1 +SymbolicName = WOLF_CATEGORY_LOGGER +Language = English +Logger +. +;Language = German +;Logger +;. + +MessageId = 0x2 +SymbolicName = WOLF_CATEGORY_DAEMON +Language = English +Dameon +. +;Language = German +;Unix-Prozess +;. + +MessageId = 0x3 +SymbolicName = WOLF_CATEGORY_TESTSERVICE +Language = English +test service +. + +EOF + +# constants things defined by the event logger (advapi32.dll) +print <<EOF; + +;// event log severity levels (severity bits) +SeverityNames = ( + Success = 0x0 : STATUS_SEVERITY_SUCCESS + Informational = 0x1 : STATUS_SEVERITY_INFORMATIONAL + Warning = 0x2 : STATUS_SEVERITY_WARNING + Error = 0x3 : STATUS_SEVERITY_ERROR +) + +;// we get a already defined message? but where is Application defined? +;// facility names +FacilityNames = ( + System = 0x0FF + Application = 0xFFF +) + +EOF + +print <<EOF; + +;// event messages from here + +MessageIdTypedef = DWORD + +EOF + +undef $/; + +open CONTENT, "find . -name '*.c' -exec cat {} \\; |"; +my $code = <CONTENT>; +close CONTENT; + +open CONTENT, "find . -name '*.c' -exec cat {} \\; | cpp -DENABLE_NLS=1 -I../../include/wolf |"; +my $expanded_code = <CONTENT>; +close CONTENT; + +for( ;; ) { + if( !( $code =~ /wolf_log\s*\(([^\;]*)/s ) ) { + last; + } + my $func = $1; + $code = $'; + +AGAIN: + if( !( $expanded_code =~ /wolf_log\s*\(([^\;]*)/s ) ) { + exit 1; + } + my $expanded_func = $1; + $expanded_code = $'; + + if( $func =~ /\s*(WOLF_LOG_[^\, ]+)\s*\,\s*(WOLF_CATEGORY_[^\, ]+)\s*\,\s*(WOLF_MSG_[^\, ]+)\s*\,\s*_\(\s*"([^"]*)/ ) { + my $level = $1; + my $category = $2; + my $messageid = $3; + my $formatstr_c = $4; + + # map C snprintf format to positional format + my $formatstr_win = $formatstr_c; + my $pos = 1; + while( $formatstr_win =~ s/%[sd]/%${pos}/ ) { $pos++ }; + + # map the Wolf levels to windows event log severity levels + my $severity; + if( $level =~ /WOLF_LOG_((EMERG)|(ALERT)|(CRIT)|(ERR))/ ) { + $severity = "Error"; + } elsif( $level eq " WOLF_LOG_WARNING" ) { + $severity = "Warning"; + } else { + $severity = "Informational"; + } + + # fetch expanded message id from the CPP output + my $messageid_number = 9999999; + if( $expanded_func =~ /\s*(WOLF_LOG_[^\, ]+)\,\s*([\d\s\+]+)\,\s*([^\,]+)/ ) { + my $expanded_messageid = $3; + $messageid_number = eval $expanded_messageid; + } else { +# print "SKIP $expanded_func\n"; + goto AGAIN; + } + + print <<EOF; +MessageId = $messageid_number +Severity = $severity +Facility = Application +SymbolicName = $messageid +EOF + + # print all translations found in gettext .po files + my @langs = ( "English" ); + my $lang; + foreach $lang ( @langs ) { + if( $lang eq "English" ) { + print <<EOF; +Language = $lang +$formatstr_win +. +EOF + } else { + my $msg = $gettext{"${lang}_${formatstr_c}"}; + + # map C snprintf format to positional format + my $pos = 1; + while( $msg =~ s/%[sd]/%${pos}/ ) { $pos++ }; + + print <<EOF; +Language = $lang +$msg +. +EOF + } + } + } +} diff --git a/tests/service/testservice.c b/tests/service/testservice.c index 3370644..70da431 100644 --- a/tests/service/testservice.c +++ b/tests/service/testservice.c @@ -23,7 +23,7 @@ #define WOLF_MSG_TESTSERVICE_CANT_OPEN_SERVICE WOLF_MSG_TESTSERVICE_BASE+9 #define WOLF_MSG_TESTSERVICE_CANT_DELETE_SERVICE WOLF_MSG_TESTSERVICE_BASE+10 #define WOLF_MSG_TESTSERVICE_CANT_DISPATCH_SERVICE WOLF_MSG_TESTSERVICE_BASE+11 -#define WOLF_MSG_TESTSERVICE_CANT_REGISTER_SERVICE_CTRL_HANDLER WOLF_MSG_TESTSERVICE_BASE+12 +#define WOLF_MSG_TESTSERVICE_CANT_REGISTER_SERVICE_CTRL_HANDLER WOLF_MSG_TESTSERVICE_BASE+12 #define WOLF_MSG_TESTSERVICE_HANDLING_EVENT WOLF_MSG_TESTSERVICE_BASE+13 #define WOLF_MSG_TESTSERVICE_STARTED_SERVICE WOLF_MSG_TESTSERVICE_BASE+14 #define WOLF_MSG_TESTSERVICE_STOPPED_SERVICE WOLF_MSG_TESTSERVICE_BASE+15 @@ -252,6 +252,12 @@ void WINAPI wolf_service_main( DWORD argc, LPTSTR *argv ) { char errbuf[512]; BOOL res; + /* all other loggers make no sense: a service is not supposed + * to have a logfile or interaction with the user in any way! + */ + wolf_log_openlogtoeventlog( NULL, "Application", "testservice", + "C:\\Temp\\testservicemsg.dll", 3, WOLF_LOG_DEBUG ); + /* register the event callback where we get called by the service * manager and the system */ @@ -319,6 +325,8 @@ SERVICE_END: wolf_log( WOLF_LOG_NOTICE, WOLF_CATEGORY_DAEMON, WOLF_MSG_TESTSERVICE_STOPPED_SERVICE, _( "Stopped %s service" ), SERVICE_NAME ); + wolf_log_closelogtoeventlog( ); + return; } @@ -328,7 +336,7 @@ void __cdecl _tmain( int argc, TCHAR *argv[] ) { wolf_log_openlogtostderr( WOLF_LOG_DEBUG ); wolf_log_openlogtofile( "testservice.log", WOLF_LOG_DEBUG ); wolf_log_openlogtoeventlog( NULL, "Application", "testservice", - "C:\\Temp\\testsrevice.dll", 3, WOLF_LOG_DEBUG ); + "C:\\Temp\\testservicemsg.dll", 3, WOLF_LOG_DEBUG ); /* called as service, dispatch the main service thread */ if( argc < 2 ) { diff --git a/tests/service/testservice.mc b/tests/service/testservice.mc deleted file mode 100644 index 658aad0..0000000 --- a/tests/service/testservice.mc +++ /dev/null @@ -1,101 +0,0 @@ -;// messages file for wolf messages - -;// language codes for translated messages -;// (409 ist the windows locale for en-US) -LanguageNames = ( - English = 0x409 : MSG00409 -) - -;// Category names come first, the 'CategoryCount' registry entry -;// for the event source must match the number of entries here. -;// Also the numbering must be strictly starting by one and increase -;// by one. Careful: categories MUST be defined here, the message -;// compiler is a little bit flag and context infected. Also make -;// sure they are not longer than 10 characters, the event viewer -;// field is quite small. - -MessageId = 0x1 -SymbolicName = WOLF_CATEGORY_1 -Language = English -Category 1 -. - -MessageId = 0x2 -SymbolicName = WOLF_CATEGORY_2 -Language = English -Category 2 -. - -MessageId = 0x3 -SymbolicName = WOLF_CATEGORY_3 -Language = English -Test Category -. - -;// event log severity levels (severity bits) -SeverityNames = ( - Success = 0x0 : STATUS_SEVERITY_SUCCESS - Informational = 0x1 : STATUS_SEVERITY_INFORMATIONAL - Warning = 0x2 : STATUS_SEVERITY_WARNING - Error = 0x3 : STATUS_SEVERITY_ERROR -) - -;// facility names -FacilityNames = ( - System = 0x0FF - Application = 0xFFF -) - - - -;// event messages from here - -MessageIdTypedef = DWORD - -MessageId = 3001 -Severity = Error -Facility = Application -SymbolicName = WOLF_CATEGORY_TEST_LOG_MSG1 -Language = English -This is error %1 -. - -MessageId = 3002 -Severity = Warning -Facility = Application -SymbolicName = WOLF_MSG_TEST_LOG_MSG2 -Language = English -Warning, this is just a test -. - -MessageId = 3003 -Severity = Informational -Facility = Application -SymbolicName = WOLF_MSG_TEST_LOG_MSG3 -Language = English -Started the logger -. - -MessageId = 3004 -Severity = Informational -Facility = Application -SymbolicName = WOLF_MSG_TEST_LOG_MSG4 -Language = English -This will not appear -. - -MessageId = 3005 -Severity = Informational -Facility = Application -SymbolicName = WOLF_MSG_TEST_LOG_MSG5 -Language = English -Closed the logger -. - -MessageId = 3006 -Severity = Error -Facility = Application -SymbolicName = WOLF_MSG_TEST_LOG_MSG6 -Language = English -This is error %1 with %2 -. diff --git a/tests/service/testservicemsg.mc b/tests/service/testservicemsg.mc new file mode 100644 index 0000000..86b4ccf --- /dev/null +++ b/tests/service/testservicemsg.mc @@ -0,0 +1,196 @@ +;// messages file for wolf messages + +;// language codes for translated messages +;// (409 ist the windows locale for en-US) +;// (see http://msdn.microsoft.com/en-us/library/ms776260.aspx) +LanguageNames = ( + English = 0x0409 : MSG00409 +; German = 0x0407 : MSG00407 +) + +;// Category names come first, the 'CategoryCount' registry entry +;// for the event source must match the number of entries here. +;// Also the numbering must be strictly starting by one and increase +;// by one. Careful: categories MUST be defined here, the message +;// compiler is a little bit flag and context infected. Also make +;// sure they are not longer than 10 characters, the event viewer +;// field is quite small. + +MessageId = 0x1 +SymbolicName = WOLF_CATEGORY_LOGGER +Language = English +Logger +. +;Language = German +;Logger +;. + +MessageId = 0x2 +SymbolicName = WOLF_CATEGORY_DAEMON +Language = English +Dameon +. +;Language = German +;Unix-Prozess +;. + +MessageId = 0x3 +SymbolicName = WOLF_CATEGORY_TESTSERVICE +Language = English +test service +. + + +;// event log severity levels (severity bits) +SeverityNames = ( + Success = 0x0 : STATUS_SEVERITY_SUCCESS + Informational = 0x1 : STATUS_SEVERITY_INFORMATIONAL + Warning = 0x2 : STATUS_SEVERITY_WARNING + Error = 0x3 : STATUS_SEVERITY_ERROR +) + +;// we get a already defined message? but where is Application defined? +;// facility names +FacilityNames = ( + System = 0x0FF + Application = 0xFFF +) + + +;// event messages from here + +MessageIdTypedef = DWORD + +MessageId = 3002 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_INSTALLING_SERVICE +Language = English +Installing service '%1' +. +MessageId = 3001 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM_FOR_INSTALL +Language = English +Unable to open the service control manager to register service '%1': %2 (%3) +. +MessageId = 3003 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_GET_PATH_OF_BINARY +Language = English +Unable to get full path of the binary of service '%1': %2 (%3) +. +MessageId = 3004 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_CREATE_SERVICE +Language = English +Unable to create service '%1': %2 (%3) +. +MessageId = 3005 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_SERVICE_INSTALLED +Language = English +Service '%1' installed successfully +. +MessageId = 3006 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_UNINSTALLING_SERVICE +Language = English +Unistalling service '%1' +. +MessageId = 3008 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM_FOR_UNINSTALL +Language = English +Unable to open the service control manager to uninstall '%1': %2 (%3) +. +MessageId = 3009 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_OPEN_SERVICE +Language = English +Unable to open service '%1': %2 (%3) +. +MessageId = 3010 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_DELETE_SERVICE +Language = English +Unable to uninstall service '%1': %2 (%3) +. +MessageId = 3007 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_SERVICE_UNINSTALLED +Language = English +Service '%1' uninstalled successfully +. +MessageId = 3019 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_REPORT_STATUS +Language = English +reporting status with new state %1 (currently in state %2) +. +MessageId = 3017 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_REPORT_STATUS +Language = English +Unable to report state %1 of service '%2' to SCM '%3 (%4) +. +MessageId = 3013 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_HANDLING_EVENT +Language = English +service handler received event %1 +. +MessageId = 3012 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_REGISTER_SERVICE_CTRL_HANDLER +Language = English +Unable to register service control handler function for service '%1': %2 (%3) +. +MessageId = 3016 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_CREATE_STOP_EVENT +Language = English +Unable to create the stop event for service '%1': %2 (%3) +. +MessageId = 3014 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_STARTED_SERVICE +Language = English +Started %1 service +. +MessageId = 3018 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_WAIT_FOR_OBJECT_FAILED +Language = English +Waiting for the stop event for service '%1' failed: %2 (%3) +. +MessageId = 3015 +Severity = Informational +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_STOPPED_SERVICE +Language = English +Stopped %1 service +. +MessageId = 3011 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TESTSERVICE_CANT_DISPATCH_SERVICE +Language = English +Unable to dispatch service '%1': %2 (%3) +. |