On 2/10/24 08:32, Thomas Schmitt wrote:
Hi,

i wrote:
   shred: -: invalid file type

to...@tuxteam.de wrote:
Hmm. This looks like a genuine bug: the man page mentions it.

Even the help text in
   https://sources.debian.org/src/coreutils/9.4-3/src/shred.c/
says
   If FILE is -, shred standard output.

The name "-" is recognized in line 1257 and leads to a call of wipefd()
in line 958. The error messages there look different from above.
So i hop from line 973 to do_wipefd() and find the message in line 845.
fd is supposed to be 1 (= stdout). fstat(2) was successful but now this
condition snaps:

   if ((S_ISCHR (st.st_mode) && isatty (fd))
       || S_ISFIFO (st.st_mode)
       || S_ISSOCK (st.st_mode))

The problem seems to be in the S_ISFIFO part.
In a little test program fstat() reports about fd==1:
   st.st_mode= 010600 , S_ISFIFO(st.st_mode)= 1
(st_mode shown in octal as in man 2 fstat.)

It looks like the test expects a pipe(2) file descriptor to be
classified as S_ISCHR and !isatty().
Without redirection through a pipe, fd 1 has st.st_mode 20620, S_ISCHR,
and isatty()==1. The isatty() result is indeed a good reason, not to
flood stdout by a zillion random bytes.


Does anybody have an old GNU/Linux system where a file descriptor from
pipe(2) is classified as character device (S_IFCHR, S_ISCHR) ?


What about dash?



Reply via email to