2 * Copyright (c) 1995-2000, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * NT server based on threads by
7 * Chas Woodfield, Fretwell Downing Informatics.
10 * Revision 1.66 2000-10-06 12:00:28 adam
11 * Fixed Handle leak for WIN32.
13 * Revision 1.65 2000/09/04 08:58:15 adam
14 * Added prefix yaz_ for most logging utility functions.
16 * Revision 1.64 2000/04/05 07:39:55 adam
17 * Added shared library support (libtool).
19 * Revision 1.63 2000/03/20 19:06:25 adam
20 * Added Segment request for fronend server. Work on admin for client.
22 * Revision 1.62 2000/03/17 12:47:02 adam
23 * Minor changes to admin client.
25 * Revision 1.61 2000/03/15 12:59:49 adam
26 * Added handle member to statserv_control.
28 * Revision 1.60 2000/03/14 09:06:11 adam
29 * Added POSIX threads support for frontend server.
31 * Revision 1.59 1999/11/30 13:47:12 adam
32 * Improved installation. Moved header files to include/yaz.
34 * Revision 1.58 1999/08/27 09:40:32 adam
35 * Renamed logf function to yaz_log. Removed VC++ project files.
37 * Revision 1.57 1999/07/06 12:17:15 adam
38 * Added option -1 that runs server once (for profiling purposes).
40 * Revision 1.56 1999/06/10 11:45:30 adam
41 * Added bend_start, bend_stop handlers and removed pre_init.
42 * Handlers bend_start/bend_stop are called when service/daemon is
45 * Revision 1.55 1999/06/10 09:18:54 adam
46 * Modified so that pre_init is called when service/server is started.
48 * Revision 1.54 1999/04/16 14:45:55 adam
49 * Added interface for tcpd wrapper for access control.
51 * Revision 1.53 1999/02/02 13:57:39 adam
52 * Uses preprocessor define WIN32 instead of WINDOWS to build code
53 * for Microsoft WIN32.
55 * Revision 1.52 1998/08/21 14:13:34 adam
56 * Added GNU Configure script to build Makefiles.
58 * Revision 1.51 1998/07/07 15:51:03 adam
59 * Changed server so that it stops if bind fails - "address already in
60 * use" typically causes this.
62 * Revision 1.50 1998/06/22 11:32:39 adam
63 * Added 'conditional cs_listen' feature.
65 * Revision 1.49 1998/02/27 14:04:55 adam
66 * Fixed bug in statserv_remove.
68 * Revision 1.48 1998/02/11 11:53:36 adam
69 * Changed code so that it compiles as C++.
71 * Revision 1.47 1998/02/10 10:28:57 adam
72 * Added app_name, service_dependencies, service_display_name and
73 * options_func. options_func allows us to specify a different function
74 * to interogate the command line arguments. The other members allow us
75 * to pass the full service details accross to the service manager (CW).
78 * Revision 1.46 1998/01/30 15:24:57 adam
79 * Fixed bug in inetd code. The server listened on tcp:@:9999 even
80 * though it was started in inetd mode.
82 * Revision 1.45 1998/01/29 13:30:23 adam
83 * Better event handle system for NT/Unix.
85 * Revision 1.44 1997/11/07 13:31:52 adam
86 * Added NT Service name part of statserv_options_block. Moved NT
87 * service utility to server library.
89 * Revision 1.43 1997/10/31 12:20:09 adam
90 * Improved memory debugging for xmalloc/nmem.c. References to NMEM
91 * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
92 * Bug fix: missing fclose in data1_read_espec1.
94 * Revision 1.42 1997/10/27 14:03:02 adam
95 * Added new member to statserver_options_block, pre_init, which
96 * specifies a callback to be invoked after command line parsing and
97 * before the server listens for the first time.
99 * Revision 1.41 1997/09/29 07:19:32 adam
100 * Server library uses nmem_init/nmem_exit. The log prefix no longer
101 * includes leading path on NT.
103 * Revision 1.40 1997/09/17 12:10:41 adam
106 * Revision 1.39 1997/09/09 10:10:19 adam
107 * Another MSV5.0 port. Changed projects to include proper
108 * library/include paths.
109 * Server starts server in test-mode when no options are given.
111 * Revision 1.38 1997/09/04 14:19:14 adam
114 * Revision 1.37 1997/09/01 08:53:01 adam
115 * New windows NT/95 port using MSV5.0. The test server 'ztest' was
116 * moved a separate directory. MSV5.0 project server.dsp created.
117 * As an option, the server can now operate as an NT service.
119 * Revision 1.36 1996/07/06 19:58:36 quinn
120 * System headerfiles gathered in yconfig
122 * Revision 1.35 1996/05/29 10:03:28 quinn
125 * Revision 1.34 1996/02/21 13:12:07 quinn
126 * *** empty log message ***
128 * Revision 1.33 1996/02/10 12:23:49 quinn
129 * Enable inetd operations fro TCP/IP stack
131 * Revision 1.32 1996/01/19 15:41:52 quinn
132 * *** empty log message ***
134 * Revision 1.31 1995/11/17 11:09:39 adam
135 * Added new option '-c' to specify configuration name in control block.
137 * Revision 1.30 1995/11/01 13:54:59 quinn
140 * Revision 1.29 1995/10/30 12:41:29 quinn
141 * Added hostname lookup for server.
143 * Revision 1.28 1995/09/29 17:12:30 quinn
146 * Revision 1.27 1995/09/27 15:03:02 quinn
147 * Modified function heads & prototypes.
149 * Revision 1.26 1995/08/29 14:44:51 quinn
152 * Revision 1.25 1995/08/29 11:18:02 quinn
153 * Added code to receive close
155 * Revision 1.24 1995/06/16 10:31:39 quinn
156 * Added session timeout.
158 * Revision 1.23 1995/06/15 12:30:48 quinn
161 * Revision 1.22 1995/06/15 07:45:17 quinn
164 * Revision 1.21 1995/06/06 08:15:40 quinn
167 * Revision 1.20 1995/05/29 08:12:09 quinn
170 * Revision 1.19 1995/05/16 09:37:27 quinn
173 * Revision 1.18 1995/05/16 08:51:09 quinn
174 * License, documentation, and memory fixes
176 * Revision 1.17 1995/05/15 11:56:42 quinn
177 * Asynchronous facilities. Restructuring of seshigh code.
179 * Revision 1.16 1995/04/10 10:23:40 quinn
180 * Some work to add scan and other things.
182 * Revision 1.15 1995/03/31 10:16:51 quinn
185 * Revision 1.14 1995/03/31 09:18:58 quinn
188 * Revision 1.13 1995/03/30 16:08:39 quinn
191 * Revision 1.12 1995/03/30 13:29:02 quinn
194 * Revision 1.11 1995/03/30 12:18:17 quinn
197 * Revision 1.10 1995/03/29 15:40:16 quinn
198 * Ongoing work. Statserv is now dynamic by default
200 * Revision 1.9 1995/03/27 08:34:30 quinn
201 * Added dynamic server functionality.
202 * Released bindings to session.c (is now redundant)
204 * Revision 1.8 1995/03/20 09:46:26 quinn
207 * Revision 1.7 1995/03/16 13:29:04 quinn
208 * Partitioned server.
210 * Revision 1.6 1995/03/15 15:18:52 quinn
211 * Little changes to better support nonblocking I/O
214 * Revision 1.5 1995/03/15 08:37:45 quinn
215 * Now we're pretty much set for nonblocking I/O.
217 * Revision 1.4 1995/03/14 16:59:48 quinn
220 * Revision 1.3 1995/03/14 11:30:15 quinn
223 * Revision 1.2 1995/03/14 10:28:03 quinn
224 * More work on demo server.
226 * Revision 1.1 1995/03/10 18:22:45 quinn
227 * The rudiments of an asynchronous server.
249 #include <yaz/comstack.h>
250 #include <yaz/tcpip.h>
251 #include <yaz/options.h>
253 #include <yaz/xmosi.h>
258 #include <yaz/statserv.h>
260 static IOCHAN pListener = NULL;
262 static char *me = "statserver";
266 int check_options(int argc, char **argv);
267 statserv_options_block control_block = {
268 1, /* dynamic mode */
269 0, /* threaded mode */
270 0, /* one shot (single session) */
271 LOG_DEFAULT_LEVEL, /* log level */
273 "", /* diagnostic output to stderr */
274 "tcp:@:9999", /* default listener port */
275 PROTO_Z3950, /* default application protocol */
276 60, /* idle timeout (minutes) */
277 1024*1024, /* maximum PDU size (approx.) to allow */
278 "default-config", /* configuration name to pass to backend */
279 "", /* set user id */
280 0, /* bend_start handler */
281 0, /* bend_stop handler */
282 check_options, /* Default routine, for checking the run-time arguments */
285 0, /* default value for inet deamon */
286 0, /* handle (for service, etc) */
287 0, /* bend_init handle */
288 0 /* bend_close handle */
290 ,"Z39.50 Server", /* NT Service Name */
291 "Server", /* NT application Name */
292 "", /* NT Service Dependencies */
293 "Z39.50 Server" /* NT Service Display Name */
298 * handle incoming connect requests.
299 * The dynamic mode is a bit tricky mostly because we want to avoid
300 * doing all of the listening and accepting in the parent - it's
305 typedef struct _ThreadList ThreadList;
314 static ThreadList *pFirstThread;
315 static CRITICAL_SECTION Thread_CritSect;
316 static BOOL bInitialized = FALSE;
318 static void ThreadList_Initialize()
320 /* Initialize the critical Sections */
321 InitializeCriticalSection(&Thread_CritSect);
323 /* Set the first thraed */
326 /* we have been initialized */
330 static void statserv_add(HANDLE hThread, IOCHAN pIOChannel)
332 /* Only one thread can go through this section at a time */
333 EnterCriticalSection(&Thread_CritSect);
336 /* Lets create our new object */
337 ThreadList *pNewThread = (ThreadList *)malloc(sizeof(ThreadList));
338 pNewThread->hThread = hThread;
339 pNewThread->pIOChannel = pIOChannel;
340 pNewThread->pNext = pFirstThread;
341 pFirstThread = pNewThread;
343 /* Lets let somebody else create a new object now */
344 LeaveCriticalSection(&Thread_CritSect);
348 void statserv_remove(IOCHAN pIOChannel)
350 /* Only one thread can go through this section at a time */
351 EnterCriticalSection(&Thread_CritSect);
354 ThreadList *pCurrentThread = pFirstThread;
355 ThreadList *pNextThread;
356 ThreadList *pPrevThread =NULL;
358 /* Step through alll the threads */
359 for (; pCurrentThread != NULL; pCurrentThread = pNextThread)
361 /* We only need to compare on the IO Channel */
362 if (pCurrentThread->pIOChannel == pIOChannel)
364 /* We have found the thread we want to delete */
365 /* First of all reset the next pointers */
366 if (pPrevThread == NULL)
367 pFirstThread = pCurrentThread->pNext;
369 pPrevThread->pNext = pCurrentThread->pNext;
371 /* All we need todo now is delete the memory */
372 free(pCurrentThread);
374 /* No need to look at any more threads */
379 /* We need to look at another thread */
380 pNextThread = pCurrentThread->pNext;
381 pPrevThread = pCurrentThread;
385 /* Lets let somebody else remove an object now */
386 LeaveCriticalSection(&Thread_CritSect);
390 void statserv_closedown()
392 /* Shouldn't do anything if we are not initialized */
396 HANDLE *pThreadHandles = NULL;
398 /* We need to stop threads adding and removing while we */
399 /* start the closedown process */
400 EnterCriticalSection(&Thread_CritSect);
403 /* We have exclusive access to the thread stuff now */
404 /* Y didn't i use a semaphore - Oh well never mind */
405 ThreadList *pCurrentThread = pFirstThread;
407 /* Before we do anything else, we need to shutdown the listener */
408 if (pListener != NULL)
409 iochan_destroy(pListener);
411 for (; pCurrentThread != NULL; pCurrentThread = pCurrentThread->pNext)
413 /* Just destroy the IOCHAN, that should do the trick */
414 iochan_destroy(pCurrentThread->pIOChannel);
416 /* Keep a running count of our handles */
422 HANDLE *pCurrentHandle ;
424 /* Allocate the thread handle array */
425 pThreadHandles = (HANDLE *)malloc(sizeof(HANDLE) * iHandles);
426 pCurrentHandle = pThreadHandles;
428 for (pCurrentThread = pFirstThread;
429 pCurrentThread != NULL;
430 pCurrentThread = pCurrentThread->pNext, pCurrentHandle++)
432 /* Just the handle */
433 *pCurrentHandle = pCurrentThread->hThread;
437 /* We can now leave the critical section */
438 LeaveCriticalSection(&Thread_CritSect);
441 /* Now we can really do something */
444 /* This will now wait, until all the threads close */
445 WaitForMultipleObjects(iHandles, pThreadHandles, TRUE, INFINITE);
447 /* Free the memory we allocated for the handle array */
448 free(pThreadHandles);
451 if (control_block.bend_stop)
452 (*control_block.bend_stop)(&control_block);
453 /* No longer require the critical section, since all threads are dead */
454 DeleteCriticalSection(&Thread_CritSect);
458 void event_loop_thread (IOCHAN iochan)
460 event_loop (&iochan);
463 static void listener(IOCHAN h, int event)
465 COMSTACK line = (COMSTACK) iochan_getdata(h);
470 if (event == EVENT_INPUT)
472 if ((res = cs_listen(line, 0, 0)) < 0)
474 yaz_log(LOG_FATAL, "cs_listen failed");
479 yaz_log(LOG_DEBUG, "listen ok");
480 iochan_setevent(h, EVENT_OUTPUT);
481 iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */
483 else if (event == EVENT_OUTPUT)
489 if (!(new_line = cs_accept(line)))
491 yaz_log(LOG_FATAL, "Accept failed.");
492 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
495 yaz_log(LOG_DEBUG, "Accept ok");
497 if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session,
500 yaz_log(LOG_FATAL, "Failed to create iochan");
505 yaz_log(LOG_DEBUG, "Creating association");
506 if (!(newas = create_association(new_chan, new_line)))
508 yaz_log(LOG_FATAL, "Failed to create new assoc.");
512 yaz_log(LOG_DEBUG, "Setting timeout %d", control_block.idle_timeout);
513 iochan_setdata(new_chan, newas);
514 iochan_settimeout(new_chan, control_block.idle_timeout * 60);
516 /* Now what we need todo is create a new thread with this iochan as
518 newHandle = (HANDLE) _beginthread(event_loop_thread, 0, new_chan);
519 if (newHandle == (HANDLE) -1)
522 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create new thread.");
526 /* We successfully created the thread, so add it to the list */
527 statserv_add(newHandle, new_chan);
529 yaz_log(LOG_DEBUG, "Created new thread, id = %ld iochan %p",(long) newHandle, new_chan);
530 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
534 yaz_log(LOG_FATAL, "Bad event on listener.");
542 /* To save having an #ifdef in event_loop we need to define this empty function */
543 void statserv_remove(IOCHAN pIOChannel)
547 void statserv_closedown()
551 if (control_block.bend_stop)
552 (*control_block.bend_stop)(&control_block);
554 for (p = pListener; p; p = p->next)
558 void sigterm(int sig)
560 statserv_closedown();
564 static void *new_session (void *vp);
566 static void listener(IOCHAN h, int event)
568 COMSTACK line = (COMSTACK) iochan_getdata(h);
570 static int child = 0;
573 if (event == EVENT_INPUT)
575 if (control_block.dynamic && !child)
581 yaz_log(LOG_FATAL|LOG_ERRNO, "pipe");
585 if ((res = fork()) < 0)
587 yaz_log(LOG_FATAL|LOG_ERRNO, "fork");
591 else if (res == 0) /* child */
598 for (pp = pListener; pp; pp = iochan_getnext(pp))
602 COMSTACK l = (COMSTACK)iochan_getdata(pp);
607 sprintf(nbuf, "%s(%d)", me, getpid());
608 yaz_log_init(control_block.loglevel, nbuf, 0);
613 /* wait for child to take the call */
619 if ((res = read(hand[0], dummy, 1)) < 0 && errno != EINTR)
621 yaz_log(LOG_FATAL|LOG_ERRNO, "handshake read");
627 yaz_log(LOG_DEBUG, "P: Child has taken the call");
632 if ((res = cs_listen_check(line, 0, 0, control_block.check_ip,
633 control_block.daemon_name)) < 0)
635 yaz_log(LOG_WARN, "cs_listen failed");
640 yaz_log(LOG_DEBUG, "listen ok");
641 iochan_setevent(h, EVENT_OUTPUT);
642 iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */
644 /* in dynamic mode, only the child ever comes down here */
645 else if (event == EVENT_OUTPUT)
649 if (!(new_line = cs_accept(line)))
651 yaz_log(LOG_FATAL, "Accept failed.");
652 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
655 yaz_log(LOG_DEBUG, "accept ok");
656 if (control_block.dynamic)
659 /* close our half of the listener socket */
660 for (pp = pListener; pp; pp = iochan_getnext(pp))
662 COMSTACK l = (COMSTACK)iochan_getdata(pp);
667 yaz_log(LOG_DEBUG, "Releasing parent");
671 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
674 if (control_block.threads)
676 pthread_t child_thread;
677 pthread_create (&child_thread, 0, new_session, new_line);
678 pthread_detach (child_thread);
681 new_session(new_line);
683 new_session(new_line);
688 yaz_log(LOG_FATAL, "Bad event on listener.");
694 static void *new_session (void *vp)
699 COMSTACK new_line = (COMSTACK) vp;
700 if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session,
703 yaz_log(LOG_FATAL, "Failed to create iochan");
706 if (!(newas = create_association(new_chan, new_line)))
708 yaz_log(LOG_FATAL, "Failed to create new assoc.");
711 iochan_setdata(new_chan, newas);
712 iochan_settimeout(new_chan, control_block.idle_timeout * 60);
713 a = cs_addrstr(new_line);
714 yaz_log(LOG_LOG, "Accepted connection from %s", a ? a : "[Unknown]");
715 if (control_block.threads)
717 event_loop(&new_chan);
721 new_chan->next = pListener;
722 pListener = new_chan;
729 static void inetd_connection(int what)
736 if ((line = cs_createbysocket(0, tcpip_type, 0, what)))
738 if ((chan = iochan_create(cs_fileno(line), ir_session, EVENT_INPUT)))
740 if ((assoc = create_association(chan, line)))
742 iochan_setdata(chan, assoc);
743 iochan_settimeout(chan, control_block.idle_timeout * 60);
744 addr = cs_addrstr(line);
745 yaz_log(LOG_LOG, "Inetd association from %s", addr ? addr : "[UNKNOWN]");
749 yaz_log(LOG_FATAL, "Failed to create association structure");
751 chan->next = pListener;
756 yaz_log(LOG_FATAL, "Failed to create iochan");
761 yaz_log(LOG_ERRNO|LOG_FATAL, "Failed to create comstack on socket 0");
766 * Set up a listening endpoint, and give it to the event-handler.
768 static void add_listener(char *where, int what)
772 char mode[100], addr[100];
776 if (!where || sscanf(where, "%[^:]:%s", mode, addr) != 2)
778 yaz_log (LOG_WARN, "%s: Address format: ('tcp'|'osi')':'<address>", me);
781 if (!strcmp(mode, "tcp"))
783 else if (!strcmp(mode, "osi"))
788 yaz_log (LOG_WARN, "OSI Transport not allowed by configuration.");
794 yaz_log (LOG_WARN, "You must specify either 'osi:' or 'tcp:'");
797 yaz_log(LOG_LOG, "Adding %s %s listener on %s",
798 control_block.dynamic ? "dynamic" :
799 (control_block.threads ? "threaded" : "static"),
800 what == PROTO_SR ? "SR" : "Z3950", where);
801 if (!(l = cs_create(type, 0, what)))
803 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create listener");
806 ap = cs_straddr (l, addr);
809 fprintf(stderr, "Address resolution failed.\n");
813 if (cs_bind(l, ap, CS_SERVER) < 0)
815 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to bind to %s", where);
819 if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT |
822 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create IOCHAN-type");
826 iochan_setdata(lst, l);
828 /* Ensure our listener chain is setup properly */
829 lst->next = pListener;
834 /* For windows we don't need to catch the signals */
835 static void catchchld(int num)
837 while (waitpid(-1, 0, WNOHANG) > 0)
839 signal(SIGCHLD, catchchld);
843 statserv_options_block *statserv_getcontrol(void)
845 static statserv_options_block cb;
847 memcpy(&cb, &control_block, sizeof(cb));
851 void statserv_setcontrol(statserv_options_block *block)
853 memcpy(&control_block, block, sizeof(*block));
856 int statserv_start(int argc, char **argv)
862 /* We need to initialize the thread list */
863 ThreadList_Initialize();
867 if ((me = strrchr (argv[0], '\\')))
874 if (control_block.options_func(argc, argv))
877 if (control_block.bend_start)
878 (*control_block.bend_start)(&control_block);
880 logf (LOG_LOG, "Starting server %s", me);
882 if (control_block.inetd)
883 inetd_connection(control_block.default_proto);
886 logf (LOG_LOG, "Starting server %s pid=%d", me, getpid());
888 sigset_t sigs_to_block;
890 sigemptyset(&sigs_to_block);
891 sigaddset (&sigs_to_block, SIGTERM);
892 pthread_sigmask (SIG_BLOCK, &sigs_to_block, 0);
897 if (control_block.dynamic)
898 signal(SIGCHLD, catchchld);
901 signal (SIGTERM, sigterm);
902 if (*control_block.setuid)
906 if (!(pw = getpwnam(control_block.setuid)))
908 yaz_log(LOG_FATAL, "%s: Unknown user", control_block.setuid);
911 if (setuid(pw->pw_uid) < 0)
913 yaz_log(LOG_FATAL|LOG_ERRNO, "setuid");
919 if ((pListener == NULL) && *control_block.default_listen)
920 add_listener(control_block.default_listen,
921 control_block.default_proto);
923 if (pListener == NULL)
927 yaz_log(LOG_LOG, "Entering event loop.");
928 ret = event_loop(&pListener);
934 int check_options(int argc, char **argv)
939 while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:", argv, argc, &arg)) != -2)
944 add_listener(arg, control_block.default_proto);
947 control_block.one_shot = 1;
948 control_block.dynamic = 0;
951 control_block.default_proto = PROTO_Z3950;
954 control_block.default_proto = PROTO_SR;
957 control_block.dynamic = 0;
961 control_block.dynamic = 0;
962 control_block.threads = 1;
964 fprintf(stderr, "%s: Threaded mode not available.\n", me);
969 strcpy(control_block.logfile, arg ? arg : "");
970 yaz_log_init(control_block.loglevel, me, control_block.logfile);
973 control_block.loglevel = yaz_log_mask_str(arg);
974 yaz_log_init(control_block.loglevel, me, control_block.logfile);
977 strcpy(control_block.apdufile, arg ? arg : "");
980 strcpy(control_block.setuid, arg ? arg : "");
983 strcpy(control_block.configname, arg ? arg : "");
986 strcpy(control_block.daemon_name, arg ? arg : "");
989 if (!arg || !(r = atoi(arg)))
991 fprintf(stderr, "%s: Specify positive timeout for -t.\n", me);
994 control_block.idle_timeout = r;
997 if (!arg || !(r = atoi(arg)))
999 fprintf(stderr, "%s: Specify positive size for -k.\n", me);
1002 control_block.maxrecordsize = r * 1024;
1005 control_block.inetd = 1;
1015 fprintf(stderr, "Usage: %s [ -a <pdufile> -v <loglevel>"
1016 " -l <logfile> -u <user> -c <config> -t <minutes>"
1017 " -k <kilobytes> -d <daemon>"
1018 " -zsiST -w <directory> <listender-addr>... ]\n", me);
1026 typedef struct _Args
1032 static Args ArgDetails;
1034 /* name of the executable */
1035 #define SZAPPNAME "server"
1037 /* list of service dependencies - "dep1\0dep2\0\0" */
1038 #define SZDEPENDENCIES ""
1040 int statserv_main(int argc, char **argv,
1041 bend_initresult *(*bend_init)(bend_initrequest *r),
1042 void (*bend_close)(void *handle))
1044 statserv_options_block *cb = statserv_getcontrol();
1046 cb->bend_init = bend_init;
1047 cb->bend_close = bend_close;
1049 statserv_setcontrol(cb);
1051 /* Lets setup the Arg structure */
1052 ArgDetails.argc = argc;
1053 ArgDetails.argv = argv;
1055 /* Now setup the service with the service controller */
1056 SetupService(argc, argv, &ArgDetails, SZAPPNAME,
1057 cb->service_name, /* internal service name */
1058 cb->service_name, /* displayed name of the service */
1063 int StartAppService(void *pHandle, int argc, char **argv)
1065 /* Initializes the App */
1069 void RunAppService(void *pHandle)
1071 Args *pArgs = (Args *)pHandle;
1073 /* Starts the app running */
1074 statserv_start(pArgs->argc, pArgs->argv);
1077 void StopAppService(void *pHandle)
1080 statserv_closedown();
1083 int statserv_main(int argc, char **argv,
1084 bend_initresult *(*bend_init)(bend_initrequest *r),
1085 void (*bend_close)(void *handle))
1088 statserv_options_block *cb = statserv_getcontrol();
1090 cb->bend_init = bend_init;
1091 cb->bend_close = bend_close;
1093 statserv_setcontrol(cb);
1094 ret = statserv_start (argc, argv);
1095 statserv_closedown ();