From owner-freebsd-questions@FreeBSD.ORG Sat Jun 5 01:06:31 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E569116A4CE for ; Sat, 5 Jun 2004 01:06:31 -0700 (PDT) Received: from web21101.mail.yahoo.com (web21101.mail.yahoo.com [216.136.227.103]) by mx1.FreeBSD.org (Postfix) with SMTP id DB1AC43D2D for ; Sat, 5 Jun 2004 01:06:31 -0700 (PDT) (envelope-from materribile@yahoo.com) Message-ID: <20040605080623.54649.qmail@web21101.mail.yahoo.com> Received: from [24.228.74.10] by web21101.mail.yahoo.com via HTTP; Sat, 05 Jun 2004 01:06:23 PDT Date: Sat, 5 Jun 2004 01:06:23 -0700 (PDT) From: Mark Terribile To: freebsd-questions@freebsd.org In-Reply-To: <20040527190051.8F59816A4E8@hub.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii cc: "Gustafson, Tim" Subject: vi, threading, EAGAIN, nonblocking (was: Error: input: Resource temporarily unavailable) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Jun 2004 08:06:32 -0000 [Sorry if this has been answered; I'm catching up on freebsd-questions and I haven't seen it in the next seven or eight digests.] Tim Gustafson writes: >I am getting the following error in "vi" pretty consistently: >Error: input: Resource temporarily unavailable >Usually I get this at every attempt I make to run vi. Here's the scenario I found for this: A threaded program (before 5.x and the new threading system) will turn on Nonblocking on ALL the program's file descriptors, including stdin, stdout, and stderr. This setting is not on the process but on the open, which is shared between processes (and thus, between various programs that run at a given terminal, including the shell). An unsophisticated, innocent program will try to do a read(2) on the terminal, expecting to block waiting for input. Instead, it will receive an EAGAIN, which basically means ``use poll(), select(), or kevent() to wait until the input is _really_ there.'' So now vi/nvi has an input terminal that doesn't behave like a terminal is supposed to behave; it's getting an EAGAIN, and it does the safest thing it knows: it reports the problem and goes away. I use this little program to check for Nonblocking and restore the normal (Blocking) state on the tty: #include #include #include #include bool checkfd( int fd ); int main() { return checkfd( 0 ) && checkfd( 1 ) && checkfd( 2 ) ? 0 : 1; } bool checkfd( int fd ) { int flags = fcntl( fd, F_GETFL, 0 ); if( flags == -1 ) { cerr << "Fd " << fd << ": " << strerror( errno ) << endl ; return false; } cout << fd << ( ( flags & O_NONBLOCK ) ? " nonblocking" : " blocking" ) << endl ; if( ! ( flags & O_NONBLOCK ) ) cerr << "blocking" << endl ; else { cerr << "nonblocking" << endl ; if( fcntl( fd, F_SETFL, flags & ~O_NONBLOCK ) == -1 ) { cerr << "Couldn't set O_NONBLOCK: " << errno << " " << strerror( errno ) << endl ; return false; } } return true; } Hope this helps. Mark Terribile __________________________________ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/