SIGPIPE propagation

Martin Laabs martin.laabs at mailbox.tu-dresden.de
Sat Mar 1 13:38:25 UTC 2008


Hello,

as you probably know I want to expand dump in such
a way it enableds multivolume dumps also when the
output data is written to stdout/a pipe.
Now I ran into a serious problem.
Dump counts the written bytes to remember where
it has to proceede after the volumen change.
Now the SIGPIPE signal does not propagate fast
enought through the system. Thus dump writes
some time after the pipe has got broken data into
the pipe while it doesn't exist anymore. This short
time it does not receive any error about that.
(Until the signal propagates to dump.)
I wrote a small test progam to demonstrate this
effect (and get clear about it by myself). It just
write data to stdout and counts it until the pipe
is broken (and the write call will return -1) This
is the output of a few successively runs:


$ ./a.out |asdf
$ asdf: command not found
cought broken pipe
i: 12 could only wrote -1 bytes. total wrote: 61440

$ ./a.out |asdf
$ asdf: command not found
cought broken pipe
i: 1 could only wrote -1 bytes. total wrote: 5120

$ ./a.out |asdf
$ asdf: command not found
cought broken pipe
i: 12 could only wrote -1 bytes. total wrote: 61440

$ ./a.out |asdf
$ asdf: command not found
cought broken pipe
i: 0 could only wrote -1 bytes. total wrote: 0


Dump encounters the same effect and I don't know how
to handle this problem. Do you have any idea how I
can manage this?

Thank you,
  Martin L.

PS: Here's the code of the small test-program:

-----------------:<----------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/errno.h>
#include <fcntl.h>
#include <signal.h>

#define MUL 5
char            buffer    [1024 * MUL];

void
sigpipe(int signo __unused)
{
         fprintf(stderr, "cought broken pipe\n");
}

main()
{
         int             i         , w;
         int             wr = 0;

         signal(SIGPIPE, sigpipe);

         for (i = 0; i <= 100; i++) {
                 w = write(STDOUT_FILENO, buffer, MUL * 1024);
                 if (w > 0)
                         wr += w;
                 if (w != 1024 * MUL) {
                         fprintf(stderr, "i: %d could only wrote %d bytes.  
total
                         break;
                 }
         }
}
------------------------:<--------------------------------


More information about the freebsd-hackers mailing list