/*
* The Remote User Information Daemon
*
- * (c) 1997--2010 Martin Mares <mj@ucw.cz>
+ * (c) 1997--2017 Martin Mares <mj@ucw.cz>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
+#include <getopt.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
u32 addr;
};
+static int do_not_daemonize;
static int sock, port;
static struct hostrec *first_host;
static time_t now, last_local_scan;
static void
daemonize(void)
{
+ if (do_not_daemonize)
+ return;
+
pid_t pid = fork();
if (pid < 0)
die("Fork failed: %m");
}
}
+static void
+usage(void)
+{
+ fprintf(stderr, "Usage: nwhod [-d] [<server>]\n");
+ exit(1);
+}
+
int
main(int argc, char **argv)
{
return 0;
}
- if (argc == 2)
- client(argv[1]);
- else if (argc == 1)
+ int opt;
+ while ((opt = getopt(argc, argv, "d")) >= 0)
+ switch (opt)
+ {
+ case 'd':
+ do_not_daemonize = 1;
+ break;
+ default:
+ usage();
+ }
+
+ if (optind == argc-1)
+ client(argv[optind]);
+ else if (optind == argc)
server();
else
- {
- fprintf(stderr, "Usage: nwhod [<server>]\n");
- return 1;
- }
+ usage();
return 0;
}