Example #1
0
int
main(int argc, char *argv[])
{
    struct timespec_t ts;

    if(argc <= 1) {
        fprintf(stderr, "error: no timespec specified (use -h for help)\n");
        help(stderr, argv[0]);
    }

    memset(&ts, 0, sizeof(struct timespec_t));

    if(parse_options(argc, argv) != 0) {
        return 1;
    }

    if(parse_timespec(optind, argc, argv, &ts) != 0) {
        return 2;
    }

    if(create_alarm(&ts) != 0) {
        return 3;
    }

    if(do_suspend(suspend_cmd ? suspend_cmd : SUSPEND_COMMAND) != 0) {
        return 4;
    }

    pthread_exit(NULL);
    return EXIT_SUCCESS;
}
Example #2
0
bool
ServerOptions::
init(Parameter const& P)
{
  P.SetParameter(this->port, "server-port", 8080);
  P.SetParameter(this->is_serial, "serial", false);
  P.SetParameter(this->logfile, "server-log", std::string("/dev/null"));
  P.SetParameter(this->num_threads, "threads", uint32_t(10));
  P.SetParameter(this->session_cache_size, "session-cache_size",25UL);
  std::string timeout_spec;
  P.SetParameter(timeout_spec, "session-timeout",std::string("30m"));
  this->session_timeout = parse_timespec(timeout_spec);
  return true;
}
Example #3
0
static void
set_param (OCState * state, char * key, char * val)
{
    char * sep;

    if (!strncmp ("s", key, 2)) state->start = parse_timespec (val);
    if (!strncmp ("start", key, 6)) state->start = parse_timespec (val);

    if (!strncmp ("e", key, 2)) state->end = parse_timespec (val);
    if (!strncmp ("end", key, 6)) state->end = parse_timespec (val);

    if (!strncmp ("t", key, 2)) {
        if (val && (sep = strchr (val, '/')) != NULL) {
            *sep++ = '\0';
            state->end = parse_timespec (sep);
        } else {
            state->end = -1.0;
        }
        state->start = parse_timespec (val);
    }
}
Example #4
0
int
cmd_main (OCState * state, int argc, char * argv[])
{
  int show_version = 0;
  int show_help = 0;
  int i;

  char * optstring = "s:e:o:knhvV";

#ifdef HAVE_GETOPT_LONG
  static struct option long_options[] = {
    {"start",    required_argument, 0, 's'},
    {"end",      required_argument, 0, 'e'},
    {"output",   required_argument, 0, 'o'},
    {"no-skeleton", no_argument, 0, 'k'},
    {"dry-run",  no_argument, 0, 'n'},
    {"help",     no_argument, 0, 'h'},
    {"version",  no_argument, 0, 'v'},
    {"verbose",  no_argument, 0, 'V'},
    {0,0,0,0}
  };
#endif

  progname = argv[0];

  if (argc < 2) {
    usage (progname);
    return (1);
  }

  if (!strncmp (argv[1], "-?", 2)) {
#ifdef HAVE_GETOPT_LONG
    ot_print_options (long_options, optstring);
#else
    ot_print_short_options (optstring);
#endif
    exit (0);
  }

  memset (state, 0, sizeof(*state));
  state->end = -1.0;
  state->do_skeleton = 1;

  while (1) {
#ifdef HAVE_GETOPT_LONG
    i = getopt_long(argc, argv, optstring, long_options, NULL);
#else
    i = getopt (argc, argv, optstring);
#endif
    if (i == -1) break;
    if (i == ':') {
      usage (progname);
      goto exit_err;
    }

    switch (i) {
    case 's': /* start */
      state->start = parse_timespec (optarg);
      break;
    case 'e': /* end */
      state->end = parse_timespec (optarg);
      break;
    case 'k': /* no-skeleton */
      state->do_skeleton = 0;
      break;
    case 'n': /* dry-run */
      state->dry_run = 1;
      break;
    case 'h': /* help */
      show_help = 1;
      break;
    case 'v': /* version */
      show_version = 1;
      break;
    case 'V': /* verbose */
      state->verbose = 1;
      break;
    case 'o': /* output */
      state->outfilename = optarg;
      break;
    default:
      break;
    }
  }

  if (show_version) {
    version (stdout);
  } else if (state->verbose) {
    version (stderr);
  }

  if (show_help) {
    usage (progname);
  }

  if (show_version || show_help) {
    goto exit_ok;
  }

  if (optind >= argc) {
    usage (progname);
    goto exit_err;
  }

  state->infilename = argv[optind++];

  return chop (state);

exit_ok:
  return 0;

exit_err:
  return 1;
}