示例#1
0
/** Handles a SIG_HUP signal from the system.
 *
 * @internal
 */
static void HandleSigHup(void)
{
   /* Reinitialize */
   SLPDLog("****************************************\n");
   SLPDLogTime();
   SLPDLog("SLPD daemon reset by SIGHUP\n");
   SLPDLog("****************************************\n\n");

   /* unregister with all DAs */
   SLPDKnownDADeinit();

   /* re-read properties */
   SLPDPropertyReinit();

#ifdef ENABLE_SLPv2_SECURITY
   /* Re-initialize SPI stuff*/
   SLPDSpiInit(G_SlpdCommandLine.spifile);
#endif

   /* Re-read the static registration file (slp.reg)*/
   SLPDDatabaseReInit(G_SlpdCommandLine.regfile);

   /* Rebuild Known DA database */
   SLPDKnownDAInit();

   SLPDLog("****************************************\n");
   SLPDLogTime();
   SLPDLog("SLPD daemon reset finished\n");
   SLPDLog("****************************************\n\n");
}
示例#2
0
/** Initialize the slpd property management subsystem.
 *
 * Reads configuration parameters from a file into the system.
 *
 * @param[in] conffile - The name of the configuration file
 *
 * @return Zero on success, or a non-zero value on failure.
 */
int SLPDPropertyInit(const char * conffile)
{
    /* initialize the slp property subsystem */
    if (SLPPropertyInit(conffile) != 0)
        return -1;

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

    SLPDPropertyReinit();

    return 0;
}
示例#3
0
/** Process main entry point.
 *
 * @param[in] argc - The number of command line arguments passed in @p argv.
 * @param[in] argv - An array of pointers to command line arguments.
 *
 * @return Zero on success, or a non-zero shell error code.
 *
 * @remarks This routine contains the main server loop.
 */
int main(int argc, char * argv[])
{
   fd_set readfds;
   fd_set writefds;
   int highfd;
   int fdcount = 0;
   time_t curtime;
   struct timeval timeout;

#ifdef DEBUG
   xmalloc_init("/var/log/slpd_xmalloc.log", 0);
#endif

   /* Parse the command line */
   if (SLPDParseCommandLine(argc,argv))
      SLPDFatal("Invalid command line\n");

   /* make sure we are root */
   if (getuid() != 0)
      SLPDFatal("slpd must be started by root\n");

   /* make sure we are not already running */
   if (CheckPid(G_SlpdCommandLine.pidfile))
      SLPDFatal("slpd is already running. Check %s\n",
            G_SlpdCommandLine.pidfile);

   /* Initialize the preferences so we know if the log file is to be
      overwritten or appended.*/
   if (SLPDPropertyInit(G_SlpdCommandLine.cfgfile))
      SLPDFatal("slpd initialization failed during property load\n");

   /* make slpd run as a daemon */
   if (Daemonize(G_SlpdCommandLine.pidfile))
      SLPDFatal("Could not daemonize\n");

   /* initialize the log file */
   if (SLPDLogFileOpen(G_SlpdCommandLine.logfile, G_SlpdProperty.appendLog))
      SLPDFatal("Could not open logfile %s\n",G_SlpdCommandLine.logfile);

   /* seed the XID generator */
   SLPXidSeed();

   /* log startup message */
   SLPDLog("****************************************\n");
   SLPDLogTime();
   SLPDLog("SLPD daemon started\n");
   SLPDLog("****************************************\n");
   SLPDLog("Command line = %s\n", argv[0]);
   SLPDLog("Using configuration file = %s\n", G_SlpdCommandLine.cfgfile);
   SLPDLog("Using registration file = %s\n", G_SlpdCommandLine.regfile);
#ifdef ENABLE_SLPv2_SECURITY
   SLPDLog("Using SPI file = %s\n", G_SlpdCommandLine.spifile);
#endif

   /* initialize for the first time */
   SLPDPropertyReinit();  /*So we get any property-related log messages*/
   if (
#ifdef ENABLE_SLPv2_SECURITY
         SLPDSpiInit(G_SlpdCommandLine.spifile) ||
#endif     
         SLPDDatabaseInit(G_SlpdCommandLine.regfile)
         || SLPDIncomingInit() 
         || SLPDOutgoingInit() 
         || SLPDKnownDAInit())
      SLPDFatal("slpd initialization failed\n");
   SLPDLog("Agent Interfaces = %s\n", G_SlpdProperty.interfaces);
   if (G_SlpdProperty.port != SLP_RESERVED_PORT)
      SLPDLog("Using port %d instead of default %d\n", G_SlpdProperty.port, SLP_RESERVED_PORT);

   /* drop privileges to reduce security risk */
   if (DropPrivileges())
      SLPDFatal("Could not drop privileges\n");

   /* Setup signal handlers */
   if (SetUpSignalHandlers())
      SLPDFatal("Error setting up signal handlers.\n");

   /* Set up alarm to age database -- a shorter start, so SAs register with us quickly on our startup */
   alarm(2);

   /* Main loop */
   SLPDLog("Startup complete entering main run loop ...\n\n");
   G_SIGALRM   = 0;
   G_SIGTERM   = 0;
   G_SIGHUP    = 0;    
#ifdef DEBUG
   G_SIGINT    = 0;
   G_SIGUSR1   = 0;    
#endif

   while (G_SIGTERM == 0)
   {
      /* load the fdsets up with all valid sockets in the list  */
      highfd = 0;
      FD_ZERO(&readfds);
      FD_ZERO(&writefds);
      LoadFdSets(&G_IncomingSocketList, &highfd, &readfds, &writefds);
      LoadFdSets(&G_OutgoingSocketList, &highfd, &readfds, &writefds);

      /* before select(), check to see if we got a signal */
      if (G_SIGALRM || G_SIGHUP)
         goto HANDLE_SIGNAL;

      /* main select -- we time out every second so the outgoing retries can occur*/
      time(&curtime);  
      timeout.tv_sec = 1;
      timeout.tv_usec = 0;
      fdcount = select(highfd + 1, &readfds, &writefds, 0, &timeout);
      if (fdcount > 0) /* fdcount will be < 0 when interrupted by a signal */
      {
         SLPDIncomingHandler(&fdcount, &readfds, &writefds);
         SLPDOutgoingHandler(&fdcount, &readfds, &writefds);
         SLPDOutgoingRetry(time(0) - curtime);
      }
      else if (fdcount == 0)
         SLPDOutgoingRetry(time(0) - curtime);


HANDLE_SIGNAL:

      if (G_SIGHUP)
      {
         HandleSigHup();
         G_SIGHUP = 0;
      }
      if (G_SIGALRM)
      {
         HandleSigAlrm();
         G_SIGALRM = 0;
         alarm(SLPD_AGE_INTERVAL);
      }

#ifdef DEBUG
      if (G_SIGINT)
      {
         HandleSigInt();
         G_SIGINT = 0;
      }        

      if (G_SIGUSR1)
      {
         HandleSigUsr1();
         G_SIGUSR1 = 0;
      }
#endif

   } /* End of main loop */

   /* Got SIGTERM */
   HandleSigTerm();

   return 0;
}