From owner-freebsd-questions Sun Oct 8 21:35:21 1995 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id VAA23221 for questions-outgoing; Sun, 8 Oct 1995 21:35:21 -0700 Received: from mail.telstra.com.au (mail.telstra.com.au [192.148.160.10]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id VAA23209 for ; Sun, 8 Oct 1995 21:35:06 -0700 Received: from mail_gw.fwall.telecom.com.au(192.148.147.10) by mail via smap (V1.3) id sma005470; Mon Oct 9 14:13:28 1995 Received: from cdn_mail.dn.itg.telecom.com.au(144.135.109.134) by mail_gw.telecom.com.au via smap (V1.3) id sma024423; Mon Oct 9 14:13:04 1995 Received: from rodin.cssc-syd.tansu.com.au (rodin.cssc-syd.tansu.com.au [149.135.252.15]) by cdn_mail.dn.itg.telecom.com.au (8.6.11/8.6.9) with ESMTP id OAA00588; Mon, 9 Oct 1995 14:13:03 +1000 Received: from crab.cssc-syd.tansu.com.au (crab.ind.tansu.com.au [149.135.100.23]) by rodin.cssc-syd.tansu.com.au (8.6.11/8.6.9) with ESMTP id OAA03689; Mon, 9 Oct 1995 14:13:02 +1000 Received: from kiwi.cssc-syd.tansu.com.au (raoul@kiwi.cssc-syd.tansu.com.au [149.135.104.48]) by crab.cssc-syd.tansu.com.au (8.6.9/8.6.9) with ESMTP id OAA24609; Mon, 9 Oct 1995 14:12:59 +1000 Received: (raoul@localhost) by kiwi.cssc-syd.tansu.com.au (8.6.9/8.6.9) id OAA07782; Mon, 9 Oct 1995 14:12:58 +1000 Message-Id: <199510090412.OAA07782@kiwi.cssc-syd.tansu.com.au> Subject: Re: Question on read syscall on serial port To: julian@ref.tfs.com (Julian Elischer) Date: Mon, 9 Oct 1995 14:12:58 +1000 (EST) Cc: raoul@cssc-syd.tansu.com.au, freebsd-questions@freebsd.org In-Reply-To: <199510090318.UAA14415@ref.tfs.com> from "Julian Elischer" at Oct 8, 95 08:18:30 pm From: raoul@cssc-syd.tansu.com.au (Raoul Golan) X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Length: 3525 Sender: owner-questions@freebsd.org Precedence: bulk > > > > > Hello people, > > > > I'm reading from a modem on /dev/cua*. It's a blocking read, > > which means I expect it to wait there until data is available, > > or until the modem loses carrier, or until an error occurs. > > > > At the moment, when the modem loses carrier, the read syscall > > returns a count of 0 data read, but it does not set errno to > > anything (it leaves errno with the same value it had before the > > call). > > > > Is there any way (via an ioctl, a fcntl, an stty(?) or via some > > modem configuration parameter) of having the read syscall put > > some value into errno, such as ENOENT or EIO, when the modem > > loses carrier? > Returning 0 bytes on a blocking call is considered "Notification of EOF" > > This is the logical definition of loss of carrier is it not? > you could arange to get a signal possibly.. (I'd have ot go back and look > again).. Absolutely. I've no problem with that. Except that tip checks errno in order to decide whether to exit or not (in tipout.c) If errno has not been set, it simply loops. Don't know if that's a problem with the tip code, or whether it's something else. That's why I get tip looping after the modem loses its carrier. One way of getting tipout to exit is for it to receive a signal from its parent process - I can do this by hitting any key after carrier is lost, and tipin() in tip.c will send the child a signal. > > > > > I ask this because in the tip code there is a loop > > that exits only once errno is set to these values. This > > means that after the modem's lost carrier my tip session > > fails to exit. > > > > The code is as follows: > > > > /* while some condition */ > > > > cnt = read(FD, buf, BUFSIZ); > > if (cnt <= 0) { > > /* lost carrier */ > > if (cnt < 0 && errno == EIO) { > > sigblock(sigmask(SIGTERM)); > > intTERM(); > > /*NOTREACHED*/ > > } else if (cnt == 0 && errno == ENOENT) { > > kill(getppid(),SIGUSR1); > > sigblock(sigmask(SIGTERM)); > > intTERM(); > > /*NOTREACHED*/ > > } else { > > printf("%d %d\r",cnt,errno); > > fflush(stdout); > > } > > continue; > > } > > /* end */ > > > > Thanks, > > > > Raoul. > > > > hmm interesting.. lemme see what psix says.. (if anything...) > nothing in read() > > hey are you openning cuax or ttyX? > My tip has been configured to open /dev/cuax. I'm assuming that tip isn't doing anything funny, and that FD points to /dev/cuax as well. I've changed the code above to be: /* while some condition */ cnt = read(FD, buf, BUFSIZ); if (cnt <= 0) { /* lost carrier */ if (cnt <= 0) { kill(getppid(),SIGUSR1); sigblock(sigmask(SIGTERM)); intTERM(); /*NOTREACHED*/ } continue; } /* end */ and now tip exits cleanly. But I wonder why it was written as it was in the first place. Raoul