#include <limits.h>
#include <signal.h>
#include <unistd.h>
+#include <fcntl.h>
#include <string.h>
#include <getopt.h>
#include <rpc/rpc.h>
{ "version", 0, 0, 'v' },
{ "outgoing-port", 1, 0, 'o' },
{ "port", 1, 0, 'p' },
+ { "name", 1, 0, 'n' },
{ NULL, 0, 0, 0 }
};
fprintf(stderr," -p, --port Port to listen on\n");
fprintf(stderr," -o, --outgoing-port Port for outgoing connections\n");
fprintf(stderr," -V, -v, --version Display version information and exit.\n");
+ fprintf(stderr," -n, --name Specify a local hostname.\n");
}
/*
version_p = VERSION;
}
+ /* Set hostname */
+ MY_NAME = NULL;
+
/* Process command line switches */
- while ((arg = getopt_long(argc, argv, "h?vVFdp:o:", longopts, NULL)) != EOF) {
+ while ((arg = getopt_long(argc, argv, "h?vVFdn:p:o:", longopts, NULL)) != EOF) {
switch (arg) {
case 'V': /* Version */
case 'v':
exit(1);
}
break;
+ case 'n': /* Specify local hostname */
+ MY_NAME = xstrdup(optarg);
+ break;
case '?': /* heeeeeelllllllpppp? heh */
case 'h':
usage();
#endif
if (!(run_mode & MODE_NODAEMON)) {
- int filedes;
+ int filedes, fdmax, tempfd;
if ((pid = fork ()) < 0) {
perror ("Could not fork");
setsid ();
chdir (DIR_BASE);
- for (filedes = 0; filedes < sysconf (_SC_OPEN_MAX); filedes++) {
+ tempfd = open("/dev/null", O_RDWR);
+ close(0); dup2(tempfd, 0);
+ close(1); dup2(tempfd, 1);
+ close(2); dup2(tempfd, 2);
+ fdmax = sysconf (_SC_OPEN_MAX);
+ for (filedes = 3; filedes < fdmax; filedes++) {
close (filedes);
}
}