From owner-freebsd-newbies Mon Jan 13 17:51:49 2003 Delivered-To: freebsd-newbies@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C525237B401 for ; Mon, 13 Jan 2003 17:51:47 -0800 (PST) Received: from txsmtp03.texas.rr.com (smtp3.texas.rr.com [24.93.36.231]) by mx1.FreeBSD.org (Postfix) with ESMTP id 10BAF43E4A for ; Mon, 13 Jan 2003 17:51:42 -0800 (PST) (envelope-from foxbsd@gristle.to) Received: from oct.gristle.to (cs242730-125.austin.rr.com [24.27.30.125]) by txsmtp03.texas.rr.com (8.12.5/8.12.2) with ESMTP id h0E1lsEM001404; Mon, 13 Jan 2003 20:47:56 -0500 (EST) Message-Id: <5.0.2.1.0.20030113194731.026c8690@pop-server.austin.rr.com> X-Sender: (Unverified) X-Mailer: QUALCOMM Windows Eudora Version 5.0.2 Date: Mon, 13 Jan 2003 19:50:22 -0600 To: Giorgos Keramidas From: Fox Subject: Re: detecting open cd drive Cc: freebsd-newbies@FreeBSD.ORG In-Reply-To: <20030113234819.GA3695@gothmog.gr> References: <5.0.2.1.0.20030113091738.02802130@pop-server.austin.rr.com> <20030110031616.359a7dcc.one-@madridwireless.net> <5.0.2.1.0.20030113091738.02802130@pop-server.austin.rr.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-freebsd-newbies@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org At 01:48 AM 1/14/03 +0200, Giorgos Keramidas wrote: >On 2003-01-13 09:20, foxbsd@gristle.to (Fox) wrote: > > Is there a way to detect that the cdrom drive has been closed from > > userland. I want to launch a script triggered by the cdrom drive > > tray closing. > > > > I am using FreeBSD 4.7 > >You could probably poll using ioctl(fd, CDIOREADTOCHEADER, ...) but >this is something I haven't tested :-/ Thanks that worked out very well, and here is the code: int fd = 0; fd = open("/dev/acd0c", O_RDONLY); while(1) { success = ioctl(fd, CDIOREADTOCHEADER, &ith); if (success != -1) { close(fd); execl("/home/user/test.py", 0); } else { close (fd); sleep(2); // try again. fd = open("/dev/acd0c", O_RDONLY); } } >To Unsubscribe: send mail to majordomo@FreeBSD.org >with "unsubscribe freebsd-newbies" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-newbies" in the body of the message