From c7753f2a498076aae60b9a4682041c573792d0cd Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 17 Jan 2004 01:20:12 +0000 Subject: [PATCH] Implement option -D, -p for GFS --- CHANGELOG | 4 +++ doc/frontend.xml | 5 ++-- doc/yaz-ztest-man.xml | 5 ++-- doc/ztest-options.xml | 17 ++++++++++- include/yaz/backend.h | 6 ++-- src/statserv.c | 78 ++++++++++++++++++++++++++++++++++++++++++------- 6 files changed, 98 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ffa8528..bd4d74c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ Possible compatibility problems with earlier versions marked with '*'. +Added option -p to make Generic Frontend Server to write PID file. + +Added option -D to put Generic Frontend Server in background on its own. + Make ZOOM C recognize option "password". If unset, "pass" is used (for backwards compatibility). diff --git a/doc/frontend.xml b/doc/frontend.xml index d8541cb..3c2a701 100644 --- a/doc/frontend.xml +++ b/doc/frontend.xml @@ -1,4 +1,4 @@ - + Generic server Introduction @@ -742,7 +742,8 @@ typedef struct bend_scan_rr { - + + listener-spec diff --git a/doc/yaz-ztest-man.xml b/doc/yaz-ztest-man.xml index f1b7fa8..6d13518 100644 --- a/doc/yaz-ztest-man.xml +++ b/doc/yaz-ztest-man.xml @@ -1,7 +1,7 @@ ]> - + @@ -29,7 +29,8 @@ - + + listener-spec diff --git a/doc/ztest-options.xml b/doc/ztest-options.xml index cf931bb..0606201 100644 --- a/doc/ztest-options.xml +++ b/doc/ztest-options.xml @@ -1,5 +1,5 @@ @@ -90,12 +90,27 @@ daemon (see -i). + -p + pidfile + + Specifies that the server should write its Process ID to + file given by pidfile. + A typical location would be /var/run/yaz-ztest.pid. + + -i Use this to make the the server run from the inetd server (UNIX only). + -D + + Use this to make the server put itself in the background and + run as a daemon. If neither -i nor + -D is given, the server starts in the foreground. + + -install Use this to install the server as an NT service diff --git a/include/yaz/backend.h b/include/yaz/backend.h index 1c63474..d6381dc 100644 --- a/include/yaz/backend.h +++ b/include/yaz/backend.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-2003, Index Data. + * Copyright (c) 1995-2004, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: backend.h,v 1.22 2003-12-29 14:54:33 adam Exp $ + * $Id: backend.h,v 1.23 2004-01-17 01:20:12 adam Exp $ */ #ifndef BACKEND_H @@ -272,6 +272,8 @@ typedef struct statserv_options_block char service_display_name[128]; /* The service display name */ #endif /* WIN32 */ struct bend_soap_handler *soap_handlers; + char pid_fname[128]; /* pid fname */ + int background; /* auto daemon */ } statserv_options_block; YAZ_EXPORT int statserv_main( diff --git a/src/statserv.c b/src/statserv.c index 8ef8acb..dd52b6a 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1,12 +1,12 @@ /* - * Copyright (c) 1995-2003, Index Data + * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.3 2004-01-15 10:05:56 adam Exp $ + * $Id: statserv.c,v 1.4 2004-01-17 01:20:13 adam Exp $ */ #include @@ -77,7 +77,9 @@ statserv_options_block control_block = { "", /* NT Service Dependencies */ "Z39.50 Server", /* NT Service Display Name */ #endif /* WIN32 */ - 0 /* SOAP handlers */ + 0, /* SOAP handlers */ + "", /* PID fname */ + 0 /* background daemon */ }; static int max_sessions = 0; @@ -706,7 +708,7 @@ static void statserv_reset(void) int statserv_start(int argc, char **argv) { - int ret; + int ret = 0; #ifdef WIN32 /* We need to initialize the thread list */ @@ -729,12 +731,38 @@ int statserv_start(int argc, char **argv) (*control_block.bend_start)(&control_block); #ifdef WIN32 yaz_log (LOG_LOG, "Starting server %s", me); + if (!pListener && *control_block.default_listen) + add_listener(control_block.default_listen, + control_block.default_proto); + + if (!pListener) + return 1; #else /* UNIX */ if (control_block.inetd) inetd_connection(control_block.default_proto); else { + if (!pListener && *control_block.default_listen) + add_listener(control_block.default_listen, + control_block.default_proto); + + if (!pListener) + return 1; + + if (*control_block.pid_fname) + { + FILE *f = fopen(control_block.pid_fname, "w"); + if (!f) + { + yaz_log(LOG_FATAL|LOG_ERRNO, "Couldn't create %s", + control_block.pid_fname); + exit(0); + } + fprintf(f, "%ld", (long) getpid()); + fclose(f); + } + yaz_log (LOG_LOG, "Starting server %s pid=%d", me, getpid()); #if 0 sigset_t sigs_to_block; @@ -764,10 +792,29 @@ int statserv_start(int argc, char **argv) exit(1); } } + if (!control_block.inetd && control_block.background) + { + switch (fork()) + { + case 0: + break; + case -1: + return 1; + default: + _exit(0); + } + + if (setsid() < 0) + return 1; + + close(0); + close(1); + close(2); + open("/dev/null",O_RDWR); + dup(0); dup(0); + } /* UNIX */ #endif - - if ((pListener == NULL) && *control_block.default_listen) add_listener(control_block.default_listen, control_block.default_proto); @@ -787,7 +834,7 @@ int check_options(int argc, char **argv) int ret = 0, r; char *arg; - while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:D:", argv, argc, &arg)) != -2) + while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:D", argv, argc, &arg)) != -2) { switch (ret) { @@ -867,14 +914,25 @@ int check_options(int argc, char **argv) return 1; } break; - case 'D': + case 'A': max_sessions = atoi(arg); break; + case 'p': + if (strlen(arg) >= sizeof(control_block.pid_fname)) + { + yaz_log(LOG_FATAL, "pid fname too long"); + exit(1); + } + strcpy(control_block.pid_fname, arg); + break; + case 'D': + control_block.background = 1; + break; default: fprintf(stderr, "Usage: %s [ -a -v " " -l -u -c -t " - " -k -d " - " -ziST1 -w ... ]\n", me); + " -k -d -p " + " -ziDST1 -w ... ]\n", me); return 1; } } -- 1.7.10.4