summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-28 08:52:01 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-03-28 08:52:01 +0100
commit6f229e42fe0a5357f0bdcd06a3a792a5f7b30ab4 (patch)
tree9c259c2915a42c7ac535f1795caf4a6fe93bcedd
parent03d693a59e880e33e895b29f5cc1ff849c8945fe (diff)
downloadwolfbones-6f229e42fe0a5357f0bdcd06a3a792a5f7b30ab4.tar.gz
wolfbones-6f229e42fe0a5357f0bdcd06a3a792a5f7b30ab4.tar.bz2
added description of service
-rw-r--r--docs/service/README3
-rw-r--r--docs/service/TODOS6
-rw-r--r--include/wolf/log/messages.h1
-rw-r--r--include/wolf/service/service.h3
-rw-r--r--src/log/wolfmsg.mc10
-rw-r--r--src/service/service.c17
-rw-r--r--tests/service/testservice.c6
-rw-r--r--tests/service/testservicemsg.mc7
8 files changed, 42 insertions, 11 deletions
diff --git a/docs/service/README b/docs/service/README
index a046212..704f704 100644
--- a/docs/service/README
+++ b/docs/service/README
@@ -16,5 +16,4 @@ Good links:
to handle the events in foreground/console mode
- the Sphynx searchd.cpp: especially service description, console events
- POCO: on some design questions
-- Microsoft Knoledge Base: best source as always
-
+- Microsoft Knowledge Base: best source as always
diff --git a/docs/service/TODOS b/docs/service/TODOS
index 0fbfae5..d0dac53 100644
--- a/docs/service/TODOS
+++ b/docs/service/TODOS
@@ -1,10 +1,6 @@
-- we should also have a foreground option
-- the description shown in the event log, where is it set?
-- try to get rid of the static variables (HandlerEx and context?)
-- try to find a good set of functions which can go into src/service
- (in libwolf)
- option parsing on windows?
- have a generic message/po-file extractor, the perl script here is
an evil copy!
- handle poweroff and pause continue
- test long-duration startup and shutdown phases with checkpoint_hints
+
diff --git a/include/wolf/log/messages.h b/include/wolf/log/messages.h
index 0d0aa70..a234d28 100644
--- a/include/wolf/log/messages.h
+++ b/include/wolf/log/messages.h
@@ -186,6 +186,7 @@
#define WOLF_MSG_SERVICE_CANT_DISPATCH_SERVICE WOLF_MSG_SERVICE_BASE+17
#define WOLF_MSG_SERVICE_CANT_REGISTER_CONSOLE_CTRL_HANDLER WOLF_MSG_SERVICE_BASE+18
#define WOLF_MSG_SERVICE_CONSOLE_CTRL_RECEIVED WOLF_MSG_SERVICE_BASE+19
+#define WOLF_MSG_SERVICE_CANT_SET_SERVICE_DESCRIPTION WOLF_MSG_SERVICE_BASE+20
#ifdef __cplusplus
extern "C" {
diff --git a/include/wolf/service/service.h b/include/wolf/service/service.h
index fbe811e..04b5057 100644
--- a/include/wolf/service/service.h
+++ b/include/wolf/service/service.h
@@ -53,8 +53,9 @@ extern HANDLE service_stop_event;
typedef struct wolf_service_params_t {
LPCTSTR service_name; /**< internal name of the service (for instance for
'net start <service_name>') */
- LPCTSTR service_name_descr; /**< the descriptive name of the service (for instance
+ LPCTSTR service_display_name; /**< the displayed name of the service (for instance
shown in the event log viewer application) */
+ LPCTSTR service_description; /**< the description (as shown in the service control */
} wolf_service_params_t;
/**
diff --git a/src/log/wolfmsg.mc b/src/log/wolfmsg.mc
index afd799e..f3e65cc 100644
--- a/src/log/wolfmsg.mc
+++ b/src/log/wolfmsg.mc
@@ -873,6 +873,16 @@ Unable to create service '%1': %2 (%3)
Language = German
Kann den '%1' Dienst nicht erstellen: %2 (%3)
.
+MessageId = 3020
+Severity = Error
+Facility = Application
+SymbolicName = WOLF_MSG_SERVICE_CANT_SET_SERVICE_DESCRIPTION
+Language = English
+Unable to set description of service '%1': %2 (%3)
+.
+Language = German
+
+.
MessageId = 3005
Severity = Informational
Facility = Application
diff --git a/src/service/service.c b/src/service/service.c
index e1d11c1..d697b82 100644
--- a/src/service/service.c
+++ b/src/service/service.c
@@ -22,6 +22,8 @@ wolf_error_t wolf_service_install( wolf_service_params_t params ) {
char errbuf[512];
DWORD res;
TCHAR binary_path[MAX_PATH];
+ BOOL rt;
+ SERVICE_DESCRIPTION descr;
wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_SERVICE, WOLF_MSG_SERVICE_INSTALLING_SERVICE,
_( "Installing service '%s'" ), params.service_name );
@@ -61,7 +63,7 @@ wolf_error_t wolf_service_install( wolf_service_params_t params ) {
service = CreateService(
scm,
params.service_name,
- params.service_name_descr,
+ params.service_display_name,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS, /* run isolated in its own process */
SERVICE_DEMAND_START, /* let the user choose the start type */
@@ -82,6 +84,19 @@ wolf_error_t wolf_service_install( wolf_service_params_t params ) {
return WOLF_ERR_INTERNAL;
}
+ /* set description of the service */
+ descr.lpDescription = (LPTSTR)params.service_description;
+ rt = ChangeServiceConfig2( service, SERVICE_CONFIG_DESCRIPTION, &descr );
+ if( !rt ) {
+ WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 );
+ wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_SERVICE, WOLF_MSG_SERVICE_CANT_SET_SERVICE_DESCRIPTION,
+ _( "Unable to set description of service '%s': %s (%d)" ),
+ params.service_name, errbuf, GetLastError( ) );
+ (void)CloseServiceHandle( service );
+ (void)CloseServiceHandle( scm );
+ return WOLF_ERR_INTERNAL;
+ }
+
(void)CloseServiceHandle( service );
(void)CloseServiceHandle( scm );
diff --git a/tests/service/testservice.c b/tests/service/testservice.c
index ddc0347..0001fd6 100644
--- a/tests/service/testservice.c
+++ b/tests/service/testservice.c
@@ -21,7 +21,8 @@
#define WOLF_MSG_TESTSERVICE_STOPPED_SERVICE WOLF_MSG_TESTSERVICE_BASE+4
#define SERVICE_NAME "testservice"
-#define SERVICE_NAME_DESCR "Wolf Test Service"
+#define SERVICE_DISPLAY_NAME "Wolf Test Service"
+#define SERVICE_DESCRIPTION "A test service doing nothing"
static void WINAPI service_main( DWORD argc, LPTSTR *argv ) {
wolf_error_t error;
@@ -89,7 +90,8 @@ void __cdecl _tmain( int argc, TCHAR *argv[] ) {
} else if( strcasecmp( argv[1], "/install" ) == 0 ) {
wolf_service_params_t params;
params.service_name = SERVICE_NAME;
- params.service_name_descr = SERVICE_NAME_DESCR;
+ params.service_display_name = SERVICE_DISPLAY_NAME;
+ params.service_description = SERVICE_DESCRIPTION;
(void)wolf_service_install( params );
} else if( strcasecmp( argv[1], "/remove" ) == 0 ) {
(void)wolf_service_remove( SERVICE_NAME );
diff --git a/tests/service/testservicemsg.mc b/tests/service/testservicemsg.mc
index f632d6d..576b12f 100644
--- a/tests/service/testservicemsg.mc
+++ b/tests/service/testservicemsg.mc
@@ -636,6 +636,13 @@ SymbolicName = WOLF_MSG_SERVICE_CANT_CREATE_SERVICE
Language = English
Unable to create service '%1': %2 (%3)
.
+MessageId = 3020
+Severity = Error
+Facility = Application
+SymbolicName = WOLF_MSG_SERVICE_CANT_SET_SERVICE_DESCRIPTION
+Language = English
+Unable to set description of service '%1': %2 (%3)
+.
MessageId = 3005
Severity = Informational
Facility = Application