Esempio n. 1
0
void init(int argc, char* argv[]) {
    // set global data
    default_config();
    default_timeout();
    default_systray();
    memset(&server, 0, sizeof(Server_global));
#ifdef ENABLE_BATTERY
    default_battery();
#endif
    default_clock();
    default_launcher();
    default_taskbar();
    default_tooltip();
    default_panel();

    // read options
    for (int i = 1; i < argc; ++i) {
        if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
            DIE("Usage: tinto [-c] <config_file>\n");
        } else if (strcmp(argv[i], "-v") == 0 ||
                   strcmp(argv[i], "--version") == 0) {
            DIE("tinto version %s\n", VERSION_STRING);
        } else if (strcmp(argv[i], "-c") == 0) {
            if (++i < argc) config_path = strdup(argv[i]);
        } else if (strcmp(argv[i], "-s") == 0) {
            if (++i < argc) snapshot_path = strdup(argv[i]);
        }
    }

    // Set signal handler
    signal_pending = 0;
    struct sigaction sa = {.sa_handler = signal_handler};
    struct sigaction sa_chld = {.sa_handler = SIG_DFL, .sa_flags = SA_NOCLDWAIT};
    sigaction(SIGUSR1, &sa, NULL);
    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGCHLD, &sa_chld, NULL);

    // BSD does not support pselect(), therefore we have to use select and hope
    // that we do not
    // end up in a race condition there (see 'man select()' on a linux machine for
    // more information)
    // block all signals, such that no race conditions occur before pselect in our
    // main loop
    //	sigset_t block_mask;
    //	sigaddset(&block_mask, SIGINT);
    //	sigaddset(&block_mask, SIGTERM);
    //	sigaddset(&block_mask, SIGHUP);
    //	sigaddset(&block_mask, SIGUSR1);
    //	sigprocmask(SIG_BLOCK, &block_mask, 0);
}
Esempio n. 2
0
void
tinto_init (int argc, char *argv[]) {
  default_config ();
  default_timeout ();
  default_systray();
  memset (&server, 0, sizeof (Server_global));
#ifdef ENABLE_BATTERY
  default_battery ();
#endif // ENABLE_BATTERY
  default_clock ();
  default_launcher ();
  default_taskbar ();
  default_tooltip ();
  panel_default ();

  for (int i = 1; i < argc; ++i) {
    if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "--help") == 0) {
      tinto_usage ();
    }

    else if (strcmp (argv[i], "-v") == 0 ||
	     strcmp (argv[i], "--version") == 0) {
      MSG ("%s version %s\n", PROJECT_NAME, PROJECT_VERSION);
      exit (EXIT_SUCCESS);
    }
    else if (strcmp (argv[i], "-c") == 0
	     || strcmp (argv[i], "--config-file") == 0) {
      if (++i < argc) config_path = strdup (argv[i]);
    }
    else if (strcmp (argv[i], "-s") == 0
	     || strcmp (argv[i], "--panel-snapshot") == 0) {
      if (++i < argc) snapshot_path = strdup (argv[i]);
    }
    else {
      MSG ("Invalid argument!");
      tinto_usage ();
    }
  }

  // Isn't this initialization redundant? Since `pending_signal'
  // is static and all?
  pending_signal = 0;
  struct sigaction sa = { .sa_handler = tinto_signal_handler };
  struct sigaction sa_chld = {
    .sa_handler = SIG_DFL,
    .sa_flags = SA_NOCLDWAIT
  };
  sigaction(SIGUSR1, &sa, NULL);
  sigaction(SIGINT, &sa, NULL);
  sigaction(SIGTERM, &sa, NULL);
  sigaction(SIGHUP, &sa, NULL);
  sigaction(SIGCHLD, &sa_chld, NULL);

  // BSD does not support pselect(), therefore we have to use select and hope that we do not
  // end up in a race condition there (see 'man select()' on a linux machine for more information)
  // block all signals, such that no race conditions occur before pselect in our main loop
  //	sigset_t block_mask;
  //	sigaddset(&block_mask, SIGINT);
  //	sigaddset(&block_mask, SIGTERM);
  //	sigaddset(&block_mask, SIGHUP);
  //	sigaddset(&block_mask, SIGUSR1);
  //	sigprocmask(SIG_BLOCK, &block_mask, 0);

  tinto_init_x11 ();
}