From: Stephen D. <sd...@us...> - 2005-04-03 06:38:13
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10396/nsd Modified Files: driver.c nsd.h nsmain.c tclinit.c Log Message: * nsd/nsd.h: * nsd/driver.c: * nsd/tclinit.c: * nsd/nsmain.c: Add -c command line option which causes the server to start in command mode, reading commands from stdin and executing them like a tclsh. * Makefile: * tests/test.nscfg: * tests/all.tcl: Add new Makefile targets test, runtest and gdb which start the server in command mode. Modify the test runner and add a test server config file. * tests/http.test: * tests/ns_addrbyhost.test: * tests/ns_adp_compress.test: * tests/ns_hostbyaddr.test: * tests/ns_hrefs.test: * tests/ns_parseargs.test: Update tests to use tlctest syntax and features. Index: tclinit.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclinit.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tclinit.c 26 Mar 2005 14:25:25 -0000 1.2 --- tclinit.c 3 Apr 2005 06:38:01 -0000 1.3 *************** *** 70,74 **** static Tcl_InterpDeleteProc FreeData; static Ns_TlsCleanup DeleteInterps; - static int InitInterp(Tcl_Interp *interp, NsServer *servPtr, NsInterp **itPtrPtr); static int UpdateInterp(NsInterp *itPtr); static Tcl_HashEntry *GetHashEntry(NsServer *servPtr); --- 70,73 ---- *************** *** 292,296 **** Ns_TclInit(Tcl_Interp *interp) { ! return InitInterp(interp, NULL, NULL); } --- 291,295 ---- Ns_TclInit(Tcl_Interp *interp) { ! return NsInitInterp(interp, NULL, NULL); } *************** *** 418,422 **** Tcl_SetHashValue(hPtr, itPtr->nextPtr); } else { ! (void) InitInterp(Tcl_CreateInterp(), servPtr, &itPtr); } interp = itPtr->interp; --- 417,421 ---- Tcl_SetHashValue(hPtr, itPtr->nextPtr); } else { ! (void) NsInitInterp(Tcl_CreateInterp(), servPtr, &itPtr); } interp = itPtr->interp; *************** *** 1135,1141 **** *---------------------------------------------------------------------- * ! * InitInterp -- * ! * Initialize an interp with standard Tcl and AOLserver commands. * If servPtr is not NULL, virtual server commands will be added * as well. --- 1134,1140 ---- *---------------------------------------------------------------------- * ! * NsInitInterp -- * ! * Initialize an interp with standard Tcl and server commands. * If servPtr is not NULL, virtual server commands will be added * as well. *************** *** 1150,1155 **** */ ! static int ! InitInterp(Tcl_Interp *interp, NsServer *servPtr, NsInterp **itPtrPtr) { static volatile int initialized = 0; --- 1149,1154 ---- */ ! int ! NsInitInterp(Tcl_Interp *interp, NsServer *servPtr, NsInterp **itPtrPtr) { static volatile int initialized = 0; Index: nsd.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsd.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** nsd.h 28 Mar 2005 17:02:07 -0000 1.8 --- nsd.h 3 Apr 2005 06:38:01 -0000 1.9 *************** *** 808,811 **** --- 808,813 ---- extern NsServer *NsGetInitServer(void); extern NsInterp *NsGetInterp(Tcl_Interp *interp); + extern int NsInitInterp(Tcl_Interp *interp, NsServer *servPtr, + NsInterp **itPtrPtr); extern Ns_OpProc NsFastGet; Index: driver.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/driver.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** driver.c 22 Mar 2005 20:49:31 -0000 1.2 --- driver.c 3 Apr 2005 06:38:01 -0000 1.3 *************** *** 500,508 **** */ ! if (ns_sockpair(trigPipe) != 0) { ! Ns_Fatal("driver: ns_sockpair() failed: %s", ! ns_sockstrerror(ns_sockerrno)); } - Ns_ThreadCreate(DriverThread, NULL, 0, &driverThread); } --- 500,510 ---- */ ! if (firstDrvPtr != NULL) { ! if (ns_sockpair(trigPipe) != 0) { ! Ns_Fatal("driver: ns_sockpair() failed: %s", ! ns_sockstrerror(ns_sockerrno)); ! } ! Ns_ThreadCreate(DriverThread, NULL, 0, &driverThread); } } Index: nsmain.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsmain.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** nsmain.c 17 Mar 2005 17:49:12 -0000 1.3 --- nsmain.c 3 Apr 2005 06:38:01 -0000 1.4 *************** *** 37,50 **** #include "nsd.h" ! #ifdef _WIN32 ! #define DEVNULL "nul:" #else ! #define DEVNULL "/dev/null" #endif /* * Local functions defined in this file. */ static int StartWatchedServer(void); static void SysLog(int priority, char *fmt, ...); --- 37,68 ---- #include "nsd.h" ! ! #ifndef _WIN32 ! # ifdef LOG_DEBUG ! # undef LOG_DEBUG /* Because this is used by the syslog facility as well */ ! # endif ! # include <syslog.h> ! # include <signal.h> ! # include <stdarg.h> ! # include <unistd.h> ! # define DEVNULL "/dev/null" #else ! # define DEVNULL "nul:" #endif /* + * The following values define the restart behaviour for watchdog mode. + */ + + #define MAX_RESTART_SECONDS 64 /* Max time in sec to wait between restarts */ + #define MIN_WORK_SECONDS 128 /* After being up for # secs, reset timers */ + #define MAX_NUM_RESTARTS 256 /* Quit after somany unsuccessful restarts */ + + /* * Local functions defined in this file. */ + static Tcl_AppInitProc CommandInit; + static int StartWatchedServer(void); static void SysLog(int priority, char *fmt, ...); *************** *** 62,84 **** /* ! * Setup timer/counter values for graceously waiting before trying ! * to restart crippled server. This should be configurable from the ! * server config file (ns/watchdog section or alike). */ ! #define MAX_RESTART_SECONDS 64 /* Max time in sec to wait between restarts */ ! #define MIN_WORK_SECONDS 128 /* After being up for # secs, reset timers */ ! #define MAX_NUM_RESTARTS 256 /* Quit after somany unsuccessful restarts */ ! ! #ifndef _WIN32 ! # ifdef LOG_DEBUG ! # undef LOG_DEBUG /* Because this is used by the syslog facility as well */ ! # endif ! # include <syslog.h> ! # include <signal.h> ! # include <stdarg.h> ! # include <unistd.h> static int watchdogExit = 0; /* Watchdog loop toggle */ ! #endif /* _WIN32 */ --- 80,89 ---- /* ! * Local variables defined in this file. */ ! static char *cmdServer; /* Command mode interp server */ static int watchdogExit = 0; /* Watchdog loop toggle */ ! *************** *** 104,108 **** Ns_Main(int argc, char **argv, Ns_ServerInitProc *initProc) { ! int i, fd, sig; char *config; Ns_Time timeout; --- 109,114 ---- Ns_Main(int argc, char **argv, Ns_ServerInitProc *initProc) { ! int i, fd, sig, cmdargc; ! char **cmdargv; char *config; Ns_Time timeout; *************** *** 171,187 **** nsconf.argv0 = argv[0]; - /* - * NaviServer requires file descriptor 0 be open on /dev/null to - * ensure the server never blocks reading stdin. - */ - - fd = open(DEVNULL, O_RDONLY); - if (fd > 0) { - dup2(fd, 0); - close(fd); - } - /* ! * Also, file descriptors 1 and 2 may not be open if the server * is starting from /etc/init. If so, open them on /dev/null * as well because the server will assume they're open during --- 177,182 ---- nsconf.argv0 = argv[0]; /* ! * File descriptors 1 and 2 may not be open if the server * is starting from /etc/init. If so, open them on /dev/null * as well because the server will assume they're open during *************** *** 204,212 **** opterr = 0; ! while ((i = getopt(argc, argv, "hpzifwVs:t:IRSkKdr:u:g:b:B:")) != -1) { switch (i) { case 'h': UsageError(NULL); break; case 'f': case 'i': --- 199,208 ---- opterr = 0; ! while ((i = getopt(argc, argv, "+chpzifwVs:t:IRSkKdr:u:g:b:B:")) != -1) { switch (i) { case 'h': UsageError(NULL); break; + case 'c': case 'f': case 'i': *************** *** 220,226 **** if (mode != 0) { #ifdef _WIN32 ! UsageError("only one of -i, -f, -V, -I, -R, or -S may be specified"); #else ! UsageError("only one of -i, -f, -w, or -V may be specified"); #endif } --- 216,222 ---- if (mode != 0) { #ifdef _WIN32 ! UsageError("only one of -c, -i, -f, -V, -I, -R, or -S may be specified"); #else ! UsageError("only one of -c, -i, -f, -w, or -V may be specified"); #endif } *************** *** 284,288 **** UsageError("required -t <config> option not specified"); } ! /* * Find the absolute config pathname and read the config data --- 280,296 ---- UsageError("required -t <config> option not specified"); } ! if (mode != 'c') { ! /* ! * The server requires file descriptor 0 be open on /dev/null to ! * ensure the server never blocks reading stdin. ! */ ! ! fd = open(DEVNULL, O_RDONLY); ! if (fd > 0) { ! dup2(fd, 0); ! close(fd); ! } ! } ! /* * Find the absolute config pathname and read the config data *************** *** 532,536 **** server = Ns_SetKey(servers, i); } ! /* * Set the procname used for the pid file. --- 540,544 ---- server = Ns_SetKey(servers, i); } ! /* * Set the procname used for the pid file. *************** *** 544,551 **** nsconf.home = Ns_ConfigGetValue(NS_CONFIG_PARAMETERS, "home"); ! if (nsconf.home == NULL) { Ns_Fatal("nsmain: missing: [%s]home", NS_CONFIG_PARAMETERS); } ! if (chdir(nsconf.home) != 0) { Ns_Fatal("nsmain: chdir(%s) failed: '%s'", nsconf.home, strerror(errno)); } --- 552,559 ---- nsconf.home = Ns_ConfigGetValue(NS_CONFIG_PARAMETERS, "home"); ! if (mode != 'c' && nsconf.home == NULL) { Ns_Fatal("nsmain: missing: [%s]home", NS_CONFIG_PARAMETERS); } ! if (nsconf.home != NULL && chdir(nsconf.home) != 0) { Ns_Fatal("nsmain: chdir(%s) failed: '%s'", nsconf.home, strerror(errno)); } *************** *** 610,614 **** */ ! if (mode != 'f') { NsLogOpen(); } --- 618,622 ---- */ ! if (mode != 'c' && mode != 'f') { NsLogOpen(); } *************** *** 646,650 **** */ ! NsCreatePidFile(procname); /* --- 654,660 ---- */ ! if (mode != 'c') { ! NsCreatePidFile(procname); ! } /* *************** *** 660,663 **** --- 670,674 ---- } } + cmdServer = server; /* *************** *** 700,703 **** --- 711,730 ---- #endif + if (mode == 'c') { + /* + * Initialize Tcl and start interpreting commands. + * This function never returns, so no clean shutdown. + */ + + NsRestoreSignals(); + cmdargv = ns_calloc((size_t) argc - optind + 2, sizeof(char *)); + cmdargc = 0; + cmdargv[cmdargc++] = argv[0]; + for (i = optind; i < argc; i++) { + cmdargv[cmdargc++] = argv[i]; + } + Tcl_Main(cmdargc, cmdargv, CommandInit); + } + /* * Once the drivers listen thread is started, this thread will just *************** *** 888,891 **** --- 915,943 ---- *---------------------------------------------------------------------- * + * CommandInit -- + * + * Initialize the interp with server commands. + * + * Results: + * TCL_OK or TCL_ERROR. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + static int + CommandInit(Tcl_Interp *interp) + { + NsServer *servPtr = NsGetServer(cmdServer); + + return NsInitInterp(interp, servPtr, NULL); + } + + + /* + *---------------------------------------------------------------------- + * * StatusMsg -- * *************** *** 958,962 **** } fprintf(stderr, "\n" ! "Usage: %s [-h|V] [-i|f] " #ifdef _WIN32 "[-I|R] " --- 1010,1014 ---- } fprintf(stderr, "\n" ! "Usage: %s [-h|V] [-c|-i|f] " #ifdef _WIN32 "[-I|R] " *************** *** 968,971 **** --- 1020,1024 ---- " -h help (this message)\n" " -V version and release information\n" + " -c command mode\n" " -i inittab mode\n" " -f foreground mode\n" |