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)
{
  unsigned port = 0;
  DskHttpServer *server;
  unsigned i;
  DskError *error = NULL;

  dsk_cmdline_init ("snipez server", "Run a snipez server", NULL, 0);
  dsk_cmdline_add_uint ("port", "Port Number",
                        "PORT", DSK_CMDLINE_MANDATORY, &port);
  dsk_cmdline_add_uint ("update-period", "Update Period",
                        "MILLIS", 0, &update_period_msecs);
  dsk_cmdline_add_func ("make-maze", "Make a Maze",
                        "WIDTHxHEIGHT", DSK_CMDLINE_OPTIONAL,
                        handle_make_maze, NULL);
  dsk_cmdline_add_shortcut ('p', "port");
  dsk_cmdline_process_args (&argc, &argv);

  server = dsk_http_server_new ();
  for (i = 0; i < DSK_N_ELEMENTS (handlers); i++)
    {
      dsk_http_server_match_save (server);
      dsk_http_server_add_match (server, DSK_HTTP_SERVER_MATCH_PATH,
                                 handlers[i].pattern);
      dsk_http_server_register_cgi_handler (server,
                                            (DskHttpServerCgiFunc) handlers[i].handler,
                                            NULL, NULL);
      dsk_http_server_match_restore (server);
    }
  if (!dsk_http_server_bind_tcp (server, NULL, port, &error))
    dsk_die ("error binding to port %u: %s", port, error->message);

  return dsk_main_run ();
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  /* Process command-line arguments. */
  dsk_cmdline_init ("a ??? HTTP-Proxy Server",
                    "Run a simple HTTP Proxy.",
                    NULL, 0);
  dsk_cmdline_add_func ("port", "port to listen on", "PORT",
                        DSK_CMDLINE_MANDATORY,
                        handle_port, NULL);
  dsk_cmdline_process_args (&argc, &argv);

  /* Run forever. */
  return dsk_main_run ();
}