#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+
#ifdef WIN32
#include <process.h>
#include <winsock.h>
#include <direct.h>
-#include "service.h"
#endif
+
+#include <yaz/sc.h>
+
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
if (!strcmp((const char *) ptr->name, "host"))
{
gfs->host = nmem_dup_xml_content(gfs_nmem,
- ptr->children);
+ ptr->children);
}
else if (!strcmp((const char *) ptr->name, "config"))
{
/* Initialize the critical Sections */
InitializeCriticalSection(&Thread_CritSect);
- /* Set the first thraed */
+ /* Set the first thraed */
pFirstThread = NULL;
/* we have been initialized */
}
/* WIN32 statserv_closedown */
-void statserv_closedown()
+static void statserv_closedown()
{
/* Shouldn't do anything if we are not initialized */
if (bInitialized)
xml_config_close();
}
-void __cdecl event_loop_thread (IOCHAN iochan)
+void __cdecl event_loop_thread(IOCHAN iochan)
{
- iochan_event_loop (&iochan);
+ iochan_event_loop(&iochan);
}
/* WIN32 listener */
{
}
-void statserv_closedown()
+static void statserv_closedown(void)
{
IOCHAN p;
term_flag = 1;
}
-static void *new_session (void *vp);
+static void *new_session(void *vp);
static int no_sessions = 0;
/* UNIX listener */
{
#if YAZ_POSIX_THREADS
pthread_t child_thread;
- pthread_create (&child_thread, 0, new_session, new_line);
- pthread_detach (child_thread);
+ pthread_create(&child_thread, 0, new_session, new_line);
+ pthread_detach(child_thread);
#elif YAZ_GNU_THREADS
pth_attr_t attr;
pth_t child_thread;
- attr = pth_attr_new ();
- pth_attr_set (attr, PTH_ATTR_JOINABLE, FALSE);
- pth_attr_set (attr, PTH_ATTR_STACK_SIZE, 32*1024);
- pth_attr_set (attr, PTH_ATTR_NAME, "session");
- yaz_log (YLOG_DEBUG, "pth_spawn begin");
- child_thread = pth_spawn (attr, new_session, new_line);
- yaz_log (YLOG_DEBUG, "pth_spawn finish");
- pth_attr_destroy (attr);
+ attr = pth_attr_new();
+ pth_attr_set(attr, PTH_ATTR_JOINABLE, FALSE);
+ pth_attr_set(attr, PTH_ATTR_STACK_SIZE, 32*1024);
+ pth_attr_set(attr, PTH_ATTR_NAME, "session");
+ yaz_log(YLOG_DEBUG, "pth_spawn begin");
+ child_thread = pth_spawn(attr, new_session, new_line);
+ yaz_log(YLOG_DEBUG, "pth_spawn finish");
+ pth_attr_destroy(attr);
#else
new_session(new_line);
#endif
}
}
-static void *new_session (void *vp)
+static void *new_session(void *vp)
{
char *a;
association *newas;
COMSTACK new_line = (COMSTACK) vp;
IOCHAN parent_chan = (IOCHAN) new_line->user;
+ yaz_log_xml_errors(0, YLOG_WARN);
unsigned cs_get_mask, cs_accept_mask, mask =
((new_line->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) |
((new_line->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0);
else
yaz_log(YLOG_FATAL, "Failed to bind to %s: %s", where,
cs_strerror(l));
- cs_close (l);
+ cs_close(l);
return -1;
}
if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT |
- EVENT_EXCEPT, listen_id)))
+ EVENT_EXCEPT, listen_id)))
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to create IOCHAN-type");
- cs_close (l);
+ cs_close(l);
return -1;
}
iochan_setdata(lst, l); /* user-defined data for listener is COMSTACK */
{
}
-int statserv_start(int argc, char **argv)
+static int statserv_sc_main(yaz_sc_t s, int argc, char **argv)
{
char sep;
#ifdef WIN32
#else
sep = '/';
#endif
- if ((me = strrchr (argv[0], sep)))
+ if ((me = strrchr(argv[0], sep)))
me++; /* get the basename */
else
me = argv[0];
#ifdef WIN32
xml_config_add_listeners();
- yaz_log (log_server, "Starting server %s", me);
+ yaz_log(log_server, "Starting server %s", me);
if (!pListener && *control_block.default_listen)
add_listener(control_block.default_listen, 0);
#else
close(hand[1]);
- yaz_log (log_server, "Starting server %s pid=%ld", programname,
- (long) getpid());
+ yaz_log(log_server, "Starting server %s pid=%ld", programname,
+ (long) getpid());
#if 0
sigset_t sigs_to_block;
sigemptyset(&sigs_to_block);
- sigaddset (&sigs_to_block, SIGTERM);
- pthread_sigmask (SIG_BLOCK, &sigs_to_block, 0);
+ sigaddset(&sigs_to_block, SIGTERM);
+ pthread_sigmask(SIG_BLOCK, &sigs_to_block, 0);
/* missing... */
#endif
if (control_block.dynamic)
signal(SIGCHLD, catchchld);
}
- signal (SIGPIPE, SIG_IGN);
- signal (SIGTERM, sigterm);
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGTERM, sigterm);
if (*control_block.setuid)
{
struct passwd *pw;
#endif
if (pListener == NULL)
return 1;
+ if (s)
+ yaz_sc_running(s);
yaz_log(YLOG_DEBUG, "Entering event loop.");
return iochan_event_loop(&pListener);
}
yaz_log_init_level(yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL));
- yaz_log_xml_errors(0, YLOG_WARN);
get_logbits(1);
while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:r:",
control_block.default_proto = PROTO_Z3950;
break;
case 's':
- fprintf (stderr, "%s: SR protocol no longer supported\n", me);
- exit (1);
+ fprintf(stderr, "%s: SR protocol no longer supported\n", me);
+ exit(1);
break;
case 'S':
control_block.dynamic = 0;
fprintf(stderr, "Usage: %s [ -a <pdufile> -v <loglevel>"
" -l <logfile> -u <user> -c <config> -t <minutes>"
" -k <kilobytes> -d <daemon> -p <pidfile> -C certfile"
- " -ziDST1 -m <time-format> -w <directory> <listener-addr>... ]\n", me);
+ " -ziDST1 -m <time-format> -w <directory> <listener-addr>... ]\n", me);
return 1;
}
}
return 0;
}
-#ifdef WIN32
-typedef struct _Args
-{
- char **argv;
- int argc;
-} Args;
-
-static Args ArgDetails;
-
-/* name of the executable */
-#define SZAPPNAME "server"
-
-/* list of service dependencies - "dep1\0dep2\0\0" */
-#define SZDEPENDENCIES ""
-
-int statserv_main(int argc, char **argv,
- bend_initresult *(*bend_init)(bend_initrequest *r),
- void (*bend_close)(void *handle))
-{
- struct statserv_options_block *cb = &control_block;
- cb->bend_init = bend_init;
- cb->bend_close = bend_close;
-
- /* Lets setup the Arg structure */
- ArgDetails.argc = argc;
- ArgDetails.argv = argv;
-
- /* Now setup the service with the service controller */
- SetupService(argc, argv, &ArgDetails, SZAPPNAME,
- cb->service_name, /* internal service name */
- cb->service_display_name, /* displayed name */
- SZDEPENDENCIES);
- return 0;
-}
-
-int StartAppService(void *pHandle, int argc, char **argv)
-{
- /* Initializes the App */
- return 1;
-}
-
-void RunAppService(void *pHandle)
-{
- Args *pArgs = (Args *)pHandle;
-
- /* Starts the app running */
- statserv_start(pArgs->argc, pArgs->argv);
-}
-
-void StopAppService(void *pHandle)
+void statserv_sc_stop(yaz_sc_t s)
{
- /* Stops the app */
statserv_closedown();
statserv_reset();
}
-/* WIN32 */
-#else
-/* UNIX */
+
int statserv_main(int argc, char **argv,
bend_initresult *(*bend_init)(bend_initrequest *r),
void (*bend_close)(void *handle))
{
int ret;
+ struct statserv_options_block *cb = &control_block;
- control_block.bend_init = bend_init;
- control_block.bend_close = bend_close;
+ /* 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
+ );
- ret = statserv_start (argc, argv);
- statserv_closedown ();
- statserv_reset();
+ cb->bend_init = bend_init;
+ cb->bend_close = bend_close;
+
+ ret = yaz_sc_program(s, argc, argv, statserv_sc_main, statserv_sc_stop);
+ yaz_sc_destroy(&s);
return ret;
}
-#endif
+
/*
* Local variables:
* c-basic-offset: 4