Пример #1
0
/*!
 * Signal handler to increase the logging level.
 *
 * Increase the current logging level to 1 if it in currently 0,
 * otherwise, increase the current logging level by a factor of 5 if it
 * is currently non-zero.
 *
 * Enables thread id logging when the log level is greater than 1.
 */
void
SetDebug_Signal(int signo)
{
    if (LogLevel > 0) {
	LogLevel *= 5;

#if defined(AFS_PTHREAD_ENV)
        if (LogLevel > 1 && threadNumProgram != NULL &&
            threadIdLogs == 0) {
            threadIdLogs = 1;
        }
#endif
    } else {
	LogLevel = 1;

#if defined(AFS_PTHREAD_ENV)
        if (threadIdLogs == 1)
            threadIdLogs = 0;
#endif
    }
#if defined(AFS_PTHREAD_ENV)
    DebugOn((void *)(intptr_t)LogLevel);
#else /* AFS_PTHREAD_ENV */
    IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
#endif /* AFS_PTHREAD_ENV */

    if (resetSignals) {
	/* When pthreaded softsig handlers are not in use, some platforms
	 * require this signal handler to be set again. */
	(void)signal(signo, SetDebug_Signal);
    }
}				/*SetDebug_Signal */
Пример #2
0
void
SetDebug_Signal(int signo)
{
    if (LogLevel > 0) {
	LogLevel *= 5;

#if defined(AFS_PTHREAD_ENV)
        if (LogLevel > 1 && threadNumProgram != NULL &&
            threadIdLogs == 0) {
            threadIdLogs = 1;
        }
#endif
    } else {
	LogLevel = 1;

#if defined(AFS_PTHREAD_ENV)
        if (threadIdLogs == 1)
            threadIdLogs = 0;
#endif
    }
    printLocks = 2;
#if defined(AFS_PTHREAD_ENV)
    DebugOn((void *)(intptr_t)LogLevel);
#else /* AFS_PTHREAD_ENV */
    IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
#endif /* AFS_PTHREAD_ENV */

    (void)signal(signo, SetDebug_Signal);	/* on some platforms, this
						 * signal handler needs to
						 * be set again */
}				/*SetDebug_Signal */
/********************************************************************************
 * Function: Debug()
 * Params:   pszFormat - Formatting of variable parameters.
 *           ...
 * Returns:  Returns the number of characters printed by vprintf()
 * Call by:  most fuctions in this program
 * Call to:  DebugOn()
 * Overview: Debugging aid if needed, which prints messages to standard output.
 * Notes:    va_start, va_end uses stdarg.h
 *           DebugOn(0) the zero does not matter, it can be any value, but 0 for
 *           simplicity.
 *           Debug is enabled by calling the program with --debug
 ********************************************************************************/
int Debug(const char *pszFormat, ...)
{
    int nReturnCode = 0;
    va_list pstrList;



    if (DebugOn(0) == TRUE)
    {
       printf("DEBUG ");

       va_start(pstrList, pszFormat);
       nReturnCode = vprintf(pszFormat, pstrList);
       va_end(pstrList);
    }


    return(nReturnCode);
}
Пример #4
0
void
ResetDebug_Signal(int signo)
{
    LogLevel = 0;

    if (printLocks > 0)
	--printLocks;
#if defined(AFS_PTHREAD_ENV)
    DebugOn((void *)(intptr_t)LogLevel);
#else /* AFS_PTHREAD_ENV */
    IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
#endif /* AFS_PTHREAD_ENV */

    (void)signal(signo, ResetDebug_Signal);	/* on some platforms,
						 * this signal handler
						 * needs to be set
						 * again */
#if defined(AFS_PTHREAD_ENV)
    if (threadIdLogs == 1)
        threadIdLogs = 0;
#endif
    if (mrafsStyleLogs)
	OpenLog((char *)&ourName);
}				/*ResetDebug_Signal */
Пример #5
0
/*!
 * Signal handler to reset the logging level.
 *
 * Reset the logging level and disable thread id logging.
 *
 * \note This handler has the side-effect of rotating and reopening
 *       MR-AFS style logs.
 */
void
ResetDebug_Signal(int signo)
{
    LogLevel = 0;

#if defined(AFS_PTHREAD_ENV)
    DebugOn((void *)(intptr_t)LogLevel);
#else /* AFS_PTHREAD_ENV */
    IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
#endif /* AFS_PTHREAD_ENV */

    if (resetSignals) {
	/* When pthreaded softsig handlers are not in use, some platforms
	 * require this signal handler to be set again. */
	(void)signal(signo, ResetDebug_Signal);
    }
#if defined(AFS_PTHREAD_ENV)
    if (threadIdLogs == 1)
        threadIdLogs = 0;
#endif
    if (serverLogOpts.lopt_rotateOnReset) {
	RotateLogFile();
    }
}				/*ResetDebug_Signal */
Пример #6
0
void RunServer()
{   
    Bool16 restartServer = false;
    UInt32 loopCount = 0;
    UInt32 debugLevel = 0;
    Bool16 printHeader = false;
    Bool16 printStatus = false;


    //just wait until someone stops the server or a fatal error occurs.
    QTSS_ServerState theServerState = sServer->GetServerState();
    while ((theServerState != qtssShuttingDownState) &&
            (theServerState != qtssFatalErrorState))
    {
#ifdef __sgi__
        OSThread::Sleep(999);
#else
        OSThread::Sleep(1000);
#endif

        LogStatus(theServerState);

        if (sStatusUpdateInterval)
        {
            debugLevel = sServer->GetDebugLevel();             
            printHeader = PrintHeader(loopCount);
            printStatus = PrintLine(loopCount);
                
            if (printStatus)
            {
                if  (DebugOn(sServer) ) // debug level display or logging is on
                    DebugStatus(debugLevel, printHeader);
                
                if (!DebugDisplayOn(sServer))
                    PrintStatus(printHeader); // default status output
            }
            
            
            loopCount++;

        }
        
        if ((sServer->SigIntSet()) || (sServer->SigTermSet()))
        {
            //
            // start the shutdown process
            theServerState = qtssShuttingDownState;
            (void)QTSS_SetValue(QTSServerInterface::GetServer(), qtssSvrState, 0, &theServerState, sizeof(theServerState));

            if (sServer->SigIntSet())
                restartServer = true;
        }
        
        theServerState = sServer->GetServerState();
        if (theServerState == qtssIdleState)
            sServer->KillAllRTPSessions();
    }
    
    //
    // Kill all the sessions and wait for them to die,
    // but don't wait more than 5 seconds
    sServer->KillAllRTPSessions();
    for (UInt32 shutdownWaitCount = 0; (sServer->GetNumRTPSessions() > 0) && (shutdownWaitCount < 5); shutdownWaitCount++)
        OSThread::Sleep(1000);
        
    //Now, make sure that the server can't do any work
    TaskThreadPool::RemoveThreads();
    
    //now that the server is definitely stopped, it is safe to initate
    //the shutdown process
    delete sServer;
    
    CleanPid(false);
    //ok, we're ready to exit. If we're quitting because of some fatal error
    //while running the server, make sure to let the parent process know by
    //exiting with a nonzero status. Otherwise, exit with a 0 status
    if (theServerState == qtssFatalErrorState || restartServer)
        ::exit (-2);//-2 signals parent process to restart server
}
Пример #7
0
void RunServer()
{   
    Bool16 restartServer = false;
    UInt32 loopCount = 0;
    UInt32 debugLevel = 0;
    Bool16 printHeader = false;
    Bool16 printStatus = false;

	UInt32 num=0;//add
    //just wait until someone stops the server or a fatal error occurs.
    QTSS_ServerState theServerState = sServer->GetServerState();
    while ((theServerState != qtssShuttingDownState) &&
            (theServerState != qtssFatalErrorState))
    {
#ifdef __sgi__
        OSThread::Sleep(999);
#else
        OSThread::Sleep(1000);
#endif
		//add,redis,定时保活
		num++;
		if(num%5==0)
		{
			num=0;
			UInt32 numModules = QTSServerInterface::GetNumModulesInRole(QTSSModule::kRedisTTLRole);
			for ( UInt32 currentModule=0;currentModule < numModules; currentModule++)
			{
				QTSSModule* theModule = QTSServerInterface::GetModule(QTSSModule::kRedisTTLRole, currentModule);
				(void)theModule->CallDispatch(Easy_RedisTTL_Role, NULL);
			}
		}
		//
        LogStatus(theServerState);

        if (sStatusUpdateInterval)
        {
            debugLevel = sServer->GetDebugLevel();             
            printHeader = PrintHeader(loopCount);
            printStatus = PrintLine(loopCount);
                
            if (printStatus)
            {
                if  (DebugOn(sServer) ) // debug level display or logging is on
                    DebugStatus(debugLevel, printHeader);
                
                if (!DebugDisplayOn(sServer))
                    PrintStatus(printHeader); // default status output
            }
            
            
            loopCount++;

        }
        
        if ((sServer->SigIntSet()) || (sServer->SigTermSet()))
        {
            //
            // start the shutdown process
            theServerState = qtssShuttingDownState;
            (void)QTSS_SetValue(QTSServerInterface::GetServer(), qtssSvrState, 0, &theServerState, sizeof(theServerState));

            if (sServer->SigIntSet())
                restartServer = true;
        }
    }
        
    //Now, make sure that the server can't do any work
    TaskThreadPool::RemoveThreads();
    
    //now that the server is definitely stopped, it is safe to initate
    //the shutdown process
    delete sServer;
    
    CleanPid(false);
    //ok, we're ready to exit. If we're quitting because of some fatal error
    //while running the server, make sure to let the parent process know by
    //exiting with a nonzero status. Otherwise, exit with a 0 status
    if (theServerState == qtssFatalErrorState || restartServer)
        ::exit (-2);//-2 signals parent process to restart server
}
/*********************************************************************************
 * Function: main()
 * Params:   argc
 *           argv
 * Returns:  0 - no errors
 *           Less than 0 means a problem, such as opening socket, binding, etc.
 * Call by:  Shell
 * Call to:  Debug()
 *           DebugOn()
 *           ProcessCommandLine()
 *           ReadClientRequest()
 *           SendIndexFile()
 * Overview: Program entry point.
 *           Reads the command line options and executes a simple webserver.  The
 *           webserver listens for client requests, accepts request, and then sends
 *           the content of index.htm.
 * Notes:    Sample: --port 80 --listenip 127.0.0.1 --indexfile ./index.htm --debug
 *           Sample: --port 80 --listenip 127.0.0.1 --indexfile ./index.htm
 *           Running on a low number port requires priviledged access; otherwise,
 *           bind() will fail.
 *           127.0.0.1 is the local host this program is running on.
 *           --debug is the only optional argument.
 *           Exiting the program with CTRL-C may hold the port open for a few
 *           minutes.
 *********************************************************************************/
int main(int argc, char *argv[])
{
   strCommandLine strRunOptions;
   int nExitCode = 0;



   memset(&strRunOptions, 0, sizeof(strRunOptions));


   if (argc < 7)
   {
      printf("Example: %s --port 80 --listenip 127.0.0.1 --indexfile ./index.htm --debug\n", argv[0]);
      printf("Example: %s --port 80 --listenip 127.0.0.1 --indexfile ./index.htm\n", argv[0]);
      printf("Low port numbers may require root access to open.\n");
      printf("--debug is the only optional argument.\n");
      printf("CTRL-C to exit the program may leave the port open for a few minutes.\n");
   }
   else
   {
      int nSocketClient = 0;
      int nSocketHost   = 0;
      int nLength       = sizeof(struct sockaddr_in);
      struct sockaddr_in strClient;


      ProcessCommandLine(&strRunOptions, argc, argv);


      /***************************************************************************
       * First call to DebugOn() will determine whether Debug() will write debug
       * messages for the rest of the program.
       *
       * If bDebug is FALSE then no logging messages are displayed when calling
       * Debug(). 
       * If bDebug is TRUE then logging messages are displayed when calling Debug().
       ***************************************************************************/
      DebugOn(strRunOptions.bDebug);

      Debug("Port: %d; IP: %s; Index file: %s; Debug: %s;\n\n",
            strRunOptions.nPort,
            strRunOptions.szHostIP,
            strRunOptions.szIndexFile,
            strRunOptions.bDebug==TRUE?"On":"Off");


      nSocketHost = OpenPort(strRunOptions.nPort);
 

      /***************************************************************************
       * Listen to the server socket, and wait for an incoming client request to
       * accept.  Once accepted (a socket to the client will be created), read the
       * header request from the browser/client.  Then read the index.htm file and
       * send the content of index.htm back to the client.
       *
       * There's no clean exit from the program at the moment.  The program can be
       * stopped with CTRL-C or a kill command.
       ***************************************************************************/
      for (;;)
      {
         if (listen(nSocketHost, 3) < 0)
         {
            fprintf(stderr, "Failed to listen(). errno=%d.\n", errno);
            break;
         }
         else
         {
            Debug("Listening...\n");
         }

         memset(&strClient, 0, sizeof(strClient));

         if ((nSocketClient = accept(nSocketHost,(struct sockaddr *)&strClient,(socklen_t*)&nLength)) <= 0)
         {
            fprintf(stderr, "Failed to accept(). errno=%d.\n", errno);
            break;
         }
         else
         {
            Debug("Reading from client...\n");
            ReadClientRequest(nSocketClient);

            Debug("About to write to client...\n");
            SendIndexFile(nSocketClient, strRunOptions.szIndexFile);
         }
      }


      close(nSocketClient);
      close(nSocketHost);
   }



   exit(nExitCode);
}