Package: portmap
Version: 5-17
Severity: wishlist
Tags: patch
Hi, see below for a patch that adds the -f option to portmap:
-f (foreground) prevents portmap from running as a daemon, and
causes log messages to be printed to the standard error output.
This is useful to have portmap run under the runit init scheme, or
(respawning) from /etc/inittab. The -d option does nearly the same, but
causes portmap to additionally print uninteresting debug messages.
Thanks for considering, Gerrit.
diff -ur ../portmap-5/portmap.8 ./portmap.8
--- ../portmap-5/portmap.8 2006-02-06 09:05:26.000000000 +0000
+++ ./portmap.8 2006-02-06 09:05:38.000000000 +0000
@@ -46,6 +46,7 @@
.Sh SYNOPSIS
.Nm portmap
.Op Fl d
+.Op Fl f
.Op Fl t Ar dir
.Op Fl v
.Op Fl i Ar address
@@ -98,6 +99,12 @@
from running as a daemon,
and causes errors and debugging information
to be printed to the standard error output.
+.It Fl f
+(foreground) prevents
+.Nm portmap
+from running as a daemon,
+and causes log messages
+to be printed to the standard error output.
.It Fl t Ar dir
(chroot) tell
.Nm portmap
diff -ur ../portmap-5/portmap.c ./portmap.c
--- ../portmap-5/portmap.c 2006-02-06 09:05:26.000000000 +0000
+++ ./portmap.c 2006-02-06 09:05:51.000000000 +0000
@@ -130,6 +130,7 @@
static void callit();
struct pmaplist *pmaplist;
int debugging = 0;
+int foreground = 0;
#include "pmap_check.h"
@@ -167,11 +168,13 @@
struct in_addr bindaddr;
int have_bindaddr = 0;
- while ((c = getopt(argc, argv, "dt:vi:")) != EOF) {
+ while ((c = getopt(argc, argv, "dft:vi:")) != EOF) {
switch (c) {
case 'd':
debugging = 1;
+ case 'f':
+ foreground = 1;
break;
case 't':
chroot_path = optarg;
@@ -183,8 +186,9 @@
have_bindaddr = inet_aton(optarg, &bindaddr);
break;
default:
- (void) fprintf(stderr, "usage: %s [-dv] [-t dir] [-i
address]\n", argv[0]);
+ (void) fprintf(stderr, "usage: %s [-dfv] [-t dir] [-i
address]\n", argv[0]);
(void) fprintf(stderr, "-d: debugging mode\n");
+ (void) fprintf(stderr, "-f: don't daemonize, log to
standard error\n");
(void) fprintf(stderr, "-t dir: chroot into dir\n");
(void) fprintf(stderr, "-v: verbose logging\n");
(void) fprintf(stderr, "-i address: bind to address\n");
@@ -192,18 +196,18 @@
}
}
- if (!debugging && daemon(0, 0)) {
+ if (!foreground && daemon(0, 0)) {
(void) fprintf(stderr, "portmap: fork: %s", strerror(errno));
exit(1);
}
#ifdef LOG_MAIL
openlog("portmap",
- debugging ? LOG_PID | LOG_NDELAY | LOG_PERROR : LOG_PID |
LOG_NDELAY,
+ foreground ? LOG_PID | LOG_NDELAY | LOG_PERROR : LOG_PID |
LOG_NDELAY,
FACILITY);
#else
openlog("portmap",
- debugging ? LOG_PID | LOG_NDELAY | LOG_PERROR : LOG_PID |
LOG_NDELAY);
+ foreground ? LOG_PID | LOG_NDELAY | LOG_PERROR : LOG_PID |
LOG_NDELAY);
#endif
if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {