X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fstatserv.c;h=cfe2ed0f61567bf0d23178302ec12adec35441ce;hb=719e0dcf2d15c08086a06457701e21c6aff3d791;hp=dd52b6a926f3fa2f5011d5c9715401822da27a17;hpb=c7753f2a498076aae60b9a4682041c573792d0cd;p=yaz-moved-to-github.git diff --git a/src/statserv.c b/src/statserv.c index dd52b6a..cfe2ed0 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1,12 +1,11 @@ /* * 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.4 2004-01-17 01:20:13 adam Exp $ + * $Id: statserv.c,v 1.8 2004-05-10 10:47:04 adam Exp $ */ #include @@ -79,7 +78,8 @@ statserv_options_block control_block = { #endif /* WIN32 */ 0, /* SOAP handlers */ "", /* PID fname */ - 0 /* background daemon */ + 0, /* background daemon */ + "" /* SSL certificate filename */ }; static int max_sessions = 0; @@ -655,9 +655,12 @@ static int add_listener(char *where, int what) l = cs_create_host(where, 2, &ap); if (!l) { - yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to listen on %s", where); + yaz_log(LOG_FATAL, "Failed to listen on %s", where); return -1; } + if (*control_block.cert_fname) + cs_set_ssl_certificate_file(l, control_block.cert_fname); + if (cs_bind(l, ap, CS_SERVER) < 0) { yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to bind to %s", where); @@ -743,6 +746,27 @@ int statserv_start(int argc, char **argv) inetd_connection(control_block.default_proto); else { + if (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); + } if (!pListener && *control_block.default_listen) add_listener(control_block.default_listen, control_block.default_proto); @@ -792,27 +816,6 @@ 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) @@ -834,7 +837,8 @@ 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:A:p:D", argv, argc, &arg)) != -2) + while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:", + argv, argc, &arg)) != -2) { switch (ret) { @@ -885,6 +889,9 @@ int check_options(int argc, char **argv) case 'c': strcpy(control_block.configname, arg ? arg : ""); break; + case 'C': + strcpy(control_block.cert_fname, arg ? arg : ""); + break; case 'd': strcpy(control_block.daemon_name, arg ? arg : ""); break; @@ -931,7 +938,7 @@ int check_options(int argc, char **argv) default: fprintf(stderr, "Usage: %s [ -a -v " " -l -u -c -t " - " -k -d -p " + " -k -d -p -C certfile" " -ziDST1 -w ... ]\n", me); return 1; }