From owner-freebsd-chat Sat Jul 21 8:16:21 2001 Delivered-To: freebsd-chat@freebsd.org Received: from cache1.hck.carroll.com (cache1.hck.carroll.com [216.44.20.19]) by hub.freebsd.org (Postfix) with ESMTP id 2853C37B401 for ; Sat, 21 Jul 2001 08:16:17 -0700 (PDT) (envelope-from damien@carroll.com) Received: from sprig.tougas.net ([216.44.20.42] verified) by cache1.hck.carroll.com (CommuniGate Pro SMTP 3.2.4) with ESMTP id 4113007 for chat@freebsd.org; Sat, 21 Jul 2001 11:16:15 -0400 Received: from sprig.tougas.net (localhost [127.0.0.1]) by sprig.tougas.net (Postfix) with ESMTP id 1F29D379 for ; Sat, 21 Jul 2001 11:16:15 -0400 (EDT) Date: Sat, 21 Jul 2001 11:16:14 -0400 From: Damien Tougas To: chat@freebsd.org Subject: C newbie needs help with kqueue Message-ID: <2042320000.995728574@sprig.tougas.net> X-Mailer: Mulberry/2.1.0b2 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org Hello, I am writing a simple program to try to learn a little bit about kqueue, but I seem to be having a problem with the file descriptor I am passing. It is probably a simple thing, but since I am quite green, the problem is not obvious to me. Perhaps someone could help me out. When I run this program, I get: Cannot create kevent: Bad file descriptor Thanks for your help. --- Damien Tougas Systems Administrator Carroll-Net, Inc. http://www.carroll.com #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fp; int i; int kq, nev; struct kevent kev, ev; struct timespec ts = { 0, 0 }; if ((fp = fopen("/var/log/messages", "r")) == NULL) { perror("Cannot open file\n"); return -1; } if (fseek(fp, 0L, SEEK_END) < 0) { perror("Cannot seek end of file"); return -1; } if (kq = kqueue() < 0) { perror("Cannot create kqueue"); } EV_SET(&kev, fileno(fp), EVFILT_READ, EV_ADD | EV_ENABLE, 0 , 0, 0); if (kevent(kq, &kev, 1, NULL, 0, &ts) < 0) { perror("Cannot create kevent"); return -1; } for (;;) { if (kevent(kq, NULL, 0, &ev, 1, NULL) > 0) { printf("File Changed!!!\n"); } else { usleep(10000); } } } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message