help needed on a unix system-call question

was-John McMillan jcm at mtunb.ATT.COM
Sat Mar 11 00:49:18 AEST 1989


In article <1134 at auspex.UUCP> guy at auspex.UUCP (Guy Harris) writes:
>>In my code I use a signal (SIGALRM), system-call, following which is a 'read'
>>...
>...
>for more data, and *then* gets interrupted by a signal, is the data it
>transferred more-or-less lost", the answer is "yes, and this happens
>under 4.xBSD as well".  The problem is that, since you get a -1 back
>from the "read", rather than a count of the number of bytes read, you
>have no idea how much data was actually transferred. 

"More or less lost"?  "Unnoticed" may be more like it,
IF MY RECOLLECTIONS ARE CORRECT.  (When did that last occur?)
I can't RECALL any place for the characters to BE lost (in
traditional tty reads -- as opposed to STREAMS, which I've paid
little attention to), so I presume they're all in the user's buffer.

A workaround?  'Hate these -- will you still respect me in the morning?
(OK: neither do I.)

#define	BKGND	'\0'

SRead(f,b,l) char *b;		/* read args */
{	register	int i;
	register	char *c;
	extern		int	errno;

	errno = 0;	/* ZERO out the errno flag -- so it can be tested
			 *	after SRead() to detect interrupt IYGAD
			 */
	
			/* ZERO out the read buffer: its cheaper if you
			 *	know the dirty-bits -- ie., if you only
			 *	zap length of soiled bytes.
			 * OK: ZERO is 'NUL-ist' -- AA requires us to
			 *	give more-than-equal consideration to
			 *	other background chars.
			 */
	for ( i=l, c=b; i-- > 0; *c++ = BKGND);

			/* Only calculate kength when nec.
			 */
	if ( (i=read(f,b,l) < 0 ) )
			/* Back-Scanning vs. Forward-Scanning:
			 *	Wasted effort vs minimum of lost BKGNDs
			 */
		for ( c=b+l, i=l+1; --i > 0 && *--c == BKGND; );
	return i;
}
NB:
	It is a 30-second HACK.
	It is neither debugged nor fully general.
	It is far from optimized -- there are conflicting strategies.

The IDEA is that you can often infer the LENGTH of data if you can
"see" it against a known -- preferably un-receivable -- background.

There are multiple attacks and defenses for details of the above
implementation.  Someone must care about them: Wire Paladin, San Francisco.

jcm	-- juzz muttering



More information about the Comp.unix.wizards mailing list