[PATCH] blktrace.c should ignore SIGPIPE
authorAlex Polvi <alex@polvi.net>
Mon, 8 May 2006 05:15:50 +0000 (07:15 +0200)
committerJens Axboe <axboe@suse.de>
Mon, 8 May 2006 05:15:50 +0000 (07:15 +0200)
commit38e1f0c68bb7a808d889e639530c69830d110f75
tree8fe94b548b2d8650c58e722e8a92b695b218b7cb
parent1452478f2d1b27916c7cba6e3976ed2129533c73
[PATCH] blktrace.c should ignore SIGPIPE

After sending a SIGINT to a "blktrace .. | blkparse .. " pipeline,
occasionally I would not be able to run blktrace again. On my next run
of the same pipeline I would get the following error:

cs411vm:/usr/src/bt# ./blktrace -d /dev/sdb -o - | ./blkparse -i -
BLKTRACESETUP: No such file or directory
Failed to start trace on /dev/sdb

After rebooting, I could reproduce this by starting the pipeline, and
kicking off a big write and sending a SIGINT to blktrace. The following
is what I used for a write:

while [ 1 ]
do
    dd if=/dev/zero of=/test/write bs=1M
done

It seemed like blktrace was not handling signals correctly, so I
strace'd the process to see what was happening.

Sure enough:

--- SIGINT (Interrupt) @ 0 (0) ---
ioctl(3, 0x1275, 0xb7fa6000)            = 0
sigreturn()                             = ? (mask now [])
write(1, "O\0\0\0\20\0\200\0\0\0\0\0\0\0\0\0\7taeN3\1\0\257R\260"...,
4096) = -1 EPIPE (Broken pipe)
--- SIGPIPE (Broken pipe) @ 0 (0) ---
+++ killed by SIGPIPE +++

Any idea what clean-up is not happening? I tried to figure it out, but
my only work-around was a reboot.

My patch against 2.6.17-rc3 just tells blktrace to ignore SIGPIPE.
Nothing crazy. :) blktrace already does enough error checking elsewhere
to handle a bad write.

On a completely unrelated note, the write_data function calls fwrite,
which will not return -1 on error. Instead you'll need to use ferror to
check if there was a problem. I'm not sure if this is a cause of any
bugs, but it seemed worth mentioning.

Furthermore, I updated the URLs in the documentation to point at a valid
git repo.
blktrace.c
doc/blktrace.tex