Ejemplo n.º 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
}
Ejemplo n.º 2
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;
}