[BusyBox-cvs] busybox/networking inetd.c,1.9,1.10

Glenn McGrath bug1 at busybox.net
Sat Jan 17 02:47:47 UTC 2004


Update of /var/cvs/busybox/networking
In directory nail:/tmp/cvs-serv31803/networking

Modified Files:
	inetd.c 
Log Message:
Use 1 line for function name and return value,
remove dofork define/variable,
dont check pid value is < or > than 0 if we know it is 0.


Index: inetd.c
===================================================================
RCS file: /var/cvs/busybox/networking/inetd.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- inetd.c	17 Jan 2004 01:44:32 -0000	1.9
+++ inetd.c	17 Jan 2004 02:47:45 -0000	1.10
@@ -131,25 +131,24 @@
 #include <stdarg.h>
 #include <time.h>
 
+#ifndef OPEN_MAX
+#define OPEN_MAX	64
+#endif
+
 #define _PATH_INETDCONF "/etc/inetd.conf"
 #define _PATH_INETDPID  "/var/run/inetd.pid"
 
-#define TOOMANY         40              /* 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 */
-
-#ifndef OPEN_MAX
-#define OPEN_MAX        64
-#endif
+#define TOOMANY		40		/* 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 */
+#define MAXARGV		20
 
+#define se_ctrladdr		se_un.se_un_ctrladdr
+#define se_ctrladdr_in	se_un.se_un_ctrladdr_in
+#define se_ctrladdr_un	se_un.se_un_ctrladdr_un
 
 /* Reserve some descriptors, 3 stdio + at least: 1 log, 1 conf. file */
-#define FD_MARGIN       (8)
-static int     rlim_ofile_cur = OPEN_MAX;
-
-#ifdef RLIMIT_NOFILE
-static struct rlimit   rlim_ofile;
-#endif
+#define FD_MARGIN	(8)
 
 /* Check unsupporting builtin */
 #if defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO || \
@@ -173,7 +172,6 @@
 	const struct  biltin *se_bi;    /* if built-in, description */
 #endif
 	char    *se_server;             /* server program */
-#define MAXARGV 20
 	char    *se_argv[MAXARGV+1];    /* program arguments */
 	int     se_fd;                  /* open descriptor */
 	union {
@@ -181,9 +179,6 @@
 		struct  sockaddr_in se_un_ctrladdr_in;
 		struct  sockaddr_un se_un_ctrladdr_un;
 	} se_un;                        /* bound address */
-#define se_ctrladdr     se_un.se_un_ctrladdr
-#define se_ctrladdr_in  se_un.se_un_ctrladdr_in
-#define se_ctrladdr_un  se_un.se_un_ctrladdr_un
 	int     se_ctrladdr_size;
 	int     se_max;                 /* max # of instances of this service */
 	int     se_count;               /* number started since se_time */
@@ -191,21 +186,21 @@
 	struct  servtab *se_next;
 } *servtab;
 
-/* Length of socket listen queue. Should be per-service probably. */
-static int      global_queuelen = 128;
-
-static int      nsock, maxsock;
-static fd_set   allsock;
-static int      timingout;
-static sigset_t blockmask, emptymask;
-
+#ifdef INETD_FEATURE_ENABLED
+struct biltin {
+	const char *bi_service;         /* internally provided service name */
+	int bi_socktype;                /* type of socket supported */
+	short bi_fork;          /* 1 if should fork before call */
+	short bi_wait;          /* 1 if should wait for child */
+	void (*bi_fn)(int, struct servtab *); /* fn which performs it */
+};
 
-       /* Echo received data */
+    /* Echo received data */
 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO
 static void echo_stream(int, struct servtab *);
 static void echo_dg(int, struct servtab *);
 #endif
-	/* Internet /dev/null */
+    /* Internet /dev/null */
 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD
 static void discard_stream(int, struct servtab *);
 static void discard_dg(int, struct servtab *);
@@ -226,16 +221,6 @@
 static void chargen_dg(int, struct servtab *);
 #endif
 
-
-#ifdef INETD_FEATURE_ENABLED
-struct biltin {
-	const char *bi_service;         /* internally provided service name */
-	int bi_socktype;                /* type of socket supported */
-	short bi_fork;          /* 1 if should fork before call */
-	short bi_wait;          /* 1 if should wait for child */
-	void (*bi_fn)(int, struct servtab *); /* fn which performs it */
-};
-
 static const struct biltin biltins[] = {
 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO
 	/* Echo received data */
@@ -266,7 +251,23 @@
 };
 #endif  /* INETD_FEATURE_ENABLED */
 
+#ifdef RLIMIT_NOFILE
+static struct rlimit   rlim_ofile;
+#endif
+
+/* Length of socket listen queue. Should be per-service probably. */
+static int      global_queuelen = 128;
+
+static FILE *fconfig;
+static sigset_t	blockmask;
+static sigset_t	emptymask;
+static fd_set	allsock;
+static int	nsock;
+static int	maxsock;
+static int	timingout;
+static int	rlim_ofile_cur = OPEN_MAX;
 static const char *CONFIG = _PATH_INETDCONF;
+static FILE *fconfig;
 
 static void
 syslog_err_and_discard_dg(int se_socktype, const char *msg, ...)
@@ -285,10 +286,7 @@
 	_exit(1);
 }
 
-static FILE *fconfig;
-
-static FILE *
-setconfig(void)
+static FILE *setconfig(void)
 {
 	FILE *f = fconfig;
 
@@ -302,8 +300,7 @@
 	return f;
 }
 
-static char *
-skip(char **cpp)
+static char *skip(char **cpp)
 {
 	char *cp = *cpp;
 	char *start;
@@ -335,8 +332,7 @@
 	return (start);
 }
 
-static char *
-newstr(char *cp)
+static char *newstr(char *cp)
 {
 	cp = strdup(cp ? cp : "");
 	if (cp)
@@ -346,8 +342,7 @@
 }
 
 
-static struct servtab *
-getconfigent(void)
+static struct servtab *getconfigent(void)
 {
 	static struct servtab serv;
 	struct servtab *sep = &serv;
@@ -441,8 +436,7 @@
 	return (sep);
 }
 
-static void
-freeconfig(struct servtab *cp)
+static void freeconfig(struct servtab *cp)
 {
 	int i;
 
@@ -459,8 +453,7 @@
 static char **Argv;
 static char *LastArg;
 
-static void
-setproctitle(char *a, int s)
+static void setproctitle(char *a, int s)
 {
 	size_t size;
 	char *cp;
@@ -480,8 +473,7 @@
 }
 #endif  /* INETD_FEATURE_ENABLED */
 
-static struct servtab *
-enter(struct servtab *cp)
+static struct servtab *enter(struct servtab *cp)
 {
 	struct servtab *sep;
 	sigset_t oldmask;
@@ -499,8 +491,7 @@
 	return (sep);
 }
 
-static int
-bump_nofile(void)
+static int bump_nofile(void)
 {
 #ifdef RLIMIT_NOFILE
 
@@ -539,8 +530,7 @@
 }
 
 
-static void
-setup(struct servtab *sep)
+static void setup(struct servtab *sep)
 {
 	int on = 1;
 
@@ -575,8 +565,7 @@
 	}
 }
 
-static void
-config(int signum)
+static void config(int signum)
 {
 	struct servtab *sep, *cp, **sepp;
 	sigset_t oldmask;
@@ -705,8 +694,7 @@
 
 
 
-static void
-reapchild(int signum)
+static void reapchild(int signum)
 {
 	int status;
 	int pid;
@@ -734,8 +722,7 @@
 	}
 }
 
-static void
-retry(int signum)
+static void retry(int signum)
 {
 	struct servtab *sep;
 
@@ -753,8 +740,7 @@
 	}
 }
 
-static void
-goaway(int signum)
+static void goaway(int signum)
 {
 	struct servtab *sep;
 
@@ -768,11 +754,9 @@
 
 
 
-extern int
-inetd_main(int argc, char *argv[])
+extern int inetd_main(int argc, char *argv[])
 {
 	struct servtab *sep;
-	struct passwd *pwd;
 	struct group *grp = NULL;
 	struct sigaction sa;
 	int pid;
@@ -781,10 +765,7 @@
 	gid_t gid;
 
 #ifdef INETD_FEATURE_ENABLED
-	int dofork;
 	extern char **environ;
-#else
-# define dofork 1
 #endif
 
 	gid = getgid();
@@ -914,12 +895,11 @@
 		sigprocmask(SIG_BLOCK, &blockmask, NULL);
 		pid = 0;
 #ifdef INETD_FEATURE_ENABLED
-		dofork = (sep->se_bi == 0 || sep->se_bi->bi_fork);
+		if (sep->se_bi == 0 || sep->se_bi->bi_fork)
 #endif
-		if (dofork) {
+		{
 			if (sep->se_count++ == 0)
-			    (void)gettimeofday(&sep->se_time,
-				(struct timezone *)0);
+			    (void)gettimeofday(&sep->se_time, (struct timezone *)0);
 			else if (sep->se_count >= sep->se_max) {
 				struct timeval now;
 
@@ -947,19 +927,19 @@
 				}
 			}
 			pid = fork();
-		}
-		if (pid < 0) {
-			syslog(LOG_ERR, "fork: %m");
-			if (sep->se_socktype == SOCK_STREAM)
-				close(ctrl);
-			sigprocmask(SIG_SETMASK, &emptymask, NULL);
-			sleep(1);
-			continue;
-		}
-		if (pid && sep->se_wait) {
-			sep->se_wait = pid;
-			FD_CLR(sep->se_fd, &allsock);
-			nsock--;
+			if (pid < 0) {
+				syslog(LOG_ERR, "fork: %m");
+				if (sep->se_socktype == SOCK_STREAM)
+					close(ctrl);
+				sigprocmask(SIG_SETMASK, &emptymask, NULL);
+				sleep(1);
+				continue;
+			}
+			if (pid && sep->se_wait) {
+				sep->se_wait = pid;
+				FD_CLR(sep->se_fd, &allsock);
+				nsock--;
+			}
 		}
 		sigprocmask(SIG_SETMASK, &emptymask, NULL);
 		if (pid == 0) {
@@ -968,8 +948,9 @@
 				(*sep->se_bi->bi_fn)(ctrl, sep);
 			else
 #endif
-			      {
-				if ((pwd = getpwnam(sep->se_user)) == NULL) {
+			{
+				struct passwd *pwd = getpwnam(sep->se_user);
+				if (pwd == NULL) {
 					syslog_err_and_discard_dg(
 						sep->se_socktype,
 						"getpwnam: %s: No such user",
@@ -1041,8 +1022,7 @@
 
 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO
 /* Echo service -- echo data back */
-static void
-echo_stream(int s, struct servtab *sep)
+static void echo_stream(int s, struct servtab *sep)
 {
 	char buffer[BUFSIZE];
 	int i;
@@ -1055,8 +1035,7 @@
 }
 
 /* Echo service -- echo data back */
-static void
-echo_dg(int s, struct servtab *sep)
+static void echo_dg(int s, struct servtab *sep)
 {
 	char buffer[BUFSIZE];
 	int i;
@@ -1075,8 +1054,7 @@
 
 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD
 /* Discard service -- ignore data */
-static void
-discard_stream(int s, struct servtab *sep)
+static void discard_stream(int s, struct servtab *sep)
 {
 	char buffer[BUFSIZE];
 
@@ -1088,8 +1066,7 @@
 }
 
 /* Discard service -- ignore data */
-static void
-discard_dg(int s, struct servtab *sep)
+static void discard_dg(int s, struct servtab *sep)
 {
 	char buffer[BUFSIZE];
 	(void)sep;
@@ -1104,8 +1081,7 @@
 static char ring[128];
 static char *endring;
 
-static void
-initring(void)
+static void initring(void)
 {
 	int i;
 
@@ -1117,8 +1093,7 @@
 }
 
 /* Character generator */
-static void
-chargen_stream(int s, struct servtab *sep)
+static void chargen_stream(int s, struct servtab *sep)
 {
 	char *rs;
 	int len;
@@ -1149,8 +1124,7 @@
 }
 
 /* Character generator */
-static void
-chargen_dg(int s, struct servtab *sep)
+static void chargen_dg(int s, struct servtab *sep)
 {
 	struct sockaddr sa;
 	static char *rs;
@@ -1192,8 +1166,7 @@
  * some seventy years Bell Labs was asleep.
  */
 
-static long
-machtime(void)
+static long machtime(void)
 {
 	struct timeval tv;
 
@@ -1204,8 +1177,7 @@
 	return (htonl((long)tv.tv_sec + 2208988800UL));
 }
 
-static void
-machtime_stream(int s, struct servtab *sep)
+static void machtime_stream(int s, struct servtab *sep)
 {
 	long result;
 	(void)sep;
@@ -1214,8 +1186,7 @@
 	write(s, (char *) &result, sizeof(result));
 }
 
-static void
-machtime_dg(int s, struct servtab *sep)
+static void machtime_dg(int s, struct servtab *sep)
 {
 	long result;
 	struct sockaddr sa;
@@ -1233,16 +1204,14 @@
 
 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME
 /* Return human-readable time of day */
-static int
-human_readable_time_sprintf(char *buffer)
+static int human_readable_time_sprintf(char *buffer)
 {
 	time_t clocc = time(NULL);
 
 	return sprintf(buffer, "%.24s\r\n", ctime(&clocc));
 }
 
-static void
-daytime_stream(int s, struct servtab *sep)
+static void daytime_stream(int s, struct servtab *sep)
 {
 	char buffer[256];
 	size_t st = human_readable_time_sprintf(buffer);
@@ -1253,8 +1222,7 @@
 }
 
 /* Return human-readable time of day */
-static void
-daytime_dg(int s, struct servtab *sep)
+static void daytime_dg(int s, struct servtab *sep)
 {
 	char buffer[256];
 	struct sockaddr sa;




More information about the busybox-cvs mailing list