Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site bu-cs.UUCP
Path: utzoo!linus!philabs!prls!amdimage!amdcad!amd!vecpyr!lll-crg!gymble!umcp-cs!seismo!harvard!bu-cs!root
From: root@bu-cs.UUCP (Barry Shein)
Newsgroups: net.lang.c,net.news,net.bugs
Subject: Re: Not checking printf's result causes another news bug
Message-ID: <584@bu-cs.UUCP>
Date: Fri, 16-Aug-85 14:33:26 EDT
Article-I.D.: bu-cs.584
Posted: Fri Aug 16 14:33:26 1985
Date-Received: Tue, 20-Aug-85 03:59:43 EDT
References: <11@brl-tgr.ARPA> <1288@eagle.UUCP> <15908@watmath.UUCP>
Organization: Boston Univ Comp. Sci.
Lines: 36
Xref: linus net.lang.c:5557 net.news:3017 net.bugs:607


All this talk about printf() return values not being checked causing
various catastrophes reminds me of another system that had what might
provide a good back-door solution to this without very much re-coding,
namely the IBM/OS SYNAD=addr option. You could set up a (in unix lingo)
a signal handler and if any I/O error occurred it would interrupt to
that routine. Now this was on a per-write (actually, per I/O) basis but
what I have in mind here is to do something like:

#define printf eprintf
#define fprintf efprintf

then add to main() something like

	signal(SIGIOT,myhandler) ;	/* choose a signal, SIGIOT seems good*/

and something reasonable for myhandler() and finally:

eprintf(fmt,a,b,c,d,e,f,g...)	/* etc or maybe use varargs */
{
	int n ;

	if((n = printf(fmt,a,b,...)) < 0)
		kill(0,SIGIOT) ;
	return(n) ;
}
and almost exactly the same for efprintf(fp,...).

(of course, the file with these routines must *not* have the #defines.

Then of course, you get to decide what to do now that you have the
error, but saves you from a lot of re-working of code.

	-Barry Shein, Boston University

Just a suggestion.