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.64 2000-04-05 07:39:55 adam
11 * Added shared library support (libtool).
13 * Revision 1.63 2000/03/20 19:06:25 adam
14 * Added Segment request for fronend server. Work on admin for client.
16 * Revision 1.62 2000/03/17 12:47:02 adam
17 * Minor changes to admin client.
19 * Revision 1.61 2000/03/15 12:59:49 adam
20 * Added handle member to statserv_control.
22 * Revision 1.60 2000/03/14 09:06:11 adam
23 * Added POSIX threads support for frontend server.
25 * Revision 1.59 1999/11/30 13:47:12 adam
26 * Improved installation. Moved header files to include/yaz.
28 * Revision 1.58 1999/08/27 09:40:32 adam
29 * Renamed logf function to yaz_log. Removed VC++ project files.
31 * Revision 1.57 1999/07/06 12:17:15 adam
32 * Added option -1 that runs server once (for profiling purposes).
34 * Revision 1.56 1999/06/10 11:45:30 adam
35 * Added bend_start, bend_stop handlers and removed pre_init.
36 * Handlers bend_start/bend_stop are called when service/daemon is
39 * Revision 1.55 1999/06/10 09:18:54 adam
40 * Modified so that pre_init is called when service/server is started.
42 * Revision 1.54 1999/04/16 14:45:55 adam
43 * Added interface for tcpd wrapper for access control.
45 * Revision 1.53 1999/02/02 13:57:39 adam
46 * Uses preprocessor define WIN32 instead of WINDOWS to build code
47 * for Microsoft WIN32.
49 * Revision 1.52 1998/08/21 14:13:34 adam
50 * Added GNU Configure script to build Makefiles.
52 * Revision 1.51 1998/07/07 15:51:03 adam
53 * Changed server so that it stops if bind fails - "address already in
54 * use" typically causes this.
56 * Revision 1.50 1998/06/22 11:32:39 adam
57 * Added 'conditional cs_listen' feature.
59 * Revision 1.49 1998/02/27 14:04:55 adam
60 * Fixed bug in statserv_remove.
62 * Revision 1.48 1998/02/11 11:53:36 adam
63 * Changed code so that it compiles as C++.
65 * Revision 1.47 1998/02/10 10:28:57 adam
66 * Added app_name, service_dependencies, service_display_name and
67 * options_func. options_func allows us to specify a different function
68 * to interogate the command line arguments. The other members allow us
69 * to pass the full service details accross to the service manager (CW).
72 * Revision 1.46 1998/01/30 15:24:57 adam
73 * Fixed bug in inetd code. The server listened on tcp:@:9999 even
74 * though it was started in inetd mode.
76 * Revision 1.45 1998/01/29 13:30:23 adam
77 * Better event handle system for NT/Unix.
79 * Revision 1.44 1997/11/07 13:31:52 adam
80 * Added NT Service name part of statserv_options_block. Moved NT
81 * service utility to server library.
83 * Revision 1.43 1997/10/31 12:20:09 adam
84 * Improved memory debugging for xmalloc/nmem.c. References to NMEM
85 * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
86 * Bug fix: missing fclose in data1_read_espec1.
88 * Revision 1.42 1997/10/27 14:03:02 adam
89 * Added new member to statserver_options_block, pre_init, which
90 * specifies a callback to be invoked after command line parsing and
91 * before the server listens for the first time.
93 * Revision 1.41 1997/09/29 07:19:32 adam
94 * Server library uses nmem_init/nmem_exit. The log prefix no longer
95 * includes leading path on NT.
97 * Revision 1.40 1997/09/17 12:10:41 adam
100 * Revision 1.39 1997/09/09 10:10:19 adam
101 * Another MSV5.0 port. Changed projects to include proper
102 * library/include paths.
103 * Server starts server in test-mode when no options are given.
105 * Revision 1.38 1997/09/04 14:19:14 adam
108 * Revision 1.37 1997/09/01 08:53:01 adam
109 * New windows NT/95 port using MSV5.0. The test server 'ztest' was
110 * moved a separate directory. MSV5.0 project server.dsp created.
111 * As an option, the server can now operate as an NT service.
113 * Revision 1.36 1996/07/06 19:58:36 quinn
114 * System headerfiles gathered in yconfig
116 * Revision 1.35 1996/05/29 10:03:28 quinn
119 * Revision 1.34 1996/02/21 13:12:07 quinn
120 * *** empty log message ***
122 * Revision 1.33 1996/02/10 12:23:49 quinn
123 * Enable inetd operations fro TCP/IP stack
125 * Revision 1.32 1996/01/19 15:41:52 quinn
126 * *** empty log message ***
128 * Revision 1.31 1995/11/17 11:09:39 adam
129 * Added new option '-c' to specify configuration name in control block.
131 * Revision 1.30 1995/11/01 13:54:59 quinn
134 * Revision 1.29 1995/10/30 12:41:29 quinn
135 * Added hostname lookup for server.
137 * Revision 1.28 1995/09/29 17:12:30 quinn
140 * Revision 1.27 1995/09/27 15:03:02 quinn
141 * Modified function heads & prototypes.
143 * Revision 1.26 1995/08/29 14:44:51 quinn
146 * Revision 1.25 1995/08/29 11:18:02 quinn
147 * Added code to receive close
149 * Revision 1.24 1995/06/16 10:31:39 quinn
150 * Added session timeout.
152 * Revision 1.23 1995/06/15 12:30:48 quinn
155 * Revision 1.22 1995/06/15 07:45:17 quinn
158 * Revision 1.21 1995/06/06 08:15:40 quinn
161 * Revision 1.20 1995/05/29 08:12:09 quinn
164 * Revision 1.19 1995/05/16 09:37:27 quinn
167 * Revision 1.18 1995/05/16 08:51:09 quinn
168 * License, documentation, and memory fixes
170 * Revision 1.17 1995/05/15 11:56:42 quinn
171 * Asynchronous facilities. Restructuring of seshigh code.
173 * Revision 1.16 1995/04/10 10:23:40 quinn
174 * Some work to add scan and other things.
176 * Revision 1.15 1995/03/31 10:16:51 quinn
179 * Revision 1.14 1995/03/31 09:18:58 quinn
182 * Revision 1.13 1995/03/30 16:08:39 quinn
185 * Revision 1.12 1995/03/30 13:29:02 quinn
188 * Revision 1.11 1995/03/30 12:18:17 quinn
191 * Revision 1.10 1995/03/29 15:40:16 quinn
192 * Ongoing work. Statserv is now dynamic by default
194 * Revision 1.9 1995/03/27 08:34:30 quinn
195 * Added dynamic server functionality.
196 * Released bindings to session.c (is now redundant)
198 * Revision 1.8 1995/03/20 09:46:26 quinn
201 * Revision 1.7 1995/03/16 13:29:04 quinn
202 * Partitioned server.
204 * Revision 1.6 1995/03/15 15:18:52 quinn
205 * Little changes to better support nonblocking I/O
208 * Revision 1.5 1995/03/15 08:37:45 quinn
209 * Now we're pretty much set for nonblocking I/O.
211 * Revision 1.4 1995/03/14 16:59:48 quinn
214 * Revision 1.3 1995/03/14 11:30:15 quinn
217 * Revision 1.2 1995/03/14 10:28:03 quinn
218 * More work on demo server.
220 * Revision 1.1 1995/03/10 18:22:45 quinn
221 * The rudiments of an asynchronous server.
243 #include <yaz/comstack.h>
244 #include <yaz/tcpip.h>
245 #include <yaz/options.h>
247 #include <yaz/xmosi.h>
252 #include <yaz/statserv.h>
254 static IOCHAN pListener = NULL;
256 static char *me = "statserver";
260 int check_options(int argc, char **argv);
261 statserv_options_block control_block = {
262 1, /* dynamic mode */
263 0, /* threaded mode */
264 0, /* one shot (single session) */
265 LOG_DEFAULT_LEVEL, /* log level */
267 "", /* diagnostic output to stderr */
268 "tcp:@:9999", /* default listener port */
269 PROTO_Z3950, /* default application protocol */
270 60, /* idle timeout (minutes) */
271 1024*1024, /* maximum PDU size (approx.) to allow */
272 "default-config", /* configuration name to pass to backend */
273 "", /* set user id */
274 0, /* bend_start handler */
275 0, /* bend_stop handler */
276 check_options, /* Default routine, for checking the run-time arguments */
279 0, /* default value for inet deamon */
280 0, /* handle (for service, etc) */
281 0, /* bend_init handle */
282 0 /* bend_close handle */
284 ,"Z39.50 Server", /* NT Service Name */
285 "Server", /* NT application Name */
286 "", /* NT Service Dependencies */
287 "Z39.50 Server" /* NT Service Display Name */
292 * handle incoming connect requests.
293 * The dynamic mode is a bit tricky mostly because we want to avoid
294 * doing all of the listening and accepting in the parent - it's
299 typedef struct _ThreadList ThreadList;
308 static ThreadList *pFirstThread;
309 static CRITICAL_SECTION Thread_CritSect;
310 static BOOL bInitialized = FALSE;
312 static void ThreadList_Initialize()
314 /* Initialize the critical Sections */
315 InitializeCriticalSection(&Thread_CritSect);
317 /* Set the first thraed */
320 /* we have been initialized */
324 static void statserv_add(HANDLE hThread, IOCHAN pIOChannel)
326 /* Only one thread can go through this section at a time */
327 EnterCriticalSection(&Thread_CritSect);
330 /* Lets create our new object */
331 ThreadList *pNewThread = (ThreadList *)malloc(sizeof(ThreadList));
332 pNewThread->hThread = hThread;
333 pNewThread->pIOChannel = pIOChannel;
334 pNewThread->pNext = pFirstThread;
335 pFirstThread = pNewThread;
337 /* Lets let somebody else create a new object now */
338 LeaveCriticalSection(&Thread_CritSect);
342 void statserv_remove(IOCHAN pIOChannel)
344 /* Only one thread can go through this section at a time */
345 EnterCriticalSection(&Thread_CritSect);
348 ThreadList *pCurrentThread = pFirstThread;
349 ThreadList *pNextThread;
350 ThreadList *pPrevThread =NULL;
352 /* Step through alll the threads */
353 for (; pCurrentThread != NULL; pCurrentThread = pNextThread)
355 /* We only need to compare on the IO Channel */
356 if (pCurrentThread->pIOChannel == pIOChannel)
358 /* We have found the thread we want to delete */
359 /* First of all reset the next pointers */
360 if (pPrevThread == NULL)
361 pFirstThread = pCurrentThread->pNext;
363 pPrevThread->pNext = pCurrentThread->pNext;
365 /* All we need todo now is delete the memory */
366 free(pCurrentThread);
368 /* No need to look at any more threads */
373 /* We need to look at another thread */
374 pNextThread = pCurrentThread->pNext;
375 pPrevThread = pCurrentThread;
379 /* Lets let somebody else remove an object now */
380 LeaveCriticalSection(&Thread_CritSect);
384 void statserv_closedown()
386 /* Shouldn't do anything if we are not initialized */
390 HANDLE *pThreadHandles = NULL;
392 /* We need to stop threads adding and removing while we */
393 /* start the closedown process */
394 EnterCriticalSection(&Thread_CritSect);
397 /* We have exclusive access to the thread stuff now */
398 /* Y didn't i use a semaphore - Oh well never mind */
399 ThreadList *pCurrentThread = pFirstThread;
401 /* Before we do anything else, we need to shutdown the listener */
402 if (pListener != NULL)
403 iochan_destroy(pListener);
405 for (; pCurrentThread != NULL; pCurrentThread = pCurrentThread->pNext)
407 /* Just destroy the IOCHAN, that should do the trick */
408 iochan_destroy(pCurrentThread->pIOChannel);
410 /* Keep a running count of our handles */
416 HANDLE *pCurrentHandle ;
418 /* Allocate the thread handle array */
419 pThreadHandles = (HANDLE *)malloc(sizeof(HANDLE) * iHandles);
420 pCurrentHandle = pThreadHandles;
422 for (pCurrentThread = pFirstThread;
423 pCurrentThread != NULL;
424 pCurrentThread = pCurrentThread->pNext, pCurrentHandle++)
426 /* Just the handle */
427 *pCurrentHandle = pCurrentThread->hThread;
431 /* We can now leave the critical section */
432 LeaveCriticalSection(&Thread_CritSect);
435 /* Now we can really do something */
438 /* This will now wait, until all the threads close */
439 WaitForMultipleObjects(iHandles, pThreadHandles, TRUE, INFINITE);
441 /* Free the memory we allocated for the handle array */
442 free(pThreadHandles);
445 if (control_block.bend_stop)
446 (*control_block.bend_stop)(&control_block);
447 /* No longer require the critical section, since all threads are dead */
448 DeleteCriticalSection(&Thread_CritSect);
452 int __stdcall event_loop_thread (IOCHAN iochan)
454 return event_loop (&iochan);
457 static void listener(IOCHAN h, int event)
459 COMSTACK line = (COMSTACK) iochan_getdata(h);
464 if (event == EVENT_INPUT)
466 if ((res = cs_listen(line, 0, 0)) < 0)
468 yaz_log(LOG_FATAL, "cs_listen failed");
473 yaz_log(LOG_DEBUG, "listen ok");
474 iochan_setevent(h, EVENT_OUTPUT);
475 iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */
477 else if (event == EVENT_OUTPUT)
484 if (!(new_line = cs_accept(line)))
486 yaz_log(LOG_FATAL, "Accept failed.");
487 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
490 yaz_log(LOG_DEBUG, "Accept ok");
492 if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session,
495 yaz_log(LOG_FATAL, "Failed to create iochan");
500 yaz_log(LOG_DEBUG, "Creating association");
501 if (!(newas = create_association(new_chan, new_line)))
503 yaz_log(LOG_FATAL, "Failed to create new assoc.");
507 yaz_log(LOG_DEBUG, "Setting timeout %d", control_block.idle_timeout);
508 iochan_setdata(new_chan, newas);
509 iochan_settimeout(new_chan, control_block.idle_timeout * 60);
511 yaz_log(LOG_DEBUG, "Determining client address");
512 a = cs_addrstr(new_line);
513 yaz_log(LOG_LOG, "Accepted connection from %s", a ? a : "[Unknown]");
515 /* Now what we need todo is create a new thread with this iochan as
517 /* if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)event_loop_thread,
518 new_chan, 0, &ThreadId) == NULL) */
519 /* Somehow, somewhere we need to store this thread id, otherwise we
520 won't be able to close cleanly */
521 NewHandle = (HANDLE)_beginthreadex(NULL, 0, event_loop_thread,
522 new_chan, 0, &ThreadId);
523 if (NewHandle == (HANDLE)-1)
526 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create new thread.");
530 /* We successfully created the thread, so add it to the list */
531 statserv_add(NewHandle, new_chan);
533 yaz_log(LOG_DEBUG, "Created new thread, iochan %p", new_chan);
534 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
538 yaz_log(LOG_FATAL, "Bad event on listener.");
546 /* To save having an #ifdef in event_loop we need to define this empty function */
547 void statserv_remove(IOCHAN pIOChannel)
551 void statserv_closedown()
555 if (control_block.bend_stop)
556 (*control_block.bend_stop)(&control_block);
558 for (p = pListener; p; p = p->next)
562 void sigterm(int sig)
564 statserv_closedown();
568 static void *new_session (void *vp);
570 static void listener(IOCHAN h, int event)
572 COMSTACK line = (COMSTACK) iochan_getdata(h);
574 static int child = 0;
577 if (event == EVENT_INPUT)
579 if (control_block.dynamic && !child)
585 yaz_log(LOG_FATAL|LOG_ERRNO, "pipe");
589 if ((res = fork()) < 0)
591 yaz_log(LOG_FATAL|LOG_ERRNO, "fork");
595 else if (res == 0) /* child */
602 for (pp = pListener; pp; pp = iochan_getnext(pp))
606 COMSTACK l = (COMSTACK)iochan_getdata(pp);
611 sprintf(nbuf, "%s(%d)", me, getpid());
612 log_init(control_block.loglevel, nbuf, 0);
617 /* wait for child to take the call */
623 if ((res = read(hand[0], dummy, 1)) < 0 && errno != EINTR)
625 yaz_log(LOG_FATAL|LOG_ERRNO, "handshake read");
631 yaz_log(LOG_DEBUG, "P: Child has taken the call");
636 if ((res = cs_listen_check(line, 0, 0, control_block.check_ip,
637 control_block.daemon_name)) < 0)
639 yaz_log(LOG_WARN, "cs_listen failed");
644 yaz_log(LOG_DEBUG, "listen ok");
645 iochan_setevent(h, EVENT_OUTPUT);
646 iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */
648 /* in dynamic mode, only the child ever comes down here */
649 else if (event == EVENT_OUTPUT)
653 if (!(new_line = cs_accept(line)))
655 yaz_log(LOG_FATAL, "Accept failed.");
656 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
659 yaz_log(LOG_DEBUG, "accept ok");
660 if (control_block.dynamic)
663 /* close our half of the listener socket */
664 for (pp = pListener; pp; pp = iochan_getnext(pp))
666 COMSTACK l = (COMSTACK)iochan_getdata(pp);
671 yaz_log(LOG_DEBUG, "Releasing parent");
675 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
678 if (control_block.threads)
680 pthread_t child_thread;
681 pthread_create (&child_thread, 0, new_session, new_line);
682 pthread_detach (child_thread);
685 new_session(new_line);
687 new_session(new_line);
692 yaz_log(LOG_FATAL, "Bad event on listener.");
698 static void *new_session (void *vp)
703 COMSTACK new_line = (COMSTACK) vp;
704 if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session,
707 yaz_log(LOG_FATAL, "Failed to create iochan");
710 if (!(newas = create_association(new_chan, new_line)))
712 yaz_log(LOG_FATAL, "Failed to create new assoc.");
715 iochan_setdata(new_chan, newas);
716 iochan_settimeout(new_chan, control_block.idle_timeout * 60);
717 a = cs_addrstr(new_line);
718 yaz_log(LOG_LOG, "Accepted connection from %s", a ? a : "[Unknown]");
719 if (control_block.threads)
721 event_loop(&new_chan);
725 new_chan->next = pListener;
726 pListener = new_chan;
733 static void inetd_connection(int what)
740 if ((line = cs_createbysocket(0, tcpip_type, 0, what)))
742 if ((chan = iochan_create(cs_fileno(line), ir_session, EVENT_INPUT)))
744 if ((assoc = create_association(chan, line)))
746 iochan_setdata(chan, assoc);
747 iochan_settimeout(chan, control_block.idle_timeout * 60);
748 addr = cs_addrstr(line);
749 yaz_log(LOG_LOG, "Inetd association from %s", addr ? addr : "[UNKNOWN]");
753 yaz_log(LOG_FATAL, "Failed to create association structure");
755 chan->next = pListener;
760 yaz_log(LOG_FATAL, "Failed to create iochan");
765 yaz_log(LOG_ERRNO|LOG_FATAL, "Failed to create comstack on socket 0");
770 * Set up a listening endpoint, and give it to the event-handler.
772 static void add_listener(char *where, int what)
776 char mode[100], addr[100];
780 if (!where || sscanf(where, "%[^:]:%s", mode, addr) != 2)
782 yaz_log (LOG_WARN, "%s: Address format: ('tcp'|'osi')':'<address>", me);
785 if (!strcmp(mode, "tcp"))
787 else if (!strcmp(mode, "osi"))
792 yaz_log (LOG_WARN, "OSI Transport not allowed by configuration.");
798 yaz_log (LOG_WARN, "You must specify either 'osi:' or 'tcp:'");
801 yaz_log(LOG_LOG, "Adding %s %s listener on %s",
802 control_block.dynamic ? "dynamic" :
803 (control_block.threads ? "threaded" : "static"),
804 what == PROTO_SR ? "SR" : "Z3950", where);
805 if (!(l = cs_create(type, 0, what)))
807 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create listener");
810 ap = cs_straddr (l, addr);
813 fprintf(stderr, "Address resolution failed.\n");
817 if (cs_bind(l, ap, CS_SERVER) < 0)
819 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to bind to %s", where);
823 if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT |
826 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create IOCHAN-type");
830 iochan_setdata(lst, l);
832 /* Ensure our listener chain is setup properly */
833 lst->next = pListener;
838 /* For windows we don't need to catch the signals */
839 static void catchchld(int num)
841 while (waitpid(-1, 0, WNOHANG) > 0)
843 signal(SIGCHLD, catchchld);
847 statserv_options_block *statserv_getcontrol(void)
849 static statserv_options_block cb;
851 memcpy(&cb, &control_block, sizeof(cb));
855 void statserv_setcontrol(statserv_options_block *block)
857 memcpy(&control_block, block, sizeof(*block));
860 int statserv_start(int argc, char **argv)
866 /* We need to initialize the thread list */
867 ThreadList_Initialize();
871 if ((me = strrchr (argv[0], '\\')))
878 if (control_block.options_func(argc, argv))
881 if (control_block.bend_start)
882 (*control_block.bend_start)(&control_block);
884 logf (LOG_LOG, "Starting server %s", me);
886 if (control_block.inetd)
887 inetd_connection(control_block.default_proto);
890 logf (LOG_LOG, "Starting server %s pid=%d", me, getpid());
892 sigset_t sigs_to_block;
894 sigemptyset(&sigs_to_block);
895 sigaddset (&sigs_to_block, SIGTERM);
896 pthread_sigmask (SIG_BLOCK, &sigs_to_block, 0);
901 if (control_block.dynamic)
902 signal(SIGCHLD, catchchld);
905 signal (SIGTERM, sigterm);
906 if (*control_block.setuid)
910 if (!(pw = getpwnam(control_block.setuid)))
912 yaz_log(LOG_FATAL, "%s: Unknown user", control_block.setuid);
915 if (setuid(pw->pw_uid) < 0)
917 yaz_log(LOG_FATAL|LOG_ERRNO, "setuid");
923 if ((pListener == NULL) && *control_block.default_listen)
924 add_listener(control_block.default_listen,
925 control_block.default_proto);
927 if (pListener == NULL)
931 yaz_log(LOG_LOG, "Entering event loop.");
932 ret = event_loop(&pListener);
938 int check_options(int argc, char **argv)
943 while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:", argv, argc, &arg)) != -2)
948 add_listener(arg, control_block.default_proto);
951 control_block.one_shot = 1;
952 control_block.dynamic = 0;
955 control_block.default_proto = PROTO_Z3950;
958 control_block.default_proto = PROTO_SR;
961 control_block.dynamic = 0;
965 control_block.dynamic = 0;
966 control_block.threads = 1;
968 fprintf(stderr, "%s: Threaded mode not available.\n", me);
973 strcpy(control_block.logfile, arg ? arg : "");
974 log_init(control_block.loglevel, me, control_block.logfile);
977 control_block.loglevel = log_mask_str(arg);
978 log_init(control_block.loglevel, me, control_block.logfile);
981 strcpy(control_block.apdufile, arg ? arg : "");
984 strcpy(control_block.setuid, arg ? arg : "");
987 strcpy(control_block.configname, arg ? arg : "");
990 strcpy(control_block.daemon_name, arg ? arg : "");
993 if (!arg || !(r = atoi(arg)))
995 fprintf(stderr, "%s: Specify positive timeout for -t.\n", me);
998 control_block.idle_timeout = r;
1001 if (!arg || !(r = atoi(arg)))
1003 fprintf(stderr, "%s: Specify positive size for -k.\n", me);
1006 control_block.maxrecordsize = r * 1024;
1009 control_block.inetd = 1;
1019 fprintf(stderr, "Usage: %s [ -a <pdufile> -v <loglevel>"
1020 " -l <logfile> -u <user> -c <config> -t <minutes>"
1021 " -k <kilobytes> -d <daemon>"
1022 " -zsiST -w <directory> <listender-addr>... ]\n", me);
1030 typedef struct _Args
1036 static Args ArgDetails;
1038 /* name of the executable */
1039 #define SZAPPNAME "server"
1041 /* list of service dependencies - "dep1\0dep2\0\0" */
1042 #define SZDEPENDENCIES ""
1044 int statserv_main(int argc, char **argv,
1045 bend_initresult *(*bend_init)(bend_initrequest *r),
1046 void (*bend_close)(void *handle))
1048 statserv_options_block *cb = statserv_getcontrol();
1050 cb->bend_init = bend_init;
1051 cb->bend_close = bend_close;
1053 statserv_setcontrol(cb);
1055 /* Lets setup the Arg structure */
1056 ArgDetails.argc = argc;
1057 ArgDetails.argv = argv;
1059 /* Now setup the service with the service controller */
1060 SetupService(argc, argv, &ArgDetails, SZAPPNAME,
1061 cb->service_name, /* internal service name */
1062 cb->service_name, /* displayed name of the service */
1067 int StartAppService(void *pHandle, int argc, char **argv)
1069 /* Initializes the App */
1073 void RunAppService(void *pHandle)
1075 Args *pArgs = (Args *)pHandle;
1077 /* Starts the app running */
1078 statserv_start(pArgs->argc, pArgs->argv);
1081 void StopAppService(void *pHandle)
1084 statserv_closedown();
1087 int statserv_main(int argc, char **argv,
1088 bend_initresult *(*bend_init)(bend_initrequest *r),
1089 void (*bend_close)(void *handle))
1092 statserv_options_block *cb = statserv_getcontrol();
1094 cb->bend_init = bend_init;
1095 cb->bend_close = bend_close;
1097 statserv_setcontrol(cb);
1098 ret = statserv_start (argc, argv);
1099 statserv_closedown ();