Date: Sat, 01 Mar 2008 14:38:17 +0100 From: "Martin Laabs" <martin.laabs@mailbox.tu-dresden.de> To: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: SIGPIPE propagation Message-ID: <op.t7cat3oq724k7f@martin>
next in thread | raw e-mail | index | archive | help
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 =3D 0; signal(SIGPIPE, sigpipe); for (i =3D 0; i <=3D 100; i++) { w =3D write(STDOUT_FILENO, buffer, MUL * 1024); if (w > 0) wr +=3D w; if (w !=3D 1024 * MUL) { fprintf(stderr, "i: %d could only wrote %d byte= s. = total break; } } } ------------------------:<--------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?op.t7cat3oq724k7f>