Date: Sun, 23 Apr 2006 10:20:15 GMT From: Bjoern Voigt <bjoern@cs.tu-berlin.de> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/96191: "cat" can display directory contents Message-ID: <200604231020.k3NAKF1Q042100@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/96191; it has been noted by GNATS.
From: Bjoern Voigt <bjoern@cs.tu-berlin.de>
To: bug-followup@FreeBSD.org
Cc:
Subject: Re: misc/96191: "cat" can display directory contents
Date: Sun, 23 Apr 2006 12:12:46 +0200
I know, that everything is a file on UNIX. But also a system should
prevent a user from falling into a trap. Shell script authors can fall
into a trap if they accidentally work on directories with "cat" and
"cat" returns with exit code 0. I think the Linux' implementation is
better here, but this is my personal opinion.
I looked at the problem more detailed now. I found, that the different
behavior between "cat /etc" on FreeBSD and Linux does not come from the
cat-tools itself. The difference comes from different implementations of
the read(2) system call. Linux's read(2) call refuses to read from
directories.
I tested FreeBSD's "cat" on Linux:
* Linux has no support for 'udom' and does not know the __FBSDID
macro (both is not important here)
* compilation on Linux: gcc -g -o cat2 -DNO_UDOM_SUPPORT
-D'__FBSDID(a)=/**/' cat.c
* The result:
$ ./cat2 /etc
cat2: /etc: Is a directory
As a result also other UNIX tools behave different on Linux and on
FreeBSD. For instance the same version of "bash" behaves different on
Linux and on FreeBSD:
FreeBSD:
$ echo $0; head < /etc
/usr/local/bin/bash
(garbage)
Linux:
echo $0; head < /etc
-bash
head: error reading `standard input': Is a directory
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604231020.k3NAKF1Q042100>
