From 10ce9394cd95d7f332cd4c86fc62c6ca7d517563 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson Date: Sat, 27 Nov 2010 02:07:12 +0100 Subject: [PATCH 3/3] inetd: Replaceable path for PID file. --- ChangeLog | 9 +++++++++ src/inetd.c | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 358fece..9623bc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2010-11-27 Mats Erik Andersson + * src/inetd.c (pidfile_option): New variable. + (pid_file): New variable. + (argp_options): Add an option for replacing path of PID file. + (parse_opt): Handle option `p'. + (main): Condition PID file use on PIDFILE_OPTION. Replace the + macro PATH_INETDPID by variable PID_FILE. + +2010-11-27 Mats Erik Andersson + * src/inetd.c (inetd_getaddrinfo): If IPV6, then add a flag AI_NUMERICHOST if the node is a numeric address string. New variable NUMERIC_ADDRESS. Debug symbolic addresses. diff --git a/src/inetd.c b/src/inetd.c index 3d87867..8d2a915 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -163,6 +163,8 @@ char **config_files; static bool env_option = false; /* Set environment variables */ static bool resolve_option = false; /* Resolve IP addresses */ +static bool pidfile_option = true; /* Record the PID in a file */ +static const char *pid_file = PATH_INETDPID; const char args_doc[] = "[CONF-FILE [CONF-DIR]]..."; const char doc[] = "Internet super-server."; @@ -185,6 +187,9 @@ static struct argp_option argp_options[] = { "turn on debugging, run in foreground mode", GRP+1}, {"environment", OPT_ENVIRON, NULL, 0, "pass local and remote socket information in environment variables", GRP+1}, + { "pidfile", 'p', "PIDFILE", OPTION_ARG_OPTIONAL, + "replace the default path \"" PATH_INETDPID "\"", + GRP+1 }, {"rate", 'R', "NUMBER", 0, "maximum invocation rate (per minute)", GRP+1}, {"resolve", OPT_RESOLVE, NULL, 0, @@ -211,6 +216,13 @@ parse_opt (int key, char *arg, struct argp_state *state) env_option = true; break; + case 'p': + if (arg && strlen (arg)) + pid_file = arg; + else + pidfile_option = false; + break; + case 'R': number = strtol (arg, &p, 0); if (number < 1 || *p) @@ -1859,15 +1871,18 @@ main (int argc, char *argv[], char *envp[]) openlog ("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON); + if (pidfile_option) { - FILE *fp = fopen (PATH_INETDPID, "w"); + FILE *fp = fopen (pid_file, "w"); if (fp != NULL) { + if (debug) + fprintf(stderr, "Using pid-file at \"%s\".\n", pid_file); fprintf (fp, "%d\n", getpid ()); fclose (fp); } else - syslog (LOG_CRIT, "can't open %s: %s\n", PATH_INETDPID, + syslog (LOG_CRIT, "can't open %s: %s\n", pid_file, strerror (errno)); } -- 1.7.2.3