Bug 12723 - pathconf for a FIFO returns a different value than fpathconf
Summary: pathconf for a FIFO returns a different value than fpathconf
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Siddhesh Poyarekar
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-02 13:32 UTC by Stew Benedict
Modified: 2014-06-27 13:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stew Benedict 2011-05-02 13:32:21 UTC
If one calls pathconf of a FIFO, you get a different value than you do from fpathconf:


 int fd151, fd152, fd161, fd162;
  long p151, p152, p161, p162;

  const char f15[15] = "fpathconf-t.15";
  const char f16[15] = "fpathconf-t.16";
  const char dot[2] = ".";

  fd151 = open(f15, O_RDONLY|O_NONBLOCK);

  p151 = fpathconf(fd151, _PC_PIPE_BUF);
  p152 = pathconf(f15, _PC_PIPE_BUF);

  if(p151 != p152) {
    printf("test15 FAIL - fpathconf for '%s' (%ld)  does not equal pathconf for 
'%s' (%ld) \n", f15, p151, f15, p152);
  } else {
    printf("test15 PASS - fpathconf for '%s' (%ld)  equals pathconf for '%s' (%ld) \n", f15, p151, f15, p152);
  }


test15 FAIL - fpathconf for 'fpathconf-t.15' (65536)  does not equal pathconf for 'fpathconf-t.15' (4096) 

This would seem to have started about the time of this change:

commit 8a492a675e566dc1e666df0a86cbf541442cb179
Author: Ulrich Drepper <drepper@redhat.com>
Date:   Tue Jul 6 07:48:23 2010 -0700

    Implement _PC_PIPE_BUF.
    
    Now that the kernel has appropriate support we can implement this
    fpathconf command correctly.

Also, according to SUSv3, the result from fpathconf for a directory should be the same as for a FIFO in that directory. This also seems to have changed:

"6. If path refers to a FIFO, or fildes refers to a pipe or FIFO, the value
returned shall apply to the referenced object. If path or fildes refers to a
directory, the value returned shall apply to any FIFO that exists or can be
created within the directory. If path or fildes refers to any other type of
file, it is unspecified whether an implementation supports an association of
the variable name with the specified file."

  fd161 = open(dot, O_RDONLY);
  fd162 = open(f16, O_RDONLY|O_NONBLOCK);

  p161 = fpathconf(fd161, _PC_PIPE_BUF);
  p162 = fpathconf(fd162, _PC_PIPE_BUF);

  if(p161 != p162) {
    printf("test16 FAIL - fpathconf for '%s' (%ld)  does not equal fpathconf for '%s' (%ld) \n", dot, p161, f16, p162);
  } else {
    printf("test16 PASS - fpathconf for '%s' (%ld)  equals fpathconf for '%s' (%ld) \n", dot, p161, f16, p162);
  }


test16 FAIL - fpathconf for '.' (4096)  does not equal fpathconf for 'fpathconf-t.16' (65536)
Comment 1 Ulrich Drepper 2011-05-03 01:01:18 UTC
Fixed in git.
Comment 2 Stew Benedict 2012-04-25 18:07:15 UTC
For some reason this fix has never manifested itself out to the distros. glibc-2.15 still has both of these tests failing.
Comment 3 Siddhesh Poyarekar 2013-03-07 06:46:43 UTC
Fixed in master.  I've reverted {f}pathconf to returning PIPE_BUF since F_GETPIPE_SZ is not the size of an atomic write; that remains at page size or PIPE_BUF (which is currently the same at 4K).