diffutils-devel
[Top][All Lists]
Advanced

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

Re: [Diffutils-devel] diffutils-3.6.17-d5ba on HP-UX


From: Bruno Haible
Subject: Re: [Diffutils-devel] diffutils-3.6.17-d5ba on HP-UX
Date: Mon, 31 Dec 2018 07:53:51 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; )

Hi Jim,

> > On HP-UX:
> >
> > $ tusc ../src/diff -N - a <&-
> > execve("../src/diff", 0x87fffffffffffb08, 0x87fffffffffffb30) = 0 [64-bit]
> > ...
> > ioctl(0, TCGETA, 0x87fffffffffff3e0) ..................... ERR#25 ENOTTY
> > fstat(0, 0x87fffffffffff420) ............................. = 0
> ...
> >
> > On Linux:
> >
> > $ strace ../src/diff -N - a <&-
> > execve("../src/diff", ["../src/diff", "-N", "-", "a"], [/* 78 vars */]) = 0
> > ...
> > ioctl(0, TCGETS, 0x7ffd75318810)        = -1 EBADF (Bad file descriptor)
> > fstat(0, 0x7ffd75318940)                = -1 EBADF (Bad file descriptor)
> ...
> >
> > The crucial difference is the open("a", O_RDONLY...) call, which is meant
> 
> The crucial difference seems earlier than that. HP-UX's fstat
> erroneously returns 0 for the invalid (closed) stdin file descriptor,
> while Linux's returns EBADF.

Indeed, when I replace said line in diff.c with

  if ((errno = EBADF, 1) || fcntl (STDIN_FILENO, F_GETFD, 0) < 0 || fstat 
(STDIN_FILENO, &cmp.file[f].stat) != 0)

then the HP-UX 'diff' behaves like the Linux one in this test case:

HP-UX:
$ ../src/diff -N - a <&-     
file_block_read fd=3 size=65536 0
block_read: read(fd=3) -> 2
block_read: read(fd=3) -> 0
file_block_read block_read returned 2
file_block_read fd=3 size=1 1
0a1
> a

Linux:
$ ../src/diff -N - a <&-       
file_block_read fd=0 size=4096 0
block_read: read(fd=0) -> 2
block_read: read(fd=0) -> 0
file_block_read block_read returned 2
file_block_read fd=0 size=1 1
0a1
> a

I guess that's the expected result?

Without the '(errno = EBADF, 1) || ', i.e. with just the fcntl call added,
it does not help:

$ tusc ../src/diff -N - a <&-
execve("../src/diff", 0x87fffffffffffb20, 0x87fffffffffffb48) = 0 [64-bit]
...
ioctl(0, TCGETA, 0x87fffffffffff400) ..................... ERR#25 ENOTTY
fcntl(0, F_GETFD, 4503599627469313) ...................... = 0
fstat(0, 0x87fffffffffff440) ............................. = 0
clock_gettime(CLOCK_REALTIME, 0x87fffffffffff410) ........ = 0
stat("a", 0x87fffffffffff580) ............................ = 0
open("a", O_RDONLY|0x800, 0) ............................. = 3
...
read(0, 0x600000000004a780, 65536) ....................... ERR#9 EBADF
...
diff: write(2, "d i f f :   ", 6) .............................. = 6
-write(2, "- ", 1) ........................................ = 1
: Bad fiwrite(2, ":   B a d   f i ", 8) .......................... = 8
le numbewrite(2, "l e   n u m b e ", 8) .......................... = 8
rwrite(2, "r ", 1) ........................................ = 1

write(2, "\n", 1) ........................................ = 1
exit(2) .................................................. WIFEXITED(2)

> One way to work around that HP-UX flaw is to make gnulib's fstat
> replacement return EBADF when the return value would otherwise be 0,

It needs more experiments to find a solution...

Bruno




reply via email to

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