Start of hostinfo daemon / play with APR.
[virt-hostinfo.git] / hostinfod / main.c
diff --git a/hostinfod/main.c b/hostinfod/main.c
new file mode 100644 (file)
index 0000000..bb915ca
--- /dev/null
@@ -0,0 +1,81 @@
+/* virt-hostinfo
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <apr_general.h>
+#include <apr_network_io.h>
+#include <apr_getopt.h>
+
+static void usage (void);
+
+int
+main (int argc, char *argv[])
+{
+  static const apr_getopt_option_t options[] = {
+    { "help", '?', FALSE, "display help" },
+    { NULL, 0, 0, NULL },
+  };
+  apr_status_t r;
+  apr_pool_t *mp;
+  apr_getopt_t *opt;
+  int c;
+  const char *optarg;
+        
+  apr_initialize ();
+  apr_pool_create (&mp, NULL);
+
+  apr_getopt_init (&opt, mp, argc, argv);
+
+  while ((r = apr_getopt_long (opt, options, &c, &optarg)) == APR_SUCCESS) {
+    switch (c) {
+    case '?':
+      usage ();
+      exit (0);
+    default:
+      abort ();
+    }
+  }
+  if (r != APR_EOF) {
+    fprintf (stderr, "%s: unknown command line option\n", argv[0]);
+    exit (1);
+  }
+
+  apr_terminate ();
+  return 0;
+}
+
+static void
+usage (void)
+{
+  printf ("hostinfod (virt-hostinfo daemon)\n"
+         "Copyright (C) 2009 Red Hat Inc.\n"
+         "\n"
+         "Usage:\n"
+         "  hostinfod [-d] [-f]\n"
+         "\n"
+         "Options:\n"
+         "  --help     Display full usage\n"
+         "  -d         Enable verbose debug messages\n"
+         "  -f         Run in the foreground (don't fork)\n");
+}