Subject: inetd_setproctitle()
To: None <tech-userlevel@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
List: tech-userlevel
Date: 05/31/2002 19:42:56
	why can't we use normal setproctitle(3) in inetd?

itojun


Index: inetd.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/inetd/inetd.c,v
retrieving revision 1.76
diff -u -r1.76 inetd.c
--- inetd.c	2002/01/21 14:42:28	1.76
+++ inetd.c	2002/05/31 10:43:00
@@ -386,7 +386,7 @@
 uint32_t	machtime __P((void));
 int 		port_good_dg __P((struct sockaddr *sa));
 static int	getline __P((int, char *, int));
-int		main __P((int, char *[], char *[]));
+int		main __P((int, char *[]));
 
 struct biltin {
 	char	*bi_service;		/* internally provided service name */
@@ -431,26 +431,17 @@
 
 #define NUMINT	(sizeof(intab) / sizeof(struct inent))
 char	*CONFIG = _PATH_INETDCONF;
-char	**Argv;
-char 	*LastArg;
 
 int
-main(argc, argv, envp)
+main(argc, argv)
 	int argc;
-	char *argv[], *envp[];
+	char *argv[];
 {
 	struct servtab *sep, *nsep;
 	struct sigvec sv;
 	int ch, dofork;
 	pid_t pid;
 
-	Argv = argv;
-	if (envp == 0 || *envp == 0)
-		envp = argv;
-	while (*envp)
-		envp++;
-	LastArg = envp[-1] + strlen(envp[-1]);
-
 	while ((ch = getopt(argc, argv,
 #ifdef LIBWRAP
 					"dl"
@@ -1757,25 +1748,19 @@
 	char *a;
 	int s;
 {
-	int size;
-	char *cp;
+	socklen_t size;
 	struct sockaddr_storage ss;
-	char buf[80];
 	char hbuf[NI_MAXHOST];
 
-	cp = Argv[0];
 	size = sizeof(ss);
 	if (getpeername(s, (struct sockaddr *)&ss, &size) == 0) {
-		if (getnameinfo((struct sockaddr *)&ss, ss.ss_len,
-				hbuf, sizeof(hbuf), NULL, 0, niflags) != 0)
-			strcpy(hbuf, "?");
-		(void)snprintf(buf, sizeof buf, "-%s [%s]", a, hbuf);
+		if (getnameinfo((struct sockaddr *)&ss, size, hbuf,
+		    sizeof(hbuf), NULL, 0, niflags) == 0)
+			setproctitle("-%s [%s]", a, hbuf);
+		else
+			setproctitle("-%s [?]", a);
 	} else
-		(void)snprintf(buf, sizeof buf, "-%s", a);
-	strncpy(cp, buf, LastArg - cp);
-	cp += strlen(cp);
-	while (cp < LastArg)
-		*cp++ = ' ';
+		setproctitle("-%s", a);
 }
 
 void