From owner-freebsd-current@FreeBSD.ORG Sat Dec 20 16:27:54 2008 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8F1371065677; Sat, 20 Dec 2008 16:27:54 +0000 (UTC) (envelope-from nork@FreeBSD.org) Received: from sakura.ninth-nine.com (unknown [IPv6:2001:2f0:104:80a0:230:48ff:fe41:2455]) by mx1.freebsd.org (Postfix) with ESMTP id 14BEA8FC1E; Sat, 20 Dec 2008 16:27:53 +0000 (UTC) (envelope-from nork@FreeBSD.org) Received: from nadesico.ninth-nine.com (nadesico.ninth-nine.com [219.127.74.122]) by sakura.ninth-nine.com (8.14.1/8.14.1/NinthNine) with SMTP id mBKGRqIG022997; Sun, 21 Dec 2008 01:27:53 +0900 (JST) (envelope-from nork@FreeBSD.org) Date: Sun, 21 Dec 2008 01:27:52 +0900 From: Norikatsu Shigemura To: Ed Schouten Message-Id: <20081221012752.cdc5cbfc.nork@FreeBSD.org> X-Mailer: Sylpheed 2.5.0 (GTK+ 2.12.11; i386-portbld-freebsd8.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (sakura.ninth-nine.com [219.127.74.121]); Sun, 21 Dec 2008 01:27:53 +0900 (JST) Cc: freebsd-current@FreeBSD.org, Norikatsu Shigemura Subject: Change select(2) to kevent(2) on script(1)... X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Dec 2008 16:27:54 -0000 Hi Ed! I inspired by your 'kqueue()-support to pseudo-terminal master devices' (svn commit: r185942). So I'm trying to use kevent(2) on script(1). (SEE ALSO following patch) But it doesn't work. Because 'master' file descriptor (from openpty(3)) doesn't return last 0 byte data readable when shell exit. In this case of select(2), 'master' file descriptor gets 0 byte data and exit script(1). Do you have any idea? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --- usr.bin/script/script.c.orig 2004-02-16 02:30:13.000000000 +0900 +++ usr.bin/script/script.c 2008-12-21 00:59:59.929804968 +0900 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -85,11 +86,12 @@ struct termios rtt, stt; struct winsize win; int aflg, kflg, ch, n; - struct timeval tv, *tvp; + struct timespec ts, *tsp; time_t tvec, start; char obuf[BUFSIZ]; char ibuf[BUFSIZ]; - fd_set rfd; + int kq; + struct kevent kev[2]; int flushtime = 30; aflg = kflg = 0; @@ -160,23 +162,29 @@ doshell(argv); if (flushtime > 0) - tvp = &tv; + tsp = &ts; else - tvp = NULL; + tsp = NULL; start = time(0); - FD_ZERO(&rfd); + + if ((kq = kqueue()) < 0) + err(1, "kqueue"); + + EV_SET(&kev[0], master, EVFILT_READ, EV_ADD, 0, 0, NULL); + EV_SET(&kev[1], STDIN_FILENO, EVFILT_READ, EV_ADD, 0, 0, NULL); + if (kevent(kq, kev, 2, NULL, 0, NULL) < 0) + err(1, "kevent"); + for (;;) { - FD_SET(master, &rfd); - FD_SET(STDIN_FILENO, &rfd); if (flushtime > 0) { - tv.tv_sec = flushtime; - tv.tv_usec = 0; + ts.tv_sec = flushtime; + ts.tv_nsec = 0; } - n = select(master + 1, &rfd, 0, 0, tvp); + n = kevent(kq, NULL, 0, kev, 1, tsp); if (n < 0 && errno != EINTR) break; - if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) { + if (n > 0 && kev[0].ident == STDIN_FILENO) { cc = read(STDIN_FILENO, ibuf, BUFSIZ); if (cc < 0) break; @@ -190,7 +198,7 @@ } } } - if (n > 0 && FD_ISSET(master, &rfd)) { + if (n > 0 && kev[0].ident == master) { cc = read(master, obuf, sizeof (obuf)); if (cc <= 0) break; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -