From owner-freebsd-bugs Fri Jul 12 8: 0:25 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 464A137B400 for ; Fri, 12 Jul 2002 08:00:12 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 58C4D43E3B for ; Fri, 12 Jul 2002 08:00:11 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g6CF0BJU036849 for ; Fri, 12 Jul 2002 08:00:11 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g6CF0Bml036848; Fri, 12 Jul 2002 08:00:11 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3650C37B400 for ; Fri, 12 Jul 2002 07:55:10 -0700 (PDT) Received: from mailhost.stack.nl (vaak.stack.nl [131.155.140.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id 77C9043E4A for ; Fri, 12 Jul 2002 07:55:09 -0700 (PDT) (envelope-from jilles@stack.nl) Received: from toad.stack.nl (toad.stack.nl [2001:610:1108:5010:202:b3ff:fe17:9e1a]) by mailhost.stack.nl (Postfix) with ESMTP id B6D7B3F97 for ; Fri, 12 Jul 2002 16:55:04 +0200 (CEST) Received: by toad.stack.nl (Postfix, from userid 1677) id 5D30998D1; Fri, 12 Jul 2002 16:55:04 +0200 (CEST) Message-Id: <20020712145504.5D30998D1@toad.stack.nl> Date: Fri, 12 Jul 2002 16:55:04 +0200 (CEST) From: Jilles Tjoelker Reply-To: Jilles Tjoelker To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/40486: [PATCH] kevent/kqueue does not work with virtual terminals Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 40486 >Category: kern >Synopsis: [PATCH] kevent/kqueue does not work with virtual terminals >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Jul 12 08:00:09 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Jilles Tjoelker >Release: FreeBSD 4.6-STABLE i386 >Organization: Eindhoven University of Technology >Environment: System: FreeBSD toad.stack.nl 4.6-STABLE FreeBSD 4.6-STABLE #0: Sun Jun 23 17:18:50 CEST 2002 marcolz@toad.stack.nl:/toad.mnt/sources/4.x/sys/compile/toad_vwww i386 The problem is also present on my laptop with 4.6-RELEASE: FreeBSD jaguar.stack.nl 4.6-RELEASE FreeBSD 4.6-RELEASE #1: Thu Jul 11 15:49:33 CEST 2002 jilles@jaguar.stack.nl:/usr/src/sys/compile/JAGUAR i386 >Description: Kevent/kqueue does not work with ttyv*, but it does work with pseudo terminals. >How-To-Repeat: Compile and run the program kevent.c When started on a virtual terminal, it gives the following error message: kevent: setup kevent: Operation not permitted This error message also occurs if the program is started as root. When started from xterm, a login via ssh or similar, it works as it should. >Fix: The following patch seems to make it work, but has not been tested a lot (only on my laptop running 4.6-RELEASE). select(2) and poll(2) work. --- syscons.c.patch begins here --- * Patch to: * $FreeBSD: src/sys/dev/syscons/syscons.c,v 1.336.2.13 2002/04/08 13:37:26 sobomax Exp $ --- /sys/dev/syscons/syscons.c.orig Mon Apr 8 15:37:26 2002 +++ /sys/dev/syscons/syscons.c Thu Jul 11 15:48:03 2002 @@ -213,8 +213,9 @@ /* maj */ CDEV_MAJOR, /* dump */ nodump, /* psize */ nopsize, - /* flags */ D_TTY, - /* bmaj */ -1 + /* flags */ D_TTY | D_KQFILTER, + /* bmaj */ -1, + /* kqfilter */ ttykqfilter }; int --- syscons.c.patch ends here --- --- kevent.c begins here --- /* Copyright (C) 2002 by Jilles Tjoelker */ #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { char buf[1024]; int kq; struct kevent E; struct timespec TS = { 0, 0 }; int n; if (argc != 1) { fprintf(stderr, "Usage: %s\n", argv[0]); return(1); } kq = kqueue(); if (kq == -1) err(1,"kqueue"); EV_SET(&E, STDIN_FILENO, EVFILT_READ, EV_ADD, 0, 0, NULL); if (kevent(kq, &E, 1, NULL, 0, &TS) == -1) err(1,"setup kevent"); for (;;) { TS.tv_sec = 5; TS.tv_nsec = 0; n = kevent(kq, NULL, 0, &E, 1, &TS); switch (n) { case 0: printf("timeout expired\n"); break; case 1: printf("data ready (%d)\n", E.data); n = read(STDIN_FILENO, buf, sizeof buf - 1); buf[n] = 0; printf("(%d) %s\n", n, buf); break; case -1: err(1, "kevent"); default: printf("unexpected kevent rc %d\n", n); } } return 0; } /* vim:ts=8:cin:sw=4:kp=man\ -S3\:2\:9\:1\:4\:5\:6\:7\:8\:n * */ --- kevent.c ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message