コード例 #1
0
void dsk_daemon_add_cmdline_args (dsk_boolean with_dsk_prefix)
{
  unsigned skip = with_dsk_prefix ? 0 : strlen ("dsk-");

#define MAYBE_SKIP_DSK_PREFIX(static_string, skip) \
  &(static_string[skip])

  dsk_cmdline_add_boolean (MAYBE_SKIP_DSK_PREFIX("dsk-fork", skip),
                           "fork and run in the background",
			   NULL, 0, &dsk_daemon_do_fork);

  dsk_cmdline_add_boolean (MAYBE_SKIP_DSK_PREFIX("dsk-watchdog", skip),
                           "restart if the program dies",
			   NULL, 0, &dsk_daemon_watchdog);

  dsk_cmdline_add_string  (MAYBE_SKIP_DSK_PREFIX("dsk-pid-filename", skip),
                           "file to write PID to, lock",
			   "FILENAME", 0, &dsk_daemon_pid_filename);

  dsk_cmdline_add_func    (MAYBE_SKIP_DSK_PREFIX("dsk-log-template", skip),
                           "redirect stdout and stderr to the given file",
			   "STRFTIME_FILENAME", 0, handle_dsk_log_template, NULL);
  dsk_cmdline_add_func    (MAYBE_SKIP_DSK_PREFIX("dsk-log-timezone", skip),
                           "use timezone for filenames and logs",
			   "TZSPEC", 0, handle_dsk_log_timezone, NULL);

  dsk_cmdline_add_string  (MAYBE_SKIP_DSK_PREFIX("dsk-alert-script", skip),
                           "for the watchdog to run if the subprocess terminates",
			   "SCRIPT", 0, &dsk_daemon_alert_script);
  dsk_cmdline_add_uint    (MAYBE_SKIP_DSK_PREFIX("dsk-alert-interval", skip),
                           "minimum time between invocation of alert script",
			   "SECONDS", 0, &dsk_daemon_alert_interval);

#undef MAYBE_SKIP_DSK_PREFIX
}
コード例 #2
0
ファイル: test-table-file-0.c プロジェクト: davebenson/dsk
int main(int argc, char **argv)
{
  unsigned i;
  char test_dir_buf[256];
  DskError *error = NULL;

  dsk_cmdline_init ("test table internals (the 'file' abstraction)",
                    "Test Table Internals",
                    NULL, 0);
  dsk_cmdline_add_boolean ("verbose", "extra logging", NULL, 0,
                           &cmdline_verbose);
  dsk_cmdline_add_boolean ("slow", "run tests that are fairly slow", NULL, 0,
                           &cmdline_slow);
  dsk_cmdline_add_boolean ("keep-testdir", "do not delete working directory", NULL, 0,
                           &cmdline_keep_testdir);
  dsk_cmdline_process_args (&argc, &argv);

  snprintf (test_dir_buf, sizeof (test_dir_buf),
            "test-table-file-%u-%u", (unsigned)time(NULL), (unsigned)getpid());
  location = dsk_dir_new (NULL, test_dir_buf, DSK_DIR_NEW_MAYBE_CREATE, &error);
  if (location == NULL)
    dsk_die ("error making directory: %s", error->message);

  for (i = 0; i < DSK_N_ELEMENTS (tests); i++)
    {
      fprintf (stderr, "Test: %s... ", tests[i].name);
      tests[i].test ();
      fprintf (stderr, " done.\n");
    }

  if (cmdline_keep_testdir)
    {
      fprintf (stderr,
               "test-table-file: keep-testdir: preserving test directory %s\n",
               dsk_dir_get_str (location));
    }
  else
    {
      DskError *error = NULL;
      if (!dsk_remove_dir_recursive (dsk_dir_get_str (location), &error))
        dsk_die ("error removing directory %s: %s",
                 dsk_dir_get_str (location), error->message);
    }
  dsk_cleanup ();
  return 0;
}
コード例 #3
0
int main(int argc, char **argv)
{
  DskDnsConfigFlags cfg_flags = DSK_DNS_CONFIG_FLAGS_INIT;
  dsk_boolean no_searchpath = DSK_FALSE;
  int i;
  dsk_cmdline_init ("perform DNS lookups",
                    "Perform DNS lookups with Dsk DNS client.\n",
                    "HOSTNAMES...",
                    0);
  dsk_cmdline_permit_extra_arguments (DSK_TRUE);
  dsk_cmdline_add_boolean ("ipv6", "Lookup names in the IPv6 namespace", NULL, 0, &use_ipv6);
  dsk_cmdline_add_boolean ("ipv4", "Lookup names in the IPv4 namespace", NULL, DSK_CMDLINE_REVERSED, &use_ipv6);
  dsk_cmdline_add_boolean ("cname", "Return CNAME or POINTER records if they arise", NULL, 0, &no_links);
  dsk_cmdline_add_string ("nameserver", "Specify the nameserver to use", "IP", 0, &nameserver);
  dsk_cmdline_add_boolean ("verbose", "Print extra messages", NULL, 0, &verbose);
  dsk_cmdline_add_boolean ("no-searchpath", "Do not use /etc/resolv.conf's searchpath", NULL, 0, &no_searchpath);
  dsk_cmdline_add_boolean ("fatal-errors", "Exit on first error", NULL, 0, &fatal_errors);
  dsk_cmdline_process_args (&argc, &argv);

  if (no_searchpath)
    cfg_flags &= ~DSK_DNS_CONFIG_USE_RESOLV_CONF_SEARCHPATH;

  if (nameserver == NULL)
    {
      /* just use default config */
    }
  else
    {
      DskIpAddress addr;
      cfg_flags &= ~DSK_DNS_CONFIG_USE_RESOLV_CONF_NS;
      if (!dsk_ip_address_parse_numeric (nameserver, &addr))
        dsk_error ("error parsing nameserver address (must be numeric)");
      dsk_dns_client_add_nameserver (&addr);
    }
  dsk_dns_client_config (cfg_flags);
  if (verbose)
    {
      dsk_dns_config_dump ();
    }

  if (argc == 1)
    dsk_error ("expected name to resolve");
  for (i = 1; i < argc; i++)
    {
      n_running++;
      dsk_dns_lookup (argv[i],
                      use_ipv6,
                      handle_dns_result,
                      argv[i]);
      while (n_running >= max_concurrent)
        dsk_main_run_once ();
    }
  dsk_dispatch_destroy_default ();
  return exit_status;
}
コード例 #4
0
int main(int argc, char **argv)
{
  unsigned i;

  dsk_cmdline_init ("test HTTP-Header parsing",
                    "Test the HTTP-Header Parsing Code",
                    NULL, 0);
  dsk_cmdline_add_boolean ("verbose", "extra logging", NULL, 0,
                           &cmdline_verbose);
  dsk_cmdline_process_args (&argc, &argv);

  for (i = 0; i < DSK_N_ELEMENTS (tests); i++)
    {
      fprintf (stderr, "Test: %s... ", tests[i].name);
      tests[i].test ();
      fprintf (stderr, " done.\n");
    }
  dsk_cleanup ();
  return 0;
}