void ShutdownSocketSet::shutdown(int fd, bool abortive) {
  DCHECK_GE(fd, 0);
  if (fd >= maxFd_) {
    doShutdown(fd, abortive);
    return;
  }

  auto& sref = data_[fd];
  uint8_t prevState = IN_USE;
  if (!sref.compare_exchange_strong(prevState,
                                    IN_SHUTDOWN,
                                    std::memory_order_acq_rel)) {
    return;
  }

  doShutdown(fd, abortive);

  prevState = IN_SHUTDOWN;
  if (sref.compare_exchange_strong(prevState,
                                   SHUT_DOWN,
                                   std::memory_order_acq_rel)) {
    return;
  }

  CHECK_EQ(prevState, MUST_CLOSE)
    << "Invalid prev state for fd " << fd << ": " << int(prevState);

  folly::closeNoInt(fd);  // ignore errors, nothing to do

  CHECK(sref.compare_exchange_strong(prevState,
                                     FREE,
                                     std::memory_order_acq_rel))
    << "Invalid prev state for fd " << fd << ": " << int(prevState);
}
Beispiel #2
0
void
TDMShutdown::scheduleShutdown( TQWidget *_parent )
{
	GSet( 1 );
	GSendInt( G_QueryShutdown );
	int how = GRecvInt();
	int start = GRecvInt();
	int timeout = GRecvInt();
	int force = GRecvInt();
	int uid = GRecvInt();
	char *os = GRecvStr();
	GSet( 0 );
	if (how) {
		int ret =
			TDMCancelShutdown( how, start, timeout, force, uid, os,
			                   _parent ).exec();
		if (!ret)
			return;
		doShutdown( 0, 0 );
		uid = ret == Authed ? 0 : -1;
	} else
		uid = -1;
	if (os)
		free( os );
	TDMShutdown( uid, _parent ).exec();
}
Beispiel #3
0
void ProxygenServer::timeoutExpired() noexcept {
  Logger::Info("%p: shutdown timer expired for ProxygenServer port=%d, "
               "state=%d, a/q/e %d/%d/%d", this, m_port, (int)m_shutdownState,
               getActiveWorker(), getQueuedJobs(),
               getLibEventConnectionCount());
  // proceed to next shutdown phase
  doShutdown();
}
Beispiel #4
0
/*!
    \reimp
    Handle cleanup tasks in the event of system shutdown.

    Returns true if all cleanup tasks were successful, otherwise return false. 
*/
bool SecurityMonitorTask::systemShutdown()
{
#ifndef QT_NO_SXE
    doShutdown();
    return true;
#else
    return true;
#endif
}
Beispiel #5
0
void
TDMSlimShutdown::externShutdown( int type, const char *os, int uid )
{
	dpySpec *sess = fetchSessions( lstRemote | lstTTY );
	int ret = TDMConfShutdown( uid, sess, type, os ).exec();
	disposeSessions( sess );
	if (ret == Schedule)
		TDMShutdown( uid ).exec();
	else if (ret)
		doShutdown( type, os );
}
Beispiel #6
0
void ProxygenServer::decrementEnqueuedCount() {
  m_enqueuedCount--;
  if (m_enqueuedCount == 0 && isScheduled()) {
    // If all requests that got enqueued are done, and no more request
    // is coming in, accelerate shutdown.
    if ((m_shutdownState == ShutdownState::DRAINING_READS &&
         m_pendingTransports.empty()) ||
        m_shutdownState == ShutdownState::DRAINING_WRITES) {
      cancelTimeout();
      doShutdown();
    }
  }
}
Beispiel #7
0
 void Server::shutdown()
 {
     {
         Mutex::Lock lock(_mutex);
         
         if(!_running)
         {
             return;
         }
         _running = false;
     }
     
     return doShutdown();
 }
Beispiel #8
0
void ProxygenServer::onConnectionsDrained() {
  ++m_drainCount;
  Logger::Info("All connections drained from ProxygenServer drainCount=%d",
               m_drainCount);
  if (!drained()) {
    // both servers have to finish
    Logger::Verbose("%p: waiting for other server port=%d", this, m_port);
    return;
  }

  // Stop the graceful shutdown timer
  cancelTimeout();

  // proceed to next shutdown phase
  doShutdown();
}
Beispiel #9
0
void ProxygenServer::abortPendingTransports() {
  if (!m_pendingTransports.empty()) {
    Logger::Warning("aborting %lu incomplete requests",
                    m_pendingTransports.size());
    // Avoid iterating the list, as abort() will unlink(), leaving the
    // list iterator in a corrupt state.
    do {
      auto& transport = m_pendingTransports.front();
      transport.abort();                // will unlink()
    } while (!m_pendingTransports.empty());
  }
  // Accelerate shutdown if all requests that were enqueued are done,
  // since no more is coming in.
  if (m_enqueuedCount == 0 &&
      m_shutdownState == ShutdownState::DRAINING_READS) {
    doShutdown();
  }
}
Beispiel #10
0
void ProxygenServer::stopListening(bool hard) {
  m_shutdownState = ShutdownState::DRAINING_READS;

#define SHUT_FBLISTEN 3
  /*
   * Modifications to the Linux kernel to support shutting down a listen
   * socket for new connections only, but anything which has completed
   * the TCP handshake will still be accepted.  This allows for un-accepted
   * connections to be queued and then wait until all queued requests are
   * actively being processed.
   */

  // triggers acceptStopped/sets acceptor state to Draining
  if (hard) {
    m_httpServerSocket.reset();
    m_httpsServerSocket.reset();
  } else {
    if (m_httpServerSocket) {
      m_httpServerSocket->stopAccepting(SHUT_FBLISTEN);
    }
    if (m_httpsServerSocket) {
      m_httpsServerSocket->stopAccepting(SHUT_FBLISTEN);
    }
  }

  if (RuntimeOption::ServerShutdownListenWait > 0) {
    std::chrono::seconds s(RuntimeOption::ServerShutdownListenWait);
    VLOG(4) << this << ": scheduling shutdown listen timeout=" <<
      s.count() <<
      " port=" << m_port;
    scheduleTimeout(s);
    if (RuntimeOption::ServerShutdownEOMWait > 0) {
      int delayMilliSeconds = RuntimeOption::ServerShutdownEOMWait * 1000;
      m_worker.getEventBase()->runAfterDelay(
        [this] { abortPendingTransports(); }, delayMilliSeconds);
    }
  } else {
    doShutdown();
  }
}
Beispiel #11
0
// this just wraps ALL the code in total catch block
int Kernel::run(int argc, char const * argv[], const std::string& appName)
{
    m_appName = appName;

    ProgramArgs args;

    try
    {
        doSwitches(argc, argv, args);
    }
    catch (const pdal_error& e)
    {
        Utils::printError(e.what());
        return 1;
    }

    if (m_showHelp)
    {
        outputHelp(args);
        return 0;
    }

    int startup_status = doStartup();
    if (startup_status)
        return startup_status;

    int execution_status = doExecution(args);

    // note we will try to shutdown cleanly even if we got an error condition
    // in the execution phase

    int shutdown_status = doShutdown();

    if (execution_status)
        return execution_status;

    return shutdown_status;
}
Beispiel #12
0
int main(int argc,char ** argv)
{
    int shmid = shmget(SHARED_KEY, sizeof(DasaServerInfo), 0666);
    if (shmid  < 0) {
        perror("dasademo shmget");
        return -1;
    }

    /*
     * Now we attach the segment to our data space.
     */
     requestState = shmat(shmid, NULL, 0);
    if (requestState  == (DasaServerInfo *) -1) {
        perror("dasademo shmat");
        return -2;
    }

  if (argc < 2)
    {
      fprintf(stderr,"No argument given to DASA\n");
      exit(3);
    }

  if (strcasecmp(argv[1],"x") == 0 || strcasecmp(argv[1],"y") == 0 || strcasecmp(argv[1],"z") == 0)
    return processPositionCommand(argc,argv);
  if (strcasecmp(argv[1],"on") == 0)
    return doOnCommand();
  if (strcasecmp(argv[1],"shutdown") == 0)
    return doShutdown();
  if (strcasecmp(argv[1],"off") == 0)
    return doOffCommand();
  if (strcasecmp(argv[1],"mode") == 0)
    {
       if (argc < 3)
         {
           fprintf(stderr,"No mode given for MODE command\n");
           exit(3);
         }
       if (strcasecmp(argv[2],"shower") == 0)
         return doModeCommand(SHOWER);
       if (strcasecmp(argv[2],"jet") == 0)
         return doModeCommand(JET);
       if (strcasecmp(argv[2],"rain") == 0)
         return doModeCommand(RAIN);
       if (strcasecmp(argv[2],"massage") == 0)
         return doModeCommand(MASSAGE);
       fprintf(stderr,"Unknown mode %s given for MODE command\n",argv[2]);
       exit(3);
     }
  if (strcasecmp(argv[1],"temp") == 0)
    {
       if (argc < 3)
         {
           fprintf(stderr,"No temperature given for TEMP command\n");
           return -1;
         }
      int temp = atoi(argv[2]);
      return doTempCommand(temp);
     }
  fprintf(stderr,"Unknown command %s given to DASA\n",argv[1]);
  exit(3);
}
DefaultOperationTcpChannel::~DefaultOperationTcpChannel()
{
    if (!isShutdown_) {
        doShutdown();
    }
}
Beispiel #14
0
bool InProcessNode::shutdown() {
  return doShutdown();
}
Beispiel #15
0
InProcessNode::~InProcessNode() {
  doShutdown();
}
Beispiel #16
0
void
TDMSlimShutdown::slotReboot( int opt )
{
	if (checkShutdown( SHUT_REBOOT, targetList[opt] ))
		doShutdown( SHUT_REBOOT, targetList[opt] );
}
Beispiel #17
0
void
TDMSlimShutdown::slotReboot()
{
	if (checkShutdown( SHUT_REBOOT, 0 ))
		doShutdown( SHUT_REBOOT, 0 );
}
Beispiel #18
0
void
TDMSlimShutdown::slotHalt()
{
	if (checkShutdown( SHUT_HALT, 0 ))
		doShutdown( SHUT_HALT, 0 );
}
Beispiel #19
0
 void Process::shutdown()
   { doShutdown(); }
Beispiel #20
0
 void Process::restart()
 {
   _exitRestart = true;
   doShutdown();
 }
Beispiel #21
0
void KaaChannelManager::shutdown()
{
    doShutdown();
}
void DefaultOperationTcpChannel::shutdown()
{
    doShutdown();
}
/*!
  \reimp
  */
bool ApplicationShutdownTask::systemShutdown()
{
    return doShutdown();
}
Beispiel #24
0
 bool shutdown(void)
 {
   return doShutdown();
 }
Beispiel #25
0
static void OSNetworkSystem_shutdownOutput(JNIEnv* env, jobject, jobject fd) {
    doShutdown(env, fd, SHUT_WR);
}