bug-diffutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-diffutils] Funny behaviour of diff 2.8.1


From: Philipp Thomas
Subject: [bug-diffutils] Funny behaviour of diff 2.8.1
Date: Wed, 11 Aug 2010 14:34:13 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

I got the following question from our ksh maintainer
(https://bugzilla.novell.com/show_bug.cgi?id=627524) which I'd like to pass
on because I have little knowledge of diffs inner workings. The original bug
report was that ksh shows an anomaly when using the "-" within a pipe
context, e. g.

$> echo "test" | diff - /dev/null
diff: -: Bad file descriptor

Which works in bash.

Our maintainer replied:

ksh uses socketpairs as a fast replacement for pipes which is a major
feature of the ksh ...  I do not understand why /usr/bin/diff
executes dup(), then opens /proc/self/fd/3, and then tries to open this:

  /bin/echo "test" | strace /usr/bin/diff - /dev/null
  [...]
  ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfdf8b18) = -1 EINVAL (Invalid
argument)
  dup(0)
  lstat64("/proc/self/fd/3", {st_mode=S_IFLNK|0700, st_size=64, ...}) = 0
  close(0)                                = 0
  open("/proc/self/fd/3", O_RDONLY|O_LARGEFILE) = -1 ENXIO (No such device
  or
address)
  close(3)                                = 0
  fstat64(0, 0xbfdf8bf0)                  = -1 EBADF (Bad file descriptor)
  stat64("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) =
  0
  write(2, "/usr/bin/diff: ", 15/usr/bin/diff: )         = 15
  write(2, "-", 1-)                        = 1
  write(2, ": Bad file descriptor", 21: Bad file descriptor)   = 21
  write(2, "\n", 1
)                       = 1
  close(1)                                = 0
  exit_group(2)                           = ?

the correct behaviour would be to read from file descriptor 0 as /bin/cat
does:

  /bin/echo "test" | strace /bin/cat -
  [...]
  read(0, "test\n", 4096)                 = 5
  write(1, "test\n", 5test
)                   = 5
  read(0, "", 4096)                       = 0
  close(0)                                = 0
  close(1)                                = 0
  close(2)                                = 0
  exit_group(0)                           = ?


Does somebody here know a way to avoid the open on the socketpair as this
always leads to an error ENXIO which finally destroys the socketpair.

Philipp



reply via email to

[Prev in Thread] Current Thread [Next in Thread]