Пример #1
0
void
test_cancel2(void) {
  gallus_result_t r;
  shutdown_grace_level_t l;
  null_thread_t nt = NULL;

  global_state_reset();

  r = global_state_set(GLOBAL_STATE_INITIALIZING);
  TEST_ASSERT_EQUAL(r, GALLUS_RESULT_OK);

  r = s_null_create(&nt, SHUTDOWN_GRACEFULLY);
  TEST_ASSERT_EQUAL(r, GALLUS_RESULT_OK);

  r = gallus_thread_start((gallus_thread_t *)&nt, false);
  TEST_ASSERT_EQUAL(r, GALLUS_RESULT_OK);

  r = global_state_set(GLOBAL_STATE_STARTED);
  TEST_ASSERT_EQUAL(r, GALLUS_RESULT_OK);

  gallus_msg_debug(1, "waiting for shutdown request ...\n");
  while ((r = global_state_wait_for_shutdown_request(
                &l, 1000LL * 1000LL * 100LL)) == GALLUS_RESULT_TIMEDOUT) {
    gallus_msg_debug(1, "still waiting for shutdown request ...\n");
  }
  if (r != GALLUS_RESULT_OK) {
    gallus_perror(r);
  }
  TEST_ASSERT_EQUAL(r, GALLUS_RESULT_OK);
  TEST_ASSERT_EQUAL(l, SHUTDOWN_GRACEFULLY);

  gallus_thread_destroy((gallus_thread_t *)&nt);
}
Пример #2
0
static inline int
s_do_main(int argc, const char *const argv[], int ipcfd) {
  lagopus_result_t st = LAGOPUS_RESULT_ANY_FAILURES;

  lagopus_msg_info("Initializing all the modules.\n");

  (void)global_state_set(GLOBAL_STATE_INITIALIZING);

  if ((st = lagopus_module_initialize_all(argc,
                                          (const char *const *)argv)) ==
      LAGOPUS_RESULT_OK &&
      s_got_term_sig == false) {

    lagopus_msg_info("All the modules are initialized.\n");

    lagopus_msg_info("Starting all the modules.\n");

    (void)global_state_set(GLOBAL_STATE_STARTING);
    if ((st = lagopus_module_start_all()) ==
        LAGOPUS_RESULT_OK &&
        s_got_term_sig == false) {
      shutdown_grace_level_t l = SHUTDOWN_UNKNOWN;

      lagopus_msg_info("All the modules are started and ready to go.\n");

      config_propagate_lagopus_conf();

      (void)global_state_set(GLOBAL_STATE_STARTED);

      if (ipcfd >= 0) {
        int zero = 0;
        (void)write(ipcfd, (void *)&zero, sizeof(int));
        (void)close(ipcfd);
        ipcfd = -1;
      }

      lagopus_msg_info("The Lagopus is a go.\n");

      s_gen_pidfile();

      while ((st = global_state_wait_for_shutdown_request(&l,
                   REQ_TIMEDOUT)) ==
             LAGOPUS_RESULT_TIMEDOUT) {
        lagopus_msg_debug(5, "Waiting for the shutdown request...\n");
      }
      if (st == LAGOPUS_RESULT_OK) {
        (void)global_state_set(GLOBAL_STATE_ACCEPT_SHUTDOWN);
        if ((st = lagopus_module_shutdown_all(l)) == LAGOPUS_RESULT_OK) {
          if ((st = lagopus_module_wait_all(s_to)) == LAGOPUS_RESULT_OK) {
            lagopus_msg_info("Shutdown succeeded.\n");
          } else if (st == LAGOPUS_RESULT_TIMEDOUT) {
          do_cancel:
            lagopus_msg_warning("Trying to stop forcibly...\n");
            if ((st = lagopus_module_stop_all()) == LAGOPUS_RESULT_OK) {
              if ((st = lagopus_module_wait_all(s_to)) ==
                  LAGOPUS_RESULT_OK) {
                lagopus_msg_warning("Stopped forcibly.\n");
              }
            }
          }
        } else if (st == LAGOPUS_RESULT_TIMEDOUT) {
          goto do_cancel;
        }
      }
    }
  }

  lagopus_module_finalize_all();

  if (st != LAGOPUS_RESULT_OK) {
    lagopus_msg_warning("Bailed out, anyway. The latest result status is:"
                        "%s\n", lagopus_error_get_string(st));
    if (ipcfd >= 0) {
      int one = 1;
      (void)write(ipcfd, (void *)&one, sizeof(int));
      (void)close(ipcfd);
    }
  }

  s_del_pidfile();

  return (st == LAGOPUS_RESULT_OK) ? 0 : 1;
}