From e255616521c8ba665309bcaeccabb35b6efe35d7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 22 Apr 2008 11:18:11 +0200 Subject: [PATCH] Unix update for service control (sc). --- include/yaz/Makefile.am | 2 +- include/yaz/backend.h | 2 -- src/Makefile.am | 4 ++-- src/sc.c | 29 ++++++++++++++++++----------- src/statserv.c | 24 +++++++++++++----------- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index a1b13b6..6e0e1b5 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -12,7 +12,7 @@ pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h comstack.h \ yaz-ccl.h yaz-iconv.h yaz-util.h yaz-version.h yconfig.h proto.h \ xmlquery.h libxml2_error.h xmltypes.h snprintf.h query-charset.h \ mutex.h oid_db.h oid_util.h oid_std.h tokenizer.h copy_types.h \ - icu.h match_glob.h poll.h daemon.h \ + icu.h match_glob.h poll.h daemon.h sc.h \ \ ill.h ill-core.h item-req.h oclc-ill-req-ext.h z-accdes1.h z-accform1.h \ z-acckrb1.h z-core.h z-date.h z-diag1.h z-espec1.h z-estask.h z-exp.h \ diff --git a/include/yaz/backend.h b/include/yaz/backend.h index 19d4229..0ac1ceb 100644 --- a/include/yaz/backend.h +++ b/include/yaz/backend.h @@ -373,8 +373,6 @@ YAZ_EXPORT int statserv_main( int argc, char **argv, bend_initresult *(*bend_init)(bend_initrequest *r), void (*bend_close)(void *handle)); -YAZ_EXPORT int statserv_start(int argc, char **argv); -YAZ_EXPORT void statserv_closedown(void); YAZ_EXPORT statserv_options_block *statserv_getcontrol(void); YAZ_EXPORT void statserv_setcontrol(statserv_options_block *block); YAZ_EXPORT int check_ip_tcpd(void *cd, const char *addr, int len, int type); diff --git a/src/Makefile.am b/src/Makefile.am index b9b4db5..d219b00 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -97,12 +97,12 @@ libyaz_la_SOURCES=version.c options.c log.c \ record_conv.c retrieval.c elementset.c snprintf.c query-charset.c \ copy_types.c match_glob.c poll.c daemon.c \ iconv_encode_marc8.c iconv_encode_iso_8859_1.c iconv_encode_wchar.c \ - iconv_decode_marc8.c + iconv_decode_marc8.c sc.c libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO) libyaz_server_la_SOURCES = statserv.c seshigh.c eventl.c \ - requestq.c eventl.h session.h service.c service.h mutex.c + requestq.c eventl.h session.h mutex.c libyaz_server_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO) diff --git a/src/sc.c b/src/sc.c index 7102fa8..27df88a 100644 --- a/src/sc.c +++ b/src/sc.c @@ -25,8 +25,10 @@ struct sc_s { char *display_name; int (*sc_main)(yaz_sc_t s, int argc, char **argv); void (*sc_stop)(yaz_sc_t s); +#ifdef WIN32 SERVICE_STATUS_HANDLE gSvcStatusHandle; SERVICE_STATUS gSvcStatus; +#endif }; @@ -34,18 +36,21 @@ yaz_sc_t yaz_sc_create(const char *service_name, const char *display_name) { yaz_sc_t s = xmalloc(sizeof(*s)); - s->service_name = xstrdup(service_name); - s->display_name = xstrdup(display_name); + s->service_name = service_name ? xstrdup(service_name) : 0; + s->display_name = display_name ? xstrdup(display_name) : 0; s->install_flag = 0; s->start_flag = 0; s->remove_flag = 0; s->run_flag = 0; s->sc_main = 0; s->sc_stop = 0; +#ifdef WIN32 s->gSvcStatusHandle = 0; +#endif return s; } +#ifdef WIN32 static void parse_args(yaz_sc_t s, int *argc_p, char ***argv_p) { int skip_opt = 0; @@ -81,9 +86,9 @@ static void parse_args(yaz_sc_t s, int *argc_p, char ***argv_p) /* -run dir */ const char *dir = (*argv_p)[i+1]; s->run_flag = 1; - chdir(dir); - skip_opt = 2; - break; + chdir(dir); + skip_opt = 2; + break; } } *argc_p -= skip_opt; @@ -203,10 +208,13 @@ static void WINAPI sc_service_main(DWORD argc, char **argv) sc_ReportSvcStatus(s, SERVICE_STOPPED, ret_code ? ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR, ret_code); } +#endif void yaz_sc_running(yaz_sc_t s) { +#ifdef WIN32 sc_ReportSvcStatus(s, SERVICE_RUNNING, NO_ERROR, 0); +#endif } int yaz_sc_program(yaz_sc_t s, int argc, char **argv, @@ -216,6 +224,7 @@ int yaz_sc_program(yaz_sc_t s, int argc, char **argv, { s->sc_main = sc_main; s->sc_stop = sc_stop; +#ifdef WIN32 parse_args(s, &argc, &argv); if (s->install_flag || s->remove_flag) @@ -333,13 +342,11 @@ int yaz_sc_program(yaz_sc_t s, int argc, char **argv, yaz_log(YLOG_FATAL|YLOG_ERRNO, "Service %s could not be controlled", s->service_name); } + return 0; } - else - { - /* run the program standalone (with no service) */ - return s->sc_main(s, argc, argv); - } - return 0; +#endif /* WIN32 */ + /* run the program standalone (with no service) */ + return s->sc_main(s, argc, argv); } void yaz_sc_destroy(yaz_sc_t *s) diff --git a/src/statserv.c b/src/statserv.c index fafff6b..c5c416a 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -697,7 +697,7 @@ void statserv_remove(IOCHAN pIOChannel) } /* WIN32 statserv_closedown */ -void statserv_closedown() +static void statserv_closedown() { /* Shouldn't do anything if we are not initialized */ if (bInitialized) @@ -870,7 +870,7 @@ void statserv_remove(IOCHAN pIOChannel) { } -void statserv_closedown() +static void statserv_closedown(void) { IOCHAN p; @@ -1197,7 +1197,7 @@ static void statserv_reset(void) { } -int statserv_start(int argc, char **argv) +static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) { char sep; #ifdef WIN32 @@ -1340,6 +1340,8 @@ int statserv_start(int argc, char **argv) #endif if (pListener == NULL) return 1; + if (s) + yaz_sc_running(s); yaz_log(YLOG_DEBUG, "Entering event loop."); return iochan_event_loop(&pListener); } @@ -1493,12 +1495,6 @@ void statserv_sc_stop(yaz_sc_t s) statserv_reset(); } -int statserv_sc_main(yaz_sc_t s, int argc, char **argv) -{ - yaz_sc_running(s); - return statserv_start(argc, argv); -} - int statserv_main(int argc, char **argv, bend_initresult *(*bend_init)(bend_initrequest *r), void (*bend_close)(void *handle)) @@ -1506,8 +1502,14 @@ int statserv_main(int argc, char **argv, int ret; struct statserv_options_block *cb = &control_block; - yaz_sc_t s = yaz_sc_create(cb->service_name, - cb->service_display_name); + /* control block does not have service_name member on Unix */ + yaz_sc_t s = yaz_sc_create( +#ifdef WIN32 + cb->service_name, cb->service_display_name +#else + 0, 0 +#endif + ); cb->bend_init = bend_init; cb->bend_close = bend_close; -- 1.7.10.4