Date: Fri, 12 Jul 2002 16:55:04 +0200 (CEST) From: Jilles Tjoelker <jilles+fbsd-bugs@stack.nl> To: FreeBSD-gnats-submit@FreeBSD.org Subject: kern/40486: [PATCH] kevent/kqueue does not work with virtual terminals Message-ID: <20020712145504.5D30998D1@toad.stack.nl>
next in thread | raw e-mail | index | archive | help
>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 <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <err.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020712145504.5D30998D1>
