[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: loadable cat bug?
From: |
Ángel |
Subject: |
Re: loadable cat bug? |
Date: |
Tue, 22 Jan 2019 21:51:33 +0100 |
On 2019-01-21 at 20:03 -0600, Peng Yu wrote:
> When I use the loadable cat, I may get the following error. The input
> is a fifo in this specific case.
>
> cat: cannot open /tmp/tmp.VXkbqFlPtH: Interrupted system call
>
> So far, I can not make a minimal script to demonstrate the problem.
> But if I replace it with coreutils cat in my code, the problem is
> gone.
>
> Does anybody know what could cause this error?
Hello
The loadable cat is getting interrupted during an open() call (due to a
signal, usually), which is quite odd. Generally open(2) is immediate,
but in the case of a fifo, open(, O_RDONLY) doesn't return until the
pipe is opened for writing. So, if a signal is received at that point,
cat will fail with this error. This is easy to reproduce on bash 4.x by
simply resizing the window. On bash-5.0 SIGWINCH was changed to use
SA_RESTART so it's not an issue.
Can you figure out if it may be getting interrupted by a different
reason?
It would be simple to avoid the symptom with eg. the following trivial
patch. However, that would also not allow ending the cat by a Ctrl-C.
If that was just a matter of the window getting resized, bash 5 already
fixed it.
Best regards
diff --git a/examples/loadables/cat.c b/examples/loadables/cat.c
index be99c4c..dc8246d 100644
--- a/examples/loadables/cat.c
+++ b/examples/loadables/cat.c
@@ -71,7 +71,10 @@ char **argv;
if (argv[i][0] == '-' && argv[i][1] == '\0')
fd = 0;
else {
- fd = open(argv[i], O_RDONLY, 0666);
+ do {
+ fd = open(argv[i], O_RDONLY, 0666);
+ } while (fd == -1 && errno == EINTR);
+
if (fd < 0) {
s = strerror(errno);
write(2, "cat: cannot open ", 17);