From owner-svn-src-head@freebsd.org Mon Mar 20 17:57:25 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EC4FDD14BFF; Mon, 20 Mar 2017 17:57:25 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C6DA3299; Mon, 20 Mar 2017 17:57:25 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2KHvOBq043360; Mon, 20 Mar 2017 17:57:24 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2KHvOkR043359; Mon, 20 Mar 2017 17:57:24 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201703201757.v2KHvOkR043359@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Mon, 20 Mar 2017 17:57:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315644 - head/usr.sbin/inetd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Mar 2017 17:57:26 -0000 Author: hrs Date: Mon Mar 20 17:57:24 2017 New Revision: 315644 URL: https://svnweb.freebsd.org/changeset/base/315644 Log: Simplify a pipe for signal handling. Modified: head/usr.sbin/inetd/inetd.c Modified: head/usr.sbin/inetd/inetd.c ============================================================================== --- head/usr.sbin/inetd/inetd.c Mon Mar 20 17:46:33 2017 (r315643) +++ head/usr.sbin/inetd/inetd.c Mon Mar 20 17:57:24 2017 (r315644) @@ -214,7 +214,6 @@ __FBSDID("$FreeBSD$"); #endif static void close_sep(struct servtab *); static void flag_signal(int); -static void flag_config(int); static void config(void); static int cpmip(const struct servtab *, int); static void endconfig(void); @@ -224,11 +223,9 @@ static struct servtab *getconfigent(void static int matchservent(const char *, const char *, const char *); static char *nextline(FILE *); static void addchild(struct servtab *, int); -static void flag_reapchild(int); static void reapchild(void); static void enable(struct servtab *); static void disable(struct servtab *); -static void flag_retry(int); static void retry(void); static int setconfig(void); static void setup(struct servtab *); @@ -532,17 +529,17 @@ main(int argc, char **argv) } #endif - sa.sa_flags = 0; + sa = (struct sigaction){ + .sa_flags = 0, + .sa_handler = flag_signal, + }; sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask, SIGALRM); sigaddset(&sa.sa_mask, SIGCHLD); sigaddset(&sa.sa_mask, SIGHUP); - sa.sa_handler = flag_retry; sigaction(SIGALRM, &sa, &saalrm); config(); - sa.sa_handler = flag_config; sigaction(SIGHUP, &sa, &sahup); - sa.sa_handler = flag_reapchild; sigaction(SIGCHLD, &sa, &sachld); sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, &sapipe); @@ -591,30 +588,34 @@ main(int argc, char **argv) } /* handle any queued signal flags */ if (FD_ISSET(signalpipe[0], &readable)) { - int nsig; + int nsig, signo; + if (ioctl(signalpipe[0], FIONREAD, &nsig) != 0) { - syslog(LOG_ERR, "ioctl: %m"); - exit(EX_OSERR); + syslog(LOG_ERR, "ioctl: %m"); + exit(EX_OSERR); } + nsig /= sizeof(signo); while (--nsig >= 0) { - char c; - if (read(signalpipe[0], &c, 1) != 1) { - syslog(LOG_ERR, "read: %m"); - exit(EX_OSERR); - } - if (debug) - warnx("handling signal flag %c", c); - switch(c) { - case 'A': /* sigalrm */ - retry(); - break; - case 'C': /* sigchld */ - reapchild(); - break; - case 'H': /* sighup */ - config(); - break; - } + size_t len; + + len = read(signalpipe[0], &signo, sizeof(signo)); + if (len != sizeof(signo)) { + syslog(LOG_ERR, "read: %m"); + exit(EX_OSERR); + } + if (debug) + warnx("handling signal flag %d", signo); + switch (signo) { + case SIGALRM: + retry(); + break; + case SIGCHLD: + reapchild(); + break; + case SIGHUP: + config(); + break; + } } } for (sep = servtab; n && sep; sep = sep->se_next) @@ -900,11 +901,12 @@ main(int argc, char **argv) */ static void -flag_signal(int c) +flag_signal(int signo) { - char ch = c; + size_t len; - if (write(signalpipe[1], &ch, 1) != 1) { + len = write(signalpipe[1], &signo, sizeof(signo)); + if (len != sizeof(signo)) { syslog(LOG_ERR, "write: %m"); _exit(EX_OSERR); } @@ -932,16 +934,6 @@ addchild(struct servtab *sep, pid_t pid) disable(sep); } -/* - * Some child process has exited. See if it's on somebody's list. - */ - -static void -flag_reapchild(int signo __unused) -{ - flag_signal('C'); -} - static void reapchild(void) { @@ -981,12 +973,6 @@ reapchild(void) } static void -flag_config(int signo __unused) -{ - flag_signal('H'); -} - -static void config(void) { struct servtab *sep, *new, **sepp; @@ -1250,12 +1236,6 @@ unregisterrpc(struct servtab *sep) } static void -flag_retry(int signo __unused) -{ - flag_signal('A'); -} - -static void retry(void) { struct servtab *sep;