Hi,
so, it’s actually not a stderr that gets closed, but stdout or stdin here (or
all of them).
The thing that has changed between the versions is the number of file
descriptors open during the `dig` operation (there’s less descriptors
open by default and then the opened socket gets fd == 1.
epoll_create1(EPOLL_CLOEXEC) = 1
pipe2([3, 4], O_CLOEXEC) = 0
And then libuv complains about operating on fd < 2.
Writing a lightweight wrapper around dig:
#!/bin/sh
/usr/bin/dig $@ >/dev/null </dev/null
would fix the xfce-plugin-genmon that closes the stdout (or stdin).
Also dig can be called with +noall option to silence all output, so closing
stdin
is also wrong here.
Given this test program:
#include <stdio.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
int
main(void) {
int fd = open("/tmp/test.txt", O_WRONLY | O_CREAT, S_IRWXU | S_IRGRP |
S_IROTH);
assert(fd >= 0);
write(STDOUT_FILENO, "stdout\n", 7);
write(STDERR_FILENO, "stderr\n", 7);
write(fd, "test\n", 5);
close(fd);
}
You will get stuff written to wrong file if you close the STDOUT_FILENO and
STDERR_FILENO:
$ rm *txt && ./a.out >stdout.txt 2>stderr.txt ; echo '== stdout ==' ; cat
stdout.txt ; echo '== stderr ==' ; cat stderr.txt ; echo '== test.txt ==' &&
cat test.txt
== stdout ==
stdout
== stderr ==
stderr
== test.txt ==
test
$ rm *txt && ./a.out >&- 2>stderr.txt ; echo '== stdout ==' ; cat stdout.txt ;
echo '== stderr ==' ; cat stderr.txt ; echo '== test.txt ==' && cat test.txt
== stdout ==
cat: stdout.txt: No such file or directory
== stderr ==
stderr
== test.txt ==
stdout
test
$ rm *txt && ./a.out >stdout.txt 2>&- ; echo '== stdout ==' ; cat stdout.txt ;
echo '== stderr ==' ; cat stderr.txt ; echo '== test.txt ==' && cat test.txt
== stdout ==
stdout
== stderr ==
cat: stderr.txt: No such file or directory
== test.txt ==
stderr
test
Also see https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html
I am inclined to reassign this to xfce-plugin-genmon as it breaks POSIX.
Ondrej
--
Ondřej Surý (He/Him)
[email protected]
> On 30. 11. 2021, at 0:53, Cesar Enrique Garcia <[email protected]> wrote:
>
> Hi,
>
> thanks for looking into this!
>
> It might be that the source of the problem is in xfce-plugin-genmon, but I
> traced down when this started to fail: it was after an upgrade from
> bind9-libs 1:9.16.15-1 to 1:9.16.22-1~deb11u1. So something in that upgrade
> changed the behavior in dig.
>