From 40c6133d4edfbdf66bf0c7119984d84caf422140 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Tue, 28 May 2013 05:50:14 +0200
Subject: [PATCH] Switch to use libbsd

---
 debian/control                  |   3 +-
 debian/patches/buftuning        |  17 ++--
 debian/patches/discard_env      |  17 ++--
 debian/patches/global_queuelen  |  21 ++--
 debian/patches/libwrap          |  23 +++--
 debian/patches/makefile         |   8 +-
 debian/patches/misc_portability | 213 +++-------------------------------------
 debian/patches/nodaemon         |  17 ++--
 debian/patches/print_pause_time |   6 +-
 debian/patches/series           |   1 -
 debian/patches/setproctitle     | 184 ----------------------------------
 debian/patches/tcp46            |  11 ++-
 12 files changed, 92 insertions(+), 429 deletions(-)
 delete mode 100644 debian/patches/setproctitle

diff --git a/debian/control b/debian/control
index cc5c625..ae872db 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,8 @@ Source: openbsd-inetd
 Section: net
 Priority: optional
 Maintainer: Marco d'Itri <md@linux.it>
-Build-Depends: debhelper (>= 5.0), libwrap0-dev
+Build-Depends: debhelper (>= 5.0), pkg-config, libbsd-dev (>= 0.5.0),
+ libwrap0-dev
 Standards-Version: 3.9.3.1
 
 Package: openbsd-inetd
diff --git a/debian/patches/buftuning b/debian/patches/buftuning
index fc6f613..452d468 100644
--- a/debian/patches/buftuning
+++ b/debian/patches/buftuning
@@ -1,6 +1,11 @@
+---
+ inetd.8 |   28 ++++++++++++++++++-
+ inetd.c |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 117 insertions(+), 2 deletions(-)
+
 --- a/inetd.8
 +++ b/inetd.8
-@@ -107,7 +107,7 @@ The fields of the configuration file are
+@@ -108,7 +108,7 @@ The fields of the configuration file are
  .Bd -unfilled -offset indent
  service name
  socket type
@@ -9,7 +14,7 @@
  wait/nowait[.max]
  user[.group] or user[:group]
  server program
-@@ -119,7 +119,7 @@ based service, the entry would contain t
+@@ -120,7 +120,7 @@ based service, the entry would contain t
  .Bd -unfilled -offset indent
  service name/version
  socket type
@@ -18,7 +23,7 @@
  wait/nowait[.max]
  user[.group] or user[:group]
  server program
-@@ -234,6 +234,30 @@ of
+@@ -235,6 +235,30 @@ of
  is used to specify a socket in the
  .Ux Ns -domain .
  .Pp
@@ -51,7 +56,7 @@
  entry is used to tell
 --- a/inetd.c
 +++ b/inetd.c
-@@ -198,6 +198,8 @@ struct	servtab {
+@@ -195,6 +195,8 @@ struct	servtab {
  	int	se_socktype;		/* type of socket to use */
  	int	se_family;		/* address family */
  	char	*se_proto;		/* protocol used */
@@ -60,7 +65,7 @@
  	int	se_rpcprog;		/* rpc program number */
  	int	se_rpcversl;		/* rpc program lowest version */
  	int	se_rpcversh;		/* rpc program highest version */
-@@ -1240,6 +1242,8 @@ getconfigent(void)
+@@ -1235,6 +1237,8 @@ getconfigent(void)
  {
  	struct servtab *sep, *tsep;
  	char *arg, *cp, *hostdelim, *s;
@@ -69,7 +74,7 @@
  	int argc;
  
  	sep = (struct servtab *) malloc(sizeof(struct servtab));
-@@ -1315,6 +1319,93 @@ more:
+@@ -1310,6 +1314,93 @@ more:
  
  	sep->se_proto = newstr(arg);
  
diff --git a/debian/patches/discard_env b/debian/patches/discard_env
index a1b2462..03a1909 100644
--- a/debian/patches/discard_env
+++ b/debian/patches/discard_env
@@ -1,6 +1,11 @@
+---
+ inetd.8 |    8 ++++++++
+ inetd.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
+ 2 files changed, 61 insertions(+), 2 deletions(-)
+
 --- a/inetd.c
 +++ b/inetd.c
-@@ -293,6 +293,7 @@ int	bump_nofile(void);
+@@ -290,6 +290,7 @@ int	bump_nofile(void);
  struct servtab *enter(struct servtab *);
  int	matchconf(struct servtab *, struct servtab *);
  int	dg_broadcast(struct in_addr *in);
@@ -8,7 +13,7 @@
  
  #define NUMINT	(sizeof(intab) / sizeof(struct inent))
  char	*CONFIG = _PATH_INETDCONF;
-@@ -324,17 +325,21 @@ main(int argc, char *argv[], char *envp[
+@@ -321,15 +322,19 @@ main(int argc, char *argv[])
  {
  	fd_set *fdsrp = NULL;
  	int readablen = 0, ch;
@@ -17,8 +22,6 @@
  	extern char *optarg;
  	extern int optind;
  	
- 	initsetproctitle(argc, argv, envp);
- 
 -	while ((ch = getopt(argc, argv, "dR:")) != -1)
 +	while ((ch = getopt(argc, argv, "dER:")) != -1)
  		switch (ch) {
@@ -31,7 +34,7 @@
  		case 'R': {	/* invocation rate */
  			char *p;
  			int val;
-@@ -352,12 +357,16 @@ main(int argc, char *argv[], char *envp[
+@@ -347,12 +352,16 @@ main(int argc, char *argv[])
  		case '?':
  		default:
  			fprintf(stderr,
@@ -49,7 +52,7 @@
  	uid = getuid();
  	if (uid != 0)
  		CONFIG = NULL;
-@@ -2057,3 +2066,45 @@ spawn(struct servtab *sep, int ctrl)
+@@ -2052,3 +2061,45 @@ spawn(struct servtab *sep, int ctrl)
  	if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
  		close(ctrl);
  }
@@ -105,7 +108,7 @@
  .Op Fl R Ar rate
  .Op Ar configuration_file
  .Sh DESCRIPTION
-@@ -62,6 +63,13 @@ The options are as follows:
+@@ -58,6 +59,13 @@ The options are as follows:
  .Bl -tag -width Ds
  .It Fl d
  Turns on debugging.
diff --git a/debian/patches/global_queuelen b/debian/patches/global_queuelen
index ed52ddf..949cf87 100644
--- a/debian/patches/global_queuelen
+++ b/debian/patches/global_queuelen
@@ -1,6 +1,11 @@
+---
+ inetd.8 |    5 +++++
+ inetd.c |   12 +++++++++---
+ 2 files changed, 14 insertions(+), 3 deletions(-)
+
 --- a/inetd.c
 +++ b/inetd.c
-@@ -170,6 +170,7 @@ int lflag = 0;
+@@ -167,6 +167,7 @@ int lflag = 0;
  #endif
  
  int	 debug = 0;
@@ -8,16 +13,16 @@
  int	 nsock, maxsock;
  fd_set	*allsockp;
  int	 allsockn;
-@@ -338,7 +339,7 @@ main(int argc, char *argv[], char *envp[
+@@ -333,7 +334,7 @@ main(int argc, char *argv[])
+ 	extern char *optarg;
+ 	extern int optind;
  	
- 	initsetproctitle(argc, argv, envp);
- 
 -	while ((ch = getopt(argc, argv, "dEilR:")) != -1)
 +	while ((ch = getopt(argc, argv, "dEilq:R:")) != -1)
  		switch (ch) {
  		case 'd':
  			debug = 1;
-@@ -358,6 +359,11 @@ main(int argc, char *argv[], char *envp[
+@@ -353,6 +354,11 @@ main(int argc, char *argv[])
  			    progname);
  			exit(1);
  #endif
@@ -29,7 +34,7 @@
  		case 'R': {	/* invocation rate */
  			char *p;
  			int val;
-@@ -375,7 +381,7 @@ main(int argc, char *argv[], char *envp[
+@@ -370,7 +376,7 @@ main(int argc, char *argv[])
  		case '?':
  		default:
  			fprintf(stderr,
@@ -38,7 +43,7 @@
  			exit(1);
  		}
  	argc -= optind;
-@@ -1060,7 +1066,7 @@ setsockopt(fd, SOL_SOCKET, opt, &on, siz
+@@ -1055,7 +1061,7 @@ setsockopt(fd, SOL_SOCKET, opt, &on, siz
  		return;
  	}
  	if (sep->se_socktype == SOCK_STREAM)
@@ -57,7 +62,7 @@
  .Op Fl R Ar rate
  .Op Ar configuration_file
  .Sh DESCRIPTION
-@@ -81,6 +82,10 @@ Internal services cannot be wrapped.  Wh
+@@ -77,6 +78,10 @@ Internal services cannot be wrapped.  Wh
  is silently not executed even if present in
  .Pa /etc/inetd.conf
  and instead libwrap is called directly by inetd.
diff --git a/debian/patches/libwrap b/debian/patches/libwrap
index 18d6605..3e13474 100644
--- a/debian/patches/libwrap
+++ b/debian/patches/libwrap
@@ -1,6 +1,11 @@
+---
+ inetd.8 |   25 +++++++++++++++++++++++++
+ inetd.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
+ 2 files changed, 82 insertions(+), 2 deletions(-)
+
 --- a/inetd.c
 +++ b/inetd.c
-@@ -164,6 +164,11 @@ size_t strlcpy(char *, const char *, siz
+@@ -161,6 +161,11 @@
  #define	CNT_INTVL	60		/* servers in CNT_INTVL sec. */
  #define	RETRYTIME	(60*10)		/* retry after bind or server fail */
  
@@ -12,16 +17,16 @@
  int	 debug = 0;
  int	 nsock, maxsock;
  fd_set	*allsockp;
-@@ -332,7 +337,7 @@ main(int argc, char *argv[], char *envp[
+@@ -327,7 +332,7 @@ main(int argc, char *argv[])
+ 	extern char *optarg;
+ 	extern int optind;
  	
- 	initsetproctitle(argc, argv, envp);
- 
 -	while ((ch = getopt(argc, argv, "dER:")) != -1)
 +	while ((ch = getopt(argc, argv, "dElR:")) != -1)
  		switch (ch) {
  		case 'd':
  			debug = 1;
-@@ -340,6 +345,15 @@ main(int argc, char *argv[], char *envp[
+@@ -335,6 +340,15 @@ main(int argc, char *argv[])
  		case 'E':
  			keepenv = 1;
  			break;
@@ -37,7 +42,7 @@
  		case 'R': {	/* invocation rate */
  			char *p;
  			int val;
-@@ -357,7 +371,7 @@ main(int argc, char *argv[], char *envp[
+@@ -352,7 +366,7 @@ main(int argc, char *argv[])
  		case '?':
  		default:
  			fprintf(stderr,
@@ -46,7 +51,7 @@
  			exit(1);
  		}
  	argc -= optind;
-@@ -1952,6 +1966,47 @@ spawn(struct servtab *sep, int ctrl)
+@@ -1947,6 +1961,47 @@ spawn(struct servtab *sep, int ctrl)
  	}
  	sigprocmask(SIG_SETMASK, &emptymask, NULL);
  	if (pid == 0) {
@@ -104,7 +109,7 @@
  .Op Fl R Ar rate
  .Op Ar configuration_file
  .Sh DESCRIPTION
-@@ -70,6 +71,13 @@ from laundering the environment.  Withou
+@@ -66,6 +67,13 @@ from laundering the environment.  Withou
  potentially harmful environent variables, including
  .Pa PATH ,
  will be removed and not inherited by services.
@@ -118,7 +123,7 @@
  .It Fl R Ar rate
  Specify the maximum number of times a service can be invoked
  in one minute; the default is 256.
-@@ -353,6 +361,23 @@ is reread.
+@@ -349,6 +357,23 @@ is reread.
  creates a file
  .Em /var/run/inetd.pid
  that contains its process identifier.
diff --git a/debian/patches/makefile b/debian/patches/makefile
index 1972c42..7a27fc8 100644
--- a/debian/patches/makefile
+++ b/debian/patches/makefile
@@ -3,12 +3,12 @@
 @@ -0,0 +1,20 @@
 +CFLAGS ?= -g -O2
 +
-+DEFS := -DLIBWRAP
-+LIBS := -lwrap
++DEFS := -DLIBWRAP $(shell pkg-config --cflags libbsd-overlay)
++LIBS := -lwrap $(shell pkg-config --libs libbsd-overlay)
 +
 +CPPFLAGS += $(DEFS)
 +
-+inetd_OBJECTS := inetd.o setproctitle.o strlcpy.o bsd-closefrom.o
++inetd_OBJECTS := inetd.o
 +
 +all: inetd
 +
@@ -19,5 +19,5 @@
 +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
 +
 +clean:
-+	rm -f inetd inetd.o setproctitle.o strlcpy.o
++	rm -f inetd inetd.o
 +
diff --git a/debian/patches/misc_portability b/debian/patches/misc_portability
index d546f53..c17a6b9 100644
--- a/debian/patches/misc_portability
+++ b/debian/patches/misc_portability
@@ -1,3 +1,8 @@
+---
+ inetd.8 |   32 ++++++++++++++++++---------
+ inetd.c |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
+ 2 files changed, 91 insertions(+), 16 deletions(-)
+
 --- a/inetd.8
 +++ b/inetd.8
 @@ -42,11 +42,7 @@
@@ -86,7 +91,7 @@
  #include <sys/time.h>
  #include <sys/resource.h>
  
-@@ -146,13 +147,18 @@
+@@ -146,11 +147,14 @@
  #include <stdlib.h>
  #include <unistd.h>
  #include <string.h>
@@ -101,12 +106,8 @@
 -#include <rpcsvc/nfs_prot.h>
  #include "pathnames.h"
  
-+size_t strlcpy(char *, const char *, size_t);
-+
  #define	TOOMANY		256		/* don't start more than TOOMANY */
- #define	CNT_INTVL	60		/* servers in CNT_INTVL sec. */
- #define	RETRYTIME	(60*10)		/* retry after bind or server fail */
-@@ -325,7 +331,6 @@ main(int argc, char *argv[])
+@@ -325,7 +329,6 @@ main(int argc, char *argv[])
  		switch (ch) {
  		case 'd':
  			debug = 1;
@@ -114,7 +115,7 @@
  			break;
  		case 'R': {	/* invocation rate */
  			char *p;
-@@ -367,9 +372,13 @@ main(int argc, char *argv[])
+@@ -367,9 +370,13 @@ main(int argc, char *argv[])
  	umask(022);
  	if (debug == 0) {
  		daemon(0, 0);
@@ -128,7 +129,7 @@
  
  	if (uid == 0) {
  		gid_t gid = getgid();
-@@ -414,6 +423,15 @@ main(int argc, char *argv[])
+@@ -414,6 +421,15 @@ main(int argc, char *argv[])
  	sa.sa_handler = SIG_IGN;
  	sigaction(SIGPIPE, &sa, &sapipe);
  
@@ -144,7 +145,7 @@
  	for (;;) {
  		int n, ctrl = -1;
  
-@@ -569,9 +587,6 @@ dg_badinput(struct sockaddr *sa)
+@@ -569,9 +585,6 @@ dg_badinput(struct sockaddr *sa)
  		return 0;
  	}
  
@@ -154,7 +155,7 @@
  	return (0);
  
  bad:
-@@ -581,6 +596,7 @@ bad:
+@@ -581,6 +594,7 @@ bad:
  int
  dg_broadcast(struct in_addr *in)
  {
@@ -162,7 +163,7 @@
  	struct ifaddrs *ifa, *ifap;
  	struct sockaddr_in *sin;
  
-@@ -597,6 +613,7 @@ dg_broadcast(struct in_addr *in)
+@@ -597,6 +611,7 @@ dg_broadcast(struct in_addr *in)
  		}
  	}
  	freeifaddrs(ifap);
@@ -170,7 +171,7 @@
  	return (0);
  }
  
-@@ -1843,7 +1860,7 @@ print_service(char *action, struct servt
+@@ -1843,7 +1858,7 @@ print_service(char *action, struct servt
  	fprintf(stderr,
  	    " wait.max=%hd.%d user:group=%s:%s builtin=%lx server=%s\n",
  	    sep->se_wait, sep->se_max, sep->se_user,
@@ -179,7 +180,7 @@
  	    (long)sep->se_bi, sep->se_server);
  }
  
-@@ -1951,6 +1968,7 @@ spawn(struct servtab *sep, int ctrl)
+@@ -1951,6 +1966,7 @@ spawn(struct servtab *sep, int ctrl)
  				if (uid != pwd->pw_uid)
  					exit(1);
  			} else {
@@ -187,7 +188,7 @@
  				tmpint = LOGIN_SETALL &
  				    ~(LOGIN_SETGROUP|LOGIN_SETLOGIN);
  				if (pwd->pw_uid)
-@@ -1966,6 +1984,53 @@ spawn(struct servtab *sep, int ctrl)
+@@ -1966,6 +1982,53 @@ spawn(struct servtab *sep, int ctrl)
  					    sep->se_service, sep->se_proto);
  					exit(1);
  				}
@@ -241,187 +242,3 @@
  			}
  			if (debug)
  				fprintf(stderr, "%ld execv %s\n",
---- /dev/null
-+++ b/strlcpy.c
-@@ -0,0 +1,63 @@
-+/*	$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $	*/
-+
-+/*
-+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
-+ * All rights reserved.
-+ *
-+ * Redistribution and use in source and binary forms, with or without
-+ * modification, are permitted provided that the following conditions
-+ * are met:
-+ * 1. Redistributions of source code must retain the above copyright
-+ *    notice, this list of conditions and the following disclaimer.
-+ * 2. Redistributions in binary form must reproduce the above copyright
-+ *    notice, this list of conditions and the following disclaimer in the
-+ *    documentation and/or other materials provided with the distribution.
-+ * 3. The name of the author may not be used to endorse or promote products
-+ *    derived from this software without specific prior written permission.
-+ *
-+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
-+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-+ *
-+ * (Old style prototype traslated)
-+ */
-+
-+#include <sys/types.h>
-+#include <string.h>
-+
-+/*
-+ * Copy src to string dst of size siz.  At most siz-1 characters
-+ * will be copied.  Always NUL terminates (unless siz == 0).
-+ * Returns strlen(src); if retval >= siz, truncation occurred.
-+ */
-+size_t strlcpy(char *dst, const char *src, size_t siz)
-+{
-+	register char *d = dst;
-+	register const char *s = src;
-+	register size_t n = siz;
-+
-+	/* Copy as many bytes as will fit */
-+	if (n != 0 && --n != 0) {
-+		do {
-+			if ((*d++ = *s++) == 0)
-+				break;
-+		} while (--n != 0);
-+	}
-+
-+	/* Not enough room in dst, add NUL and traverse rest of src */
-+	if (n == 0) {
-+		if (siz != 0)
-+			*d = '\0';		/* NUL-terminate dst */
-+		while (*s++)
-+			;
-+	}
-+
-+	return(s - src - 1);	/* count does not include NUL */
-+}
---- /dev/null
-+++ b/bsd-closefrom.c
-@@ -0,0 +1,115 @@
-+/*
-+ * Copyright (c) 2004-2005 Todd C. Miller <Todd.Miller@courtesan.com>
-+ *
-+ * Permission to use, copy, modify, and distribute this software for any
-+ * purpose with or without fee is hereby granted, provided that the above
-+ * copyright notice and this permission notice appear in all copies.
-+ *
-+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-+ */
-+
-+#define HAVE_FCNTL_H
-+#define HAVE_DIRENT_H
-+#ifdef linux
-+#define HAVE_DIRFD
-+#define HAVE_PROC_PID
-+#endif
-+#define HAVE_SYSCONF
-+
-+#ifndef HAVE_CLOSEFROM
-+
-+#include <sys/types.h>
-+#include <sys/param.h>
-+#include <unistd.h>
-+#include <stdio.h>
-+#ifdef HAVE_FCNTL_H
-+# include <fcntl.h>
-+#endif
-+#include <limits.h>
-+#include <stdlib.h>
-+#include <stddef.h>
-+#include <string.h>
-+#include <unistd.h>
-+#ifdef HAVE_DIRENT_H
-+# include <dirent.h>
-+# define NAMLEN(dirent) strlen((dirent)->d_name)
-+#else
-+# define dirent direct
-+# define NAMLEN(dirent) (dirent)->d_namlen
-+# ifdef HAVE_SYS_NDIR_H
-+#  include <sys/ndir.h>
-+# endif
-+# ifdef HAVE_SYS_DIR_H
-+#  include <sys/dir.h>
-+# endif
-+# ifdef HAVE_NDIR_H
-+#  include <ndir.h>
-+# endif
-+#endif
-+
-+#ifndef OPEN_MAX
-+# define OPEN_MAX	256
-+#endif
-+
-+#if 0
-+__unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $";
-+#endif /* lint */
-+
-+/*
-+ * Close all file descriptors greater than or equal to lowfd.
-+ */
-+#ifdef HAVE_FCNTL_CLOSEM
-+void
-+closefrom(int lowfd)
-+{
-+    (void) fcntl(lowfd, F_CLOSEM, 0);
-+}
-+#else
-+void
-+closefrom(int lowfd)
-+{
-+    long fd, maxfd;
-+#if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID)
-+    char fdpath[PATH_MAX], *endp;
-+    struct dirent *dent;
-+    DIR *dirp;
-+    int len;
-+
-+    /* Check for a /proc/$$/fd directory. */
-+    len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid());
-+    if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) {
-+	while ((dent = readdir(dirp)) != NULL) {
-+	    fd = strtol(dent->d_name, &endp, 10);
-+	    if (dent->d_name != endp && *endp == '\0' &&
-+		fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))
-+		(void) close((int) fd);
-+	}
-+	(void) closedir(dirp);
-+    } else
-+#endif
-+    {
-+	/*
-+	 * Fall back on sysconf() or getdtablesize().  We avoid checking
-+	 * resource limits since it is possible to open a file descriptor
-+	 * and then drop the rlimit such that it is below the open fd.
-+	 */
-+#ifdef HAVE_SYSCONF
-+	maxfd = sysconf(_SC_OPEN_MAX);
-+#else
-+	maxfd = getdtablesize();
-+#endif /* HAVE_SYSCONF */
-+	if (maxfd < 0)
-+	    maxfd = OPEN_MAX;
-+
-+	for (fd = lowfd; fd < maxfd; fd++)
-+	    (void) close((int) fd);
-+    }
-+}
-+#endif /* !HAVE_FCNTL_CLOSEM */
-+#endif /* HAVE_CLOSEFROM */
diff --git a/debian/patches/nodaemon b/debian/patches/nodaemon
index 1f3887e..85f4e30 100644
--- a/debian/patches/nodaemon
+++ b/debian/patches/nodaemon
@@ -1,3 +1,8 @@
+---
+ inetd.8 |    3 +++
+ inetd.c |   14 +++++++++++---
+ 2 files changed, 14 insertions(+), 3 deletions(-)
+
 --- a/inetd.8
 +++ b/inetd.8
 @@ -39,6 +39,7 @@
@@ -8,7 +13,7 @@
  .Op Fl l
  .Op Fl R Ar rate
  .Op Ar configuration_file
-@@ -71,6 +72,8 @@ from laundering the environment.  Withou
+@@ -67,6 +68,8 @@ from laundering the environment.  Withou
  potentially harmful environent variables, including
  .Pa PATH ,
  will be removed and not inherited by services.
@@ -19,7 +24,7 @@
  Internal services cannot be wrapped.  When enabled,
 --- a/inetd.c
 +++ b/inetd.c
-@@ -331,13 +331,14 @@ main(int argc, char *argv[], char *envp[
+@@ -328,11 +328,12 @@ main(int argc, char *argv[])
  	fd_set *fdsrp = NULL;
  	int readablen = 0, ch;
  	int keepenv = 0;
@@ -28,14 +33,12 @@
  	extern char *optarg;
  	extern int optind;
  	
- 	initsetproctitle(argc, argv, envp);
- 
 -	while ((ch = getopt(argc, argv, "dElR:")) != -1)
 +	while ((ch = getopt(argc, argv, "dEilR:")) != -1)
  		switch (ch) {
  		case 'd':
  			debug = 1;
-@@ -345,6 +346,9 @@ main(int argc, char *argv[], char *envp[
+@@ -340,6 +341,9 @@ main(int argc, char *argv[])
  		case 'E':
  			keepenv = 1;
  			break;
@@ -45,7 +48,7 @@
  		case 'l':
  #ifdef LIBWRAP
  			lflag = 1;
-@@ -371,7 +375,7 @@ main(int argc, char *argv[], char *envp[
+@@ -366,7 +370,7 @@ main(int argc, char *argv[])
  		case '?':
  		default:
  			fprintf(stderr,
@@ -54,7 +57,7 @@
  			exit(1);
  		}
  	argc -= optind;
-@@ -397,7 +401,11 @@ main(int argc, char *argv[], char *envp[
+@@ -392,7 +396,11 @@ main(int argc, char *argv[])
  
  	umask(022);
  	if (debug == 0) {
diff --git a/debian/patches/print_pause_time b/debian/patches/print_pause_time
index 734a763..3964088 100644
--- a/debian/patches/print_pause_time
+++ b/debian/patches/print_pause_time
@@ -1,6 +1,10 @@
+---
+ inetd.c |    5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
 --- a/inetd.c
 +++ b/inetd.c
-@@ -1944,8 +1944,9 @@ spawn(struct servtab *sep, int ctrl)
+@@ -1939,8 +1939,9 @@ spawn(struct servtab *sep, int ctrl)
  					return;
  				}
  				syslog(LOG_ERR,
diff --git a/debian/patches/series b/debian/patches/series
index 9f98e0e..6a13a80 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,7 +2,6 @@
 makefile
 test
 misc_portability
-setproctitle
 
 # features
 discard_env
diff --git a/debian/patches/setproctitle b/debian/patches/setproctitle
deleted file mode 100644
index c2dcb55..0000000
--- a/debian/patches/setproctitle
+++ /dev/null
@@ -1,184 +0,0 @@
---- a/inetd.c
-+++ b/inetd.c
-@@ -156,6 +156,7 @@
- #include <rpc/rpc.h>
- #include <rpc/pmap_clnt.h>
- #include "pathnames.h"
-+#include "setproctitle.h"
- 
- size_t strlcpy(char *, const char *, size_t);
- 
-@@ -319,7 +320,7 @@ fd_grow(fd_set **fdsp, int *bytes, int f
- struct sigaction sa, sapipe;
- 
- int
--main(int argc, char *argv[])
-+main(int argc, char *argv[], char *envp[])
- {
- 	fd_set *fdsrp = NULL;
- 	int readablen = 0, ch;
-@@ -327,6 +328,8 @@ main(int argc, char *argv[])
- 	extern char *optarg;
- 	extern int optind;
- 	
-+	initsetproctitle(argc, argv, envp);
-+
- 	while ((ch = getopt(argc, argv, "dR:")) != -1)
- 		switch (ch) {
- 		case 'd':
---- /dev/null
-+++ b/setproctitle.c
-@@ -0,0 +1,146 @@
-+/*
-+ * setproctitle implementation for linux.
-+ * Stolen from sendmail 8.7.4 and bashed around by David A. Holland
-+ */
-+
-+/*
-+ * Copyright (c) 1983, 1995 Eric P. Allman
-+ * Copyright (c) 1988, 1993
-+ *	The Regents of the University of California.  All rights reserved.
-+ *
-+ * Redistribution and use in source and binary forms, with or without
-+ * modification, are permitted provided that the following conditions
-+ * are met:
-+ * 1. Redistributions of source code must retain the above copyright
-+ *    notice, this list of conditions and the following disclaimer.
-+ * 2. Redistributions in binary form must reproduce the above copyright
-+ *    notice, this list of conditions and the following disclaimer in the
-+ *    documentation and/or other materials provided with the distribution.
-+ * 3. All advertising materials mentioning features or use of this software
-+ *    must display the following acknowledgement:
-+ *	This product includes software developed by the University of
-+ *	California, Berkeley and its contributors.
-+ * 4. Neither the name of the University nor the names of its contributors
-+ *    may be used to endorse or promote products derived from this software
-+ *    without specific prior written permission.
-+ *
-+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-+ * SUCH DAMAGE.
-+ *
-+ * From: @(#)conf.c	8.243 (Berkeley) 11/20/95
-+ */
-+char setproctitle_rcsid[] =
-+  "$Id: setproctitle.c,v 1.3 1997/05/19 12:58:15 dholland Exp $";
-+
-+#include <stdlib.h>
-+#include <string.h>
-+#include <stdarg.h>
-+#include <unistd.h>
-+#include <stdio.h>
-+
-+#include "setproctitle.h"
-+/*
-+**  SETPROCTITLE -- set process title for ps
-+**
-+**	Parameters:
-+**		fmt -- a printf style format string.
-+**		a, b, c -- possible parameters to fmt.
-+**
-+**	Returns:
-+**		none.
-+**
-+**	Side Effects:
-+**		Clobbers argv of our main procedure so ps(1) will
-+**		display the title.
-+*/
-+
-+
-+/*
-+**  Pointers for setproctitle.
-+**	This allows "ps" listings to give more useful information.
-+*/
-+
-+static char **Argv = NULL;		/* pointer to argument vector */
-+static char *LastArgv = NULL;		/* end of argv */
-+static char Argv0[128];			/* program name */
-+
-+void
-+initsetproctitle(int argc, char **argv, char **envp)
-+{
-+	register int i;
-+	char *tmp;
-+
-+	/*
-+        **  Move the environment so setproctitle can use the space at
-+	**  the top of memory.
-+	*/
-+
-+	for (i = 0; envp[i] != NULL; i++)
-+		continue;
-+	__environ = (char **) malloc(sizeof (char *) * (i + 1));
-+	for (i = 0; envp[i] != NULL; i++)
-+		__environ[i] = strdup(envp[i]);
-+	__environ[i] = NULL;
-+
-+	/*
-+	**  Save start and extent of argv for setproctitle.
-+	*/
-+
-+	Argv = argv;
-+	if (i > 0)
-+		LastArgv = envp[i - 1] + strlen(envp[i - 1]);
-+	else
-+		LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
-+
-+	tmp = strrchr(argv[0], '/');
-+	if (!tmp) tmp = argv[0];
-+	else tmp++;
-+	strncpy(Argv0, tmp, sizeof(Argv0));
-+	/* remember to take away one or we go outside the array space */
-+	Argv0[sizeof(Argv0) - 1] = 0;
-+}
-+
-+void
-+setproctitle(const char *fmt, ...)
-+{
-+	register char *p;
-+	register int i;
-+	static char buf[2048];
-+	va_list ap;
-+
-+	p = buf;
-+
-+	/* print progname: heading for grep */
-+	/* This can't overflow buf due to the relative size of Argv0. */
-+	(void) strcpy(p, Argv0);
-+	(void) strcat(p, ": ");
-+	p += strlen(p);
-+
-+	/* print the argument string */
-+	va_start(ap, fmt);
-+	(void) vsnprintf(p, sizeof(buf) - (p - buf), fmt, ap);
-+	va_end(ap);
-+
-+	i = strlen(buf);
-+
-+	if (i > LastArgv - Argv[0] - 2)
-+	{
-+		i = LastArgv - Argv[0] - 2;
-+		buf[i] = '\0';
-+	}
-+	(void) strcpy(Argv[0], buf);
-+	p = &Argv[0][i];
-+	while (p < LastArgv)
-+		*p++ = ' ';
-+	Argv[1] = NULL;
-+}
-+
---- /dev/null
-+++ b/setproctitle.h
-@@ -0,0 +1,4 @@
-+/* Call this from main. */
-+void initsetproctitle(int argc, char **argv, char **envp);
-+
-+void setproctitle(const char *fmt, ...);
diff --git a/debian/patches/tcp46 b/debian/patches/tcp46
index f616097..d9dac84 100644
--- a/debian/patches/tcp46
+++ b/debian/patches/tcp46
@@ -1,6 +1,11 @@
+---
+ inetd.8 |    5 +++++
+ inetd.c |   18 ++++++++++++++++--
+ 2 files changed, 21 insertions(+), 2 deletions(-)
+
 --- a/inetd.8
 +++ b/inetd.8
-@@ -413,6 +413,11 @@ and IPv6 traffic will go to server on
+@@ -414,6 +414,11 @@ and IPv6 traffic will go to server on
  If you have only one server on
  .Dq tcp6 ,
  only IPv6 traffic will be routed to the server.
@@ -14,7 +19,7 @@
  .Xr fingerd 8 ,
 --- a/inetd.c
 +++ b/inetd.c
-@@ -814,10 +814,14 @@ doconfig(void)
+@@ -809,10 +809,14 @@ doconfig(void)
  
  				if (!port) {
  					/* XXX */
@@ -31,7 +36,7 @@
  					sp = getservbyname(sep->se_service,
  					    protoname);
  					if (sp == 0) {
-@@ -1011,6 +1015,16 @@ setup(struct servtab *sep)
+@@ -1006,6 +1010,16 @@ setup(struct servtab *sep)
  		    sep->se_service, sep->se_proto);
  		return;
  	}
-- 
1.8.3.rc3

