summaryrefslogtreecommitdiff
path: root/tests/service
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-23 20:59:00 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-03-23 20:59:00 +0100
commit2f0a989a9ebd8d93fdcaf9a8530fea94877f607f (patch)
tree3b76d2718a71c77beb2415a473bde6db0231e0bd /tests/service
parentbbbb86a7aeb2394e7c118ebe1edaa2be18350cda (diff)
downloadwolfbones-2f0a989a9ebd8d93fdcaf9a8530fea94877f607f.tar.gz
wolfbones-2f0a989a9ebd8d93fdcaf9a8530fea94877f607f.tar.bz2
stated a win32 wrapper for wolf_log, must continue tomorrow
Diffstat (limited to 'tests/service')
-rw-r--r--tests/service/testservice.c53
-rw-r--r--tests/service/testservice.mc44
2 files changed, 88 insertions, 9 deletions
diff --git a/tests/service/testservice.c b/tests/service/testservice.c
index 8675a97..7efa312 100644
--- a/tests/service/testservice.c
+++ b/tests/service/testservice.c
@@ -10,32 +10,71 @@
#define WOLF_CATEGORY_TESTSERVICE WOLF_LAST_INTERNAL_CATEGORY+1
#define WOLF_MSG_TESTSERVICE_BASE ( WOLF_CATEGORY_TESTSERVICE ) * 1000
-#define WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM WOLF_MSG_TESTSERVICE_BASE+1
+#define WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM WOLF_MSG_TESTSERVICE_BASE+1
+#define WOLF_MSG_TESTSERVICE_REGISTERING_SERVICE WOLF_MSG_TESTSERVICE_BASE+2
+
+/* TODO: log with GetLastErrror(), FormatStr(), should be a wrapper in wolf/log,
+ * the same we should also do for strerror_r
+ */
+static void wolf_log_win32( wolf_log_level_t level, int category_id, int message_id, const char *format, ... ) {
+ DWORD last_error = GetLastError( );
+ LPVOID buf;
+ DWORD buf_size;
+ DWORD res;
+
+ res = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, /* message is from system */
+ last_error, /* there is a message with that id */
+ 0, /* default language preference */
+ (LPTSTR)&buf, /* buffer allocated internally with LocalAlloc */
+ 0, /* minimum allocation size */
+ NULL ); /* no arguments */
+ }
+
+ if( res != 0 ) {
+
+ }
+
+ wolf_log(
+}
static void wolf_service_register( void ) {
SC_HANDLE scm;
+ wolf_log( WOLF_LOG_INFO, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_REGISTERING_SERVICE,
+ "Registering service" );
+
+ /* get service control manager with enough rights on the local
+ * machine to install the service
+ */
scm = (SC_HANDLE)OpenSCManager(
NULL, /* local computer */
SERVICES_ACTIVE_DATABASE,
SC_MANAGER_ALL_ACCESS );
- if( scm != NULL ) {
+ if( scm == NULL ) {
DWORD last_error = GetLastError( );
- wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM,
- _( "Unable to open the service control manager: %s (%d)" ),
- "", last_error );
+ wolf_log_win32( WOLF_LOG_EMERG, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM,
+ _( "Unable to open the service control manager to register srevice '%s'" ),
+ "testservice" );
}
+
}
void __cdecl _tmain( int argc, TCHAR *argv[] ) {
- wolf_log_openlogtostderr( WOLF_LOG_NOTICE );
+ wolf_log_openlogtostderr( WOLF_LOG_DEBUG );
wolf_log_openlogtofile( "testservice.log", WOLF_LOG_NOTICE );
wolf_log_openlogtoeventlog( NULL, "Application", "testservice",
"C:\\Temp\\testsrevice.dll", 3, WOLF_LOG_NOTICE );
- if( strcasecmp( argv[1], "install" ) == 0 ) {
+ if( argc < 2 ) {
+ return;
+ }
+
+ if( strcasecmp( argv[1], "/install" ) == 0 ) {
wolf_service_register( );
}
diff --git a/tests/service/testservice.mc b/tests/service/testservice.mc
index 8b032be..658aad0 100644
--- a/tests/service/testservice.mc
+++ b/tests/service/testservice.mc
@@ -27,9 +27,9 @@ Category 2
.
MessageId = 0x3
-SymbolicName = WOLF_CATEGORY_TESTSERVICE
+SymbolicName = WOLF_CATEGORY_3
Language = English
-Testservice
+Test Category
.
;// event log severity levels (severity bits)
@@ -59,3 +59,43 @@ 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
+.