Example #1
0
void test_event_init()
{
  scheduler_t* scheduler;
  scheduler = scheduler_init(testdb, NULL);
  scheduler_foss_config(scheduler);

  event_t* e;

  sample_args = &call_num;
  e = event_init(sample_event, sample_args, "sample", s_name, s_line);

  FO_ASSERT_PTR_EQUAL(   e->func,     sample_event);
  FO_ASSERT_PTR_EQUAL(   e->argument, sample_args);
  FO_ASSERT_STRING_EQUAL(e->name,     "sample");

  g_free(e);
  scheduler_destroy(scheduler);
}
Example #2
0
void test_event_loop_take()
{
  event_t* retval;
  scheduler_t* scheduler;
  scheduler = scheduler_init(testdb, NULL);
  scheduler_foss_config(scheduler);
  event_loop_t* vl = event_loop_get();

  vl->occupied = 0;
  vl->terminated = 1;

  retval = event_loop_take(vl);
  FO_ASSERT_PTR_NULL(retval);
  FO_ASSERT_FALSE(vl->occupied);
  FO_ASSERT_TRUE(vl->terminated);

  scheduler_destroy(scheduler);
}
Example #3
0
void test_event_loop_put()
{
  scheduler_t* scheduler;
  scheduler = scheduler_init(testdb, NULL);
  scheduler_foss_config(scheduler);
  event_t* e;

  sample_args = &call_num;
  event_signal(sample_event, sample_args);

  e = g_async_queue_pop(event_loop_get()->queue);

  FO_ASSERT_PTR_EQUAL(   e->func,     sample_event);
  FO_ASSERT_PTR_EQUAL(   e->argument, sample_args);
  FO_ASSERT_STRING_EQUAL(e->name,     "sample_event");

  event_loop_put(event_loop_get(),e);
  scheduler_destroy(scheduler);
}
Example #4
0
void test_event_loop_terminate()
{
  int retval = 0;
  scheduler_t* scheduler;
  scheduler = scheduler_init(testdb, NULL);
  scheduler_foss_config(scheduler);
  event_loop_t* vl = event_loop_get();

  vl->occupied = 0;
  vl->terminated = 1;

  event_signal(terminate_event, NULL);
  retval = event_loop_enter(scheduler, NULL, NULL);
  FO_ASSERT_EQUAL(retval, 0x0);
  FO_ASSERT_FALSE(vl->occupied);
  FO_ASSERT_TRUE(vl->terminated);

  scheduler_destroy(scheduler);
}
Example #5
0
/**
 * main function for FOSSology scheduler, does command line parsing,
 * Initialization and then simply enters the event loop.
 *
 * @param argc the command line argument cound
 * @param argv the command line argument values
 * @return if the program ran correctly
 */
int main(int argc, char** argv)
{
  /* locals */
  gboolean db_reset = FALSE;  // flag to reset the job queue upon database connection
  gboolean ki_kill  = FALSE;  // flag that indicates all schedulers should be forcibly shutdown
  gboolean ki_shut  = FALSE;  // flag that indicates all schedulers should be gracefully shutdown
  gboolean db_init  = FALSE;  // flag indicating a database test
  gboolean test_die = FALSE;  // flag to run the tests then die
  gboolean s_daemon = FALSE;  // falg to run the scheduler as a daemon
  gchar* logdir = NULL;       // used when a different log from the default is used
  GOptionContext* options;    // option context used for command line parsing
  GError* error = NULL;       // error object used during parsing
  uint16_t port = 0;
  gchar* sysconfigdir = DEFAULT_SETUP;

  /* THE SCHEDULER */
  scheduler_t* scheduler;

  if(getenv("FO_SYSCONFDIR") != NULL)
    sysconfigdir = getenv("FO_SYSCONFDIR");

  /* get this done first */
  srand(time(NULL));
#if !(GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 32)
  g_thread_init(NULL);
#endif
#if !(GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 36)
  g_type_init();
#endif

  /* the options for the command line parser */
  GOptionEntry entries[] =
  {
      { "daemon",   'd', 0, G_OPTION_ARG_NONE,   &s_daemon,     "      Run scheduler as daemon"                       },
      { "database", 'i', 0, G_OPTION_ARG_NONE,   &db_init,      "      Initialize database connection and exit"       },
      { "kill",     'k', 0, G_OPTION_ARG_NONE,   &ki_kill,      "      Forcibly kills all running schedulers"         },
      { "shutdown", 's', 0, G_OPTION_ARG_NONE,   &ki_shut,      "      Gracefully shutdown of all running schedulers" },
      { "log",      'L', 0, G_OPTION_ARG_STRING, &logdir,       "[str] Specify location of log file"                  },
      { "port",     'p', 0, G_OPTION_ARG_INT,    &port,         "[num] Set the interface port"                        },
      { "reset",    'R', 0, G_OPTION_ARG_NONE,   &db_reset,     "      Reset the job queue upon startup"              },
      { "test",     't', 0, G_OPTION_ARG_NONE,   &test_die,     "      Close the scheduler after running tests"       },
      { "verbose",  'v', 0, G_OPTION_ARG_INT,    &verbose,      "[num] Set the scheduler verbose level"               },
      { "config",   'c', 0, G_OPTION_ARG_STRING, &sysconfigdir, "[str] Specify system configuration directory"        },
      {NULL}
  };

  /* ********************* */
  /* *** parse options *** */
  /* ********************* */
  options = g_option_context_new("- scheduler for FOSSology");
  g_option_context_add_main_entries(options, entries, NULL);
  g_option_context_parse(options, &argc, &argv, &error);

  if(error)
  {
    fprintf(stderr, "ERROR: %s\n", error->message);
    fprintf(stderr, "%s", g_option_context_get_help(options, FALSE, NULL));
    fflush(stderr);
    return -1;
  }

  g_option_context_free(options);

  /* check changes to the process first */
  if(ki_shut) { return kill_scheduler(FALSE); }
  if(ki_kill) { return kill_scheduler(TRUE);  }

  /* initialize the scheduler */
  scheduler = scheduler_init(sysconfigdir,
      log_new("stdout", "initializing", getpid()));

  if(logdir)
  {
    scheduler->logdir     = logdir;
    scheduler->logcmdline = TRUE;
    scheduler->main_log   = log_new(scheduler->logdir, NULL, scheduler->s_pid);

    log_destroy(main_log);
    main_log = scheduler->main_log;
  }

  scheduler->process_name = g_strdup(argv[0]);
  scheduler->s_daemon     = s_daemon;

  scheduler_foss_config(scheduler);
  if(s_daemon && scheduler_daemonize(scheduler) == -1) { return -1; }
  scheduler_agent_config(scheduler);

  database_init(scheduler);
  email_init(scheduler);

  NOTIFY("*****************************************************************");
  NOTIFY("***                FOSSology scheduler started                ***");
  NOTIFY("***        pid:      %-33d        ***", getpid());
  NOTIFY("***        verbose:  %-33d        ***", verbose);
  NOTIFY("***        config:   %-33s        ***", sysconfigdir);
  NOTIFY("*****************************************************************");

  interface_init(scheduler);
  fo_RepOpenFull(scheduler->sysconfig);

  signal(SIGCHLD, scheduler_sig_handle);
  signal(SIGTERM, scheduler_sig_handle);
  signal(SIGQUIT, scheduler_sig_handle);
  signal(SIGHUP,  scheduler_sig_handle);

  /* ***************************************************** */
  /* *** we have finished initialization without error *** */
  /* ***************************************************** */

  if(db_reset)
    database_reset_queue(scheduler);
  if(test_die)
    closing = 1;
  event_loop_enter(scheduler, scheduler_update, scheduler_signal);

  NOTIFY("*****************************************************************");
  NOTIFY("***                FOSSology scheduler closed                 ***");
  NOTIFY("***        pid:     %-34d        ***", scheduler->s_pid);
  NOTIFY("*****************************************************************\n");

  interface_destroy(scheduler);
  scheduler_destroy(scheduler);
  return 0;
}