[comp.unix.questions] Interrupted system call during pipe fwrite/fread

flynn@pixel.cps.msu.edu (Patrick J. Flynn) (09/18/89)

I'm developing an image-processing application under Suntools which reads
and write large files (500K or more), which are normally stored using
LZW compression.  In my application, I have simple code which
determines whether the requested file to be read (written) is
(should be) compressed, or not.  Here's a code outline for reading:

----------------------
FILE *fp;
char pipemode=FALSE;

if (filename ends in .Z) {
  fp=popen("zcat filename","r");
  pipemode = TRUE;
  }
else
  fp=fopen(filename,"r");

if (!fp) {
  print a nasty message
  return FALSE;
  };

if (1 != (fread(buf,sizeof(thing),1,fp))) {
  perror("error reading thing:")
  return FALSE;
  }

if (pipemode)
  pclose(fp)
else
  fclose(fp);
----------------------

[ The code for writing is similar; zcat changes to "compress -f >filename",
the [fp]open mode to "w", and fread to fwrite. ]

This code *always* works when uncompressed files are being read or written.
Occasionally during reads, and almost always during writes of compressed
files, the perror is called, with errno set to EINTR 
("error reading thing: interrupted system call").

I use this same code in a lot of other (non-Suntools) programs, and
everything works fine.  I've read the Suntools documentation, and
nothing jumped out of the pages at me.

Are my pipe writes/reads interacting with Suntools' processing of
signals in some way?  Any way I can catch whatever signal is getting
through to clobber my fread/fwrite?  You have to catch signals differently
under Suntools.

TIA.  Please respond by email, and I'll summarize to the net.

[ I would post this to Sun-Spots as well, but it seems to be incredibly
constipated nowadays.  Nothing for weeks, then a couple of hundred articles
in one day. Yech.]
------------------------------------------------------------------------------
Patrick Flynn, CS, Mich. State Univ. -- flynn@cps.msu.edu -- uunet!frith!flynn