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.65 2000-09-04 08:58:15 adam
11 * Added prefix yaz_ for most logging utility functions.
13 * Revision 1.64 2000/04/05 07:39:55 adam
14 * Added shared library support (libtool).
16 * Revision 1.63 2000/03/20 19:06:25 adam
17 * Added Segment request for fronend server. Work on admin for client.
19 * Revision 1.62 2000/03/17 12:47:02 adam
20 * Minor changes to admin client.
22 * Revision 1.61 2000/03/15 12:59:49 adam
23 * Added handle member to statserv_control.
25 * Revision 1.60 2000/03/14 09:06:11 adam
26 * Added POSIX threads support for frontend server.
28 * Revision 1.59 1999/11/30 13:47:12 adam
29 * Improved installation. Moved header files to include/yaz.
31 * Revision 1.58 1999/08/27 09:40:32 adam
32 * Renamed logf function to yaz_log. Removed VC++ project files.
34 * Revision 1.57 1999/07/06 12:17:15 adam
35 * Added option -1 that runs server once (for profiling purposes).
37 * Revision 1.56 1999/06/10 11:45:30 adam
38 * Added bend_start, bend_stop handlers and removed pre_init.
39 * Handlers bend_start/bend_stop are called when service/daemon is
42 * Revision 1.55 1999/06/10 09:18:54 adam
43 * Modified so that pre_init is called when service/server is started.
45 * Revision 1.54 1999/04/16 14:45:55 adam
46 * Added interface for tcpd wrapper for access control.
48 * Revision 1.53 1999/02/02 13:57:39 adam
49 * Uses preprocessor define WIN32 instead of WINDOWS to build code
50 * for Microsoft WIN32.
52 * Revision 1.52 1998/08/21 14:13:34 adam
53 * Added GNU Configure script to build Makefiles.
55 * Revision 1.51 1998/07/07 15:51:03 adam
56 * Changed server so that it stops if bind fails - "address already in
57 * use" typically causes this.
59 * Revision 1.50 1998/06/22 11:32:39 adam
60 * Added 'conditional cs_listen' feature.
62 * Revision 1.49 1998/02/27 14:04:55 adam
63 * Fixed bug in statserv_remove.
65 * Revision 1.48 1998/02/11 11:53:36 adam
66 * Changed code so that it compiles as C++.
68 * Revision 1.47 1998/02/10 10:28:57 adam
69 * Added app_name, service_dependencies, service_display_name and
70 * options_func. options_func allows us to specify a different function
71 * to interogate the command line arguments. The other members allow us
72 * to pass the full service details accross to the service manager (CW).
75 * Revision 1.46 1998/01/30 15:24:57 adam
76 * Fixed bug in inetd code. The server listened on tcp:@:9999 even
77 * though it was started in inetd mode.
79 * Revision 1.45 1998/01/29 13:30:23 adam
80 * Better event handle system for NT/Unix.
82 * Revision 1.44 1997/11/07 13:31:52 adam
83 * Added NT Service name part of statserv_options_block. Moved NT
84 * service utility to server library.
86 * Revision 1.43 1997/10/31 12:20:09 adam
87 * Improved memory debugging for xmalloc/nmem.c. References to NMEM
88 * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
89 * Bug fix: missing fclose in data1_read_espec1.
91 * Revision 1.42 1997/10/27 14:03:02 adam
92 * Added new member to statserver_options_block, pre_init, which
93 * specifies a callback to be invoked after command line parsing and
94 * before the server listens for the first time.
96 * Revision 1.41 1997/09/29 07:19:32 adam
97 * Server library uses nmem_init/nmem_exit. The log prefix no longer
98 * includes leading path on NT.
100 * Revision 1.40 1997/09/17 12:10:41 adam
103 * Revision 1.39 1997/09/09 10:10:19 adam
104 * Another MSV5.0 port. Changed projects to include proper
105 * library/include paths.
106 * Server starts server in test-mode when no options are given.
108 * Revision 1.38 1997/09/04 14:19:14 adam
111 * Revision 1.37 1997/09/01 08:53:01 adam
112 * New windows NT/95 port using MSV5.0. The test server 'ztest' was
113 * moved a separate directory. MSV5.0 project server.dsp created.
114 * As an option, the server can now operate as an NT service.
116 * Revision 1.36 1996/07/06 19:58:36 quinn
117 * System headerfiles gathered in yconfig
119 * Revision 1.35 1996/05/29 10:03:28 quinn
122 * Revision 1.34 1996/02/21 13:12:07 quinn
123 * *** empty log message ***
125 * Revision 1.33 1996/02/10 12:23:49 quinn
126 * Enable inetd operations fro TCP/IP stack
128 * Revision 1.32 1996/01/19 15:41:52 quinn
129 * *** empty log message ***
131 * Revision 1.31 1995/11/17 11:09:39 adam
132 * Added new option '-c' to specify configuration name in control block.
134 * Revision 1.30 1995/11/01 13:54:59 quinn
137 * Revision 1.29 1995/10/30 12:41:29 quinn
138 * Added hostname lookup for server.
140 * Revision 1.28 1995/09/29 17:12:30 quinn
143 * Revision 1.27 1995/09/27 15:03:02 quinn
144 * Modified function heads & prototypes.
146 * Revision 1.26 1995/08/29 14:44:51 quinn
149 * Revision 1.25 1995/08/29 11:18:02 quinn
150 * Added code to receive close
152 * Revision 1.24 1995/06/16 10:31:39 quinn
153 * Added session timeout.
155 * Revision 1.23 1995/06/15 12:30:48 quinn
158 * Revision 1.22 1995/06/15 07:45:17 quinn
161 * Revision 1.21 1995/06/06 08:15:40 quinn
164 * Revision 1.20 1995/05/29 08:12:09 quinn
167 * Revision 1.19 1995/05/16 09:37:27 quinn
170 * Revision 1.18 1995/05/16 08:51:09 quinn
171 * License, documentation, and memory fixes
173 * Revision 1.17 1995/05/15 11:56:42 quinn
174 * Asynchronous facilities. Restructuring of seshigh code.
176 * Revision 1.16 1995/04/10 10:23:40 quinn
177 * Some work to add scan and other things.
179 * Revision 1.15 1995/03/31 10:16:51 quinn
182 * Revision 1.14 1995/03/31 09:18:58 quinn
185 * Revision 1.13 1995/03/30 16:08:39 quinn
188 * Revision 1.12 1995/03/30 13:29:02 quinn
191 * Revision 1.11 1995/03/30 12:18:17 quinn
194 * Revision 1.10 1995/03/29 15:40:16 quinn
195 * Ongoing work. Statserv is now dynamic by default
197 * Revision 1.9 1995/03/27 08:34:30 quinn
198 * Added dynamic server functionality.
199 * Released bindings to session.c (is now redundant)
201 * Revision 1.8 1995/03/20 09:46:26 quinn
204 * Revision 1.7 1995/03/16 13:29:04 quinn
205 * Partitioned server.
207 * Revision 1.6 1995/03/15 15:18:52 quinn
208 * Little changes to better support nonblocking I/O
211 * Revision 1.5 1995/03/15 08:37:45 quinn
212 * Now we're pretty much set for nonblocking I/O.
214 * Revision 1.4 1995/03/14 16:59:48 quinn
217 * Revision 1.3 1995/03/14 11:30:15 quinn
220 * Revision 1.2 1995/03/14 10:28:03 quinn
221 * More work on demo server.
223 * Revision 1.1 1995/03/10 18:22:45 quinn
224 * The rudiments of an asynchronous server.
246 #include <yaz/comstack.h>
247 #include <yaz/tcpip.h>
248 #include <yaz/options.h>
250 #include <yaz/xmosi.h>
255 #include <yaz/statserv.h>
257 static IOCHAN pListener = NULL;
259 static char *me = "statserver";
263 int check_options(int argc, char **argv);
264 statserv_options_block control_block = {
265 1, /* dynamic mode */
266 0, /* threaded mode */
267 0, /* one shot (single session) */
268 LOG_DEFAULT_LEVEL, /* log level */
270 "", /* diagnostic output to stderr */
271 "tcp:@:9999", /* default listener port */
272 PROTO_Z3950, /* default application protocol */
273 60, /* idle timeout (minutes) */
274 1024*1024, /* maximum PDU size (approx.) to allow */
275 "default-config", /* configuration name to pass to backend */
276 "", /* set user id */
277 0, /* bend_start handler */
278 0, /* bend_stop handler */
279 check_options, /* Default routine, for checking the run-time arguments */
282 0, /* default value for inet deamon */
283 0, /* handle (for service, etc) */
284 0, /* bend_init handle */
285 0 /* bend_close handle */
287 ,"Z39.50 Server", /* NT Service Name */
288 "Server", /* NT application Name */
289 "", /* NT Service Dependencies */
290 "Z39.50 Server" /* NT Service Display Name */
295 * handle incoming connect requests.
296 * The dynamic mode is a bit tricky mostly because we want to avoid
297 * doing all of the listening and accepting in the parent - it's
302 typedef struct _ThreadList ThreadList;
311 static ThreadList *pFirstThread;
312 static CRITICAL_SECTION Thread_CritSect;
313 static BOOL bInitialized = FALSE;
315 static void ThreadList_Initialize()
317 /* Initialize the critical Sections */
318 InitializeCriticalSection(&Thread_CritSect);
320 /* Set the first thraed */
323 /* we have been initialized */
327 static void statserv_add(HANDLE hThread, IOCHAN pIOChannel)
329 /* Only one thread can go through this section at a time */
330 EnterCriticalSection(&Thread_CritSect);
333 /* Lets create our new object */
334 ThreadList *pNewThread = (ThreadList *)malloc(sizeof(ThreadList));
335 pNewThread->hThread = hThread;
336 pNewThread->pIOChannel = pIOChannel;
337 pNewThread->pNext = pFirstThread;
338 pFirstThread = pNewThread;
340 /* Lets let somebody else create a new object now */
341 LeaveCriticalSection(&Thread_CritSect);
345 void statserv_remove(IOCHAN pIOChannel)
347 /* Only one thread can go through this section at a time */
348 EnterCriticalSection(&Thread_CritSect);
351 ThreadList *pCurrentThread = pFirstThread;
352 ThreadList *pNextThread;
353 ThreadList *pPrevThread =NULL;
355 /* Step through alll the threads */
356 for (; pCurrentThread != NULL; pCurrentThread = pNextThread)
358 /* We only need to compare on the IO Channel */
359 if (pCurrentThread->pIOChannel == pIOChannel)
361 /* We have found the thread we want to delete */
362 /* First of all reset the next pointers */
363 if (pPrevThread == NULL)
364 pFirstThread = pCurrentThread->pNext;
366 pPrevThread->pNext = pCurrentThread->pNext;
368 /* All we need todo now is delete the memory */
369 free(pCurrentThread);
371 /* No need to look at any more threads */
376 /* We need to look at another thread */
377 pNextThread = pCurrentThread->pNext;
378 pPrevThread = pCurrentThread;
382 /* Lets let somebody else remove an object now */
383 LeaveCriticalSection(&Thread_CritSect);
387 void statserv_closedown()
389 /* Shouldn't do anything if we are not initialized */
393 HANDLE *pThreadHandles = NULL;
395 /* We need to stop threads adding and removing while we */
396 /* start the closedown process */
397 EnterCriticalSection(&Thread_CritSect);
400 /* We have exclusive access to the thread stuff now */
401 /* Y didn't i use a semaphore - Oh well never mind */
402 ThreadList *pCurrentThread = pFirstThread;
404 /* Before we do anything else, we need to shutdown the listener */
405 if (pListener != NULL)
406 iochan_destroy(pListener);
408 for (; pCurrentThread != NULL; pCurrentThread = pCurrentThread->pNext)
410 /* Just destroy the IOCHAN, that should do the trick */
411 iochan_destroy(pCurrentThread->pIOChannel);
413 /* Keep a running count of our handles */
419 HANDLE *pCurrentHandle ;
421 /* Allocate the thread handle array */
422 pThreadHandles = (HANDLE *)malloc(sizeof(HANDLE) * iHandles);
423 pCurrentHandle = pThreadHandles;
425 for (pCurrentThread = pFirstThread;
426 pCurrentThread != NULL;
427 pCurrentThread = pCurrentThread->pNext, pCurrentHandle++)
429 /* Just the handle */
430 *pCurrentHandle = pCurrentThread->hThread;
434 /* We can now leave the critical section */
435 LeaveCriticalSection(&Thread_CritSect);
438 /* Now we can really do something */
441 /* This will now wait, until all the threads close */
442 WaitForMultipleObjects(iHandles, pThreadHandles, TRUE, INFINITE);
444 /* Free the memory we allocated for the handle array */
445 free(pThreadHandles);
448 if (control_block.bend_stop)
449 (*control_block.bend_stop)(&control_block);
450 /* No longer require the critical section, since all threads are dead */
451 DeleteCriticalSection(&Thread_CritSect);
455 int __stdcall event_loop_thread (IOCHAN iochan)
457 return event_loop (&iochan);
460 static void listener(IOCHAN h, int event)
462 COMSTACK line = (COMSTACK) iochan_getdata(h);
467 if (event == EVENT_INPUT)
469 if ((res = cs_listen(line, 0, 0)) < 0)
471 yaz_log(LOG_FATAL, "cs_listen failed");
476 yaz_log(LOG_DEBUG, "listen ok");
477 iochan_setevent(h, EVENT_OUTPUT);
478 iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */
480 else if (event == EVENT_OUTPUT)
487 if (!(new_line = cs_accept(line)))
489 yaz_log(LOG_FATAL, "Accept failed.");
490 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
493 yaz_log(LOG_DEBUG, "Accept ok");
495 if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session,
498 yaz_log(LOG_FATAL, "Failed to create iochan");
503 yaz_log(LOG_DEBUG, "Creating association");
504 if (!(newas = create_association(new_chan, new_line)))
506 yaz_log(LOG_FATAL, "Failed to create new assoc.");
510 yaz_log(LOG_DEBUG, "Setting timeout %d", control_block.idle_timeout);
511 iochan_setdata(new_chan, newas);
512 iochan_settimeout(new_chan, control_block.idle_timeout * 60);
514 yaz_log(LOG_DEBUG, "Determining client address");
515 a = cs_addrstr(new_line);
516 yaz_log(LOG_LOG, "Accepted connection from %s", a ? a : "[Unknown]");
518 /* Now what we need todo is create a new thread with this iochan as
520 /* if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)event_loop_thread,
521 new_chan, 0, &ThreadId) == NULL) */
522 /* Somehow, somewhere we need to store this thread id, otherwise we
523 won't be able to close cleanly */
524 NewHandle = (HANDLE)_beginthreadex(NULL, 0, event_loop_thread,
525 new_chan, 0, &ThreadId);
526 if (NewHandle == (HANDLE)-1)
529 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create new thread.");
533 /* We successfully created the thread, so add it to the list */
534 statserv_add(NewHandle, new_chan);
536 yaz_log(LOG_DEBUG, "Created new thread, iochan %p", new_chan);
537 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
541 yaz_log(LOG_FATAL, "Bad event on listener.");
549 /* To save having an #ifdef in event_loop we need to define this empty function */
550 void statserv_remove(IOCHAN pIOChannel)
554 void statserv_closedown()
558 if (control_block.bend_stop)
559 (*control_block.bend_stop)(&control_block);
561 for (p = pListener; p; p = p->next)
565 void sigterm(int sig)
567 statserv_closedown();
571 static void *new_session (void *vp);
573 static void listener(IOCHAN h, int event)
575 COMSTACK line = (COMSTACK) iochan_getdata(h);
577 static int child = 0;
580 if (event == EVENT_INPUT)
582 if (control_block.dynamic && !child)
588 yaz_log(LOG_FATAL|LOG_ERRNO, "pipe");
592 if ((res = fork()) < 0)
594 yaz_log(LOG_FATAL|LOG_ERRNO, "fork");
598 else if (res == 0) /* child */
605 for (pp = pListener; pp; pp = iochan_getnext(pp))
609 COMSTACK l = (COMSTACK)iochan_getdata(pp);
614 sprintf(nbuf, "%s(%d)", me, getpid());
615 yaz_log_init(control_block.loglevel, nbuf, 0);
620 /* wait for child to take the call */
626 if ((res = read(hand[0], dummy, 1)) < 0 && errno != EINTR)
628 yaz_log(LOG_FATAL|LOG_ERRNO, "handshake read");
634 yaz_log(LOG_DEBUG, "P: Child has taken the call");
639 if ((res = cs_listen_check(line, 0, 0, control_block.check_ip,
640 control_block.daemon_name)) < 0)
642 yaz_log(LOG_WARN, "cs_listen failed");
647 yaz_log(LOG_DEBUG, "listen ok");
648 iochan_setevent(h, EVENT_OUTPUT);
649 iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */
651 /* in dynamic mode, only the child ever comes down here */
652 else if (event == EVENT_OUTPUT)
656 if (!(new_line = cs_accept(line)))
658 yaz_log(LOG_FATAL, "Accept failed.");
659 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
662 yaz_log(LOG_DEBUG, "accept ok");
663 if (control_block.dynamic)
666 /* close our half of the listener socket */
667 for (pp = pListener; pp; pp = iochan_getnext(pp))
669 COMSTACK l = (COMSTACK)iochan_getdata(pp);
674 yaz_log(LOG_DEBUG, "Releasing parent");
678 iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
681 if (control_block.threads)
683 pthread_t child_thread;
684 pthread_create (&child_thread, 0, new_session, new_line);
685 pthread_detach (child_thread);
688 new_session(new_line);
690 new_session(new_line);
695 yaz_log(LOG_FATAL, "Bad event on listener.");
701 static void *new_session (void *vp)
706 COMSTACK new_line = (COMSTACK) vp;
707 if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session,
710 yaz_log(LOG_FATAL, "Failed to create iochan");
713 if (!(newas = create_association(new_chan, new_line)))
715 yaz_log(LOG_FATAL, "Failed to create new assoc.");
718 iochan_setdata(new_chan, newas);
719 iochan_settimeout(new_chan, control_block.idle_timeout * 60);
720 a = cs_addrstr(new_line);
721 yaz_log(LOG_LOG, "Accepted connection from %s", a ? a : "[Unknown]");
722 if (control_block.threads)
724 event_loop(&new_chan);
728 new_chan->next = pListener;
729 pListener = new_chan;
736 static void inetd_connection(int what)
743 if ((line = cs_createbysocket(0, tcpip_type, 0, what)))
745 if ((chan = iochan_create(cs_fileno(line), ir_session, EVENT_INPUT)))
747 if ((assoc = create_association(chan, line)))
749 iochan_setdata(chan, assoc);
750 iochan_settimeout(chan, control_block.idle_timeout * 60);
751 addr = cs_addrstr(line);
752 yaz_log(LOG_LOG, "Inetd association from %s", addr ? addr : "[UNKNOWN]");
756 yaz_log(LOG_FATAL, "Failed to create association structure");
758 chan->next = pListener;
763 yaz_log(LOG_FATAL, "Failed to create iochan");
768 yaz_log(LOG_ERRNO|LOG_FATAL, "Failed to create comstack on socket 0");
773 * Set up a listening endpoint, and give it to the event-handler.
775 static void add_listener(char *where, int what)
779 char mode[100], addr[100];
783 if (!where || sscanf(where, "%[^:]:%s", mode, addr) != 2)
785 yaz_log (LOG_WARN, "%s: Address format: ('tcp'|'osi')':'<address>", me);
788 if (!strcmp(mode, "tcp"))
790 else if (!strcmp(mode, "osi"))
795 yaz_log (LOG_WARN, "OSI Transport not allowed by configuration.");
801 yaz_log (LOG_WARN, "You must specify either 'osi:' or 'tcp:'");
804 yaz_log(LOG_LOG, "Adding %s %s listener on %s",
805 control_block.dynamic ? "dynamic" :
806 (control_block.threads ? "threaded" : "static"),
807 what == PROTO_SR ? "SR" : "Z3950", where);
808 if (!(l = cs_create(type, 0, what)))
810 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create listener");
813 ap = cs_straddr (l, addr);
816 fprintf(stderr, "Address resolution failed.\n");
820 if (cs_bind(l, ap, CS_SERVER) < 0)
822 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to bind to %s", where);
826 if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT |
829 yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create IOCHAN-type");
833 iochan_setdata(lst, l);
835 /* Ensure our listener chain is setup properly */
836 lst->next = pListener;
841 /* For windows we don't need to catch the signals */
842 static void catchchld(int num)
844 while (waitpid(-1, 0, WNOHANG) > 0)
846 signal(SIGCHLD, catchchld);
850 statserv_options_block *statserv_getcontrol(void)
852 static statserv_options_block cb;
854 memcpy(&cb, &control_block, sizeof(cb));
858 void statserv_setcontrol(statserv_options_block *block)
860 memcpy(&control_block, block, sizeof(*block));
863 int statserv_start(int argc, char **argv)
869 /* We need to initialize the thread list */
870 ThreadList_Initialize();
874 if ((me = strrchr (argv[0], '\\')))
881 if (control_block.options_func(argc, argv))
884 if (control_block.bend_start)
885 (*control_block.bend_start)(&control_block);
887 logf (LOG_LOG, "Starting server %s", me);
889 if (control_block.inetd)
890 inetd_connection(control_block.default_proto);
893 logf (LOG_LOG, "Starting server %s pid=%d", me, getpid());
895 sigset_t sigs_to_block;
897 sigemptyset(&sigs_to_block);
898 sigaddset (&sigs_to_block, SIGTERM);
899 pthread_sigmask (SIG_BLOCK, &sigs_to_block, 0);
904 if (control_block.dynamic)
905 signal(SIGCHLD, catchchld);
908 signal (SIGTERM, sigterm);
909 if (*control_block.setuid)
913 if (!(pw = getpwnam(control_block.setuid)))
915 yaz_log(LOG_FATAL, "%s: Unknown user", control_block.setuid);
918 if (setuid(pw->pw_uid) < 0)
920 yaz_log(LOG_FATAL|LOG_ERRNO, "setuid");
926 if ((pListener == NULL) && *control_block.default_listen)
927 add_listener(control_block.default_listen,
928 control_block.default_proto);
930 if (pListener == NULL)
934 yaz_log(LOG_LOG, "Entering event loop.");
935 ret = event_loop(&pListener);
941 int check_options(int argc, char **argv)
946 while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:", argv, argc, &arg)) != -2)
951 add_listener(arg, control_block.default_proto);
954 control_block.one_shot = 1;
955 control_block.dynamic = 0;
958 control_block.default_proto = PROTO_Z3950;
961 control_block.default_proto = PROTO_SR;
964 control_block.dynamic = 0;
968 control_block.dynamic = 0;
969 control_block.threads = 1;
971 fprintf(stderr, "%s: Threaded mode not available.\n", me);
976 strcpy(control_block.logfile, arg ? arg : "");
977 yaz_log_init(control_block.loglevel, me, control_block.logfile);
980 control_block.loglevel = yaz_log_mask_str(arg);
981 yaz_log_init(control_block.loglevel, me, control_block.logfile);
984 strcpy(control_block.apdufile, arg ? arg : "");
987 strcpy(control_block.setuid, arg ? arg : "");
990 strcpy(control_block.configname, arg ? arg : "");
993 strcpy(control_block.daemon_name, arg ? arg : "");
996 if (!arg || !(r = atoi(arg)))
998 fprintf(stderr, "%s: Specify positive timeout for -t.\n", me);
1001 control_block.idle_timeout = r;
1004 if (!arg || !(r = atoi(arg)))
1006 fprintf(stderr, "%s: Specify positive size for -k.\n", me);
1009 control_block.maxrecordsize = r * 1024;
1012 control_block.inetd = 1;
1022 fprintf(stderr, "Usage: %s [ -a <pdufile> -v <loglevel>"
1023 " -l <logfile> -u <user> -c <config> -t <minutes>"
1024 " -k <kilobytes> -d <daemon>"
1025 " -zsiST -w <directory> <listender-addr>... ]\n", me);
1033 typedef struct _Args
1039 static Args ArgDetails;
1041 /* name of the executable */
1042 #define SZAPPNAME "server"
1044 /* list of service dependencies - "dep1\0dep2\0\0" */
1045 #define SZDEPENDENCIES ""
1047 int statserv_main(int argc, char **argv,
1048 bend_initresult *(*bend_init)(bend_initrequest *r),
1049 void (*bend_close)(void *handle))
1051 statserv_options_block *cb = statserv_getcontrol();
1053 cb->bend_init = bend_init;
1054 cb->bend_close = bend_close;
1056 statserv_setcontrol(cb);
1058 /* Lets setup the Arg structure */
1059 ArgDetails.argc = argc;
1060 ArgDetails.argv = argv;
1062 /* Now setup the service with the service controller */
1063 SetupService(argc, argv, &ArgDetails, SZAPPNAME,
1064 cb->service_name, /* internal service name */
1065 cb->service_name, /* displayed name of the service */
1070 int StartAppService(void *pHandle, int argc, char **argv)
1072 /* Initializes the App */
1076 void RunAppService(void *pHandle)
1078 Args *pArgs = (Args *)pHandle;
1080 /* Starts the app running */
1081 statserv_start(pArgs->argc, pArgs->argv);
1084 void StopAppService(void *pHandle)
1087 statserv_closedown();
1090 int statserv_main(int argc, char **argv,
1091 bend_initresult *(*bend_init)(bend_initrequest *r),
1092 void (*bend_close)(void *handle))
1095 statserv_options_block *cb = statserv_getcontrol();
1097 cb->bend_init = bend_init;
1098 cb->bend_close = bend_close;
1100 statserv_setcontrol(cb);
1101 ret = statserv_start (argc, argv);
1102 statserv_closedown ();