ce426f
commit adbb8027be47b3295367019b2f45863ea3d6c727
ce426f
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
ce426f
Date:   Thu Mar 7 12:15:08 2013 +0530
ce426f
ce426f
    Remove PIPE_BUF Linux-specific code
ce426f
    
ce426f
    Fixes BZ #12723
ce426f
    
ce426f
    The variable pipe buffer size does nothing to the value of PIPE_BUF,
ce426f
    since the number of bytes that are atomically written is still
ce426f
    PIPE_BUF on Linux.
ce426f
ce426f
diff --git glibc-2.17-c758a686/posix/Makefile glibc-2.17-c758a686/posix/Makefile
ce426f
index 2cacd21..658c47e 100644
ce426f
--- glibc-2.17-c758a686/posix/Makefile
ce426f
+++ glibc-2.17-c758a686/posix/Makefile
ce426f
@@ -86,7 +86,8 @@ tests		:= tstgetopt testfnm runtests runptests	     \
ce426f
 		   tst-rfc3484-3 \
ce426f
 		   tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset \
ce426f
 		   bug-getopt1 bug-getopt2 bug-getopt3 bug-getopt4 \
ce426f
-		   bug-getopt5 tst-getopt_long1 bug-regex34
ce426f
+		   bug-getopt5 tst-getopt_long1 bug-regex34 \
ce426f
+		   tst-pathconf
ce426f
 xtests		:= bug-ga2
ce426f
 ifeq (yes,$(build-shared))
ce426f
 test-srcs	:= globtest
ce426f
diff --git glibc-2.17-c758a686/posix/tst-pathconf.c glibc-2.17-c758a686/posix/tst-pathconf.c
ce426f
new file mode 100644
ce426f
index 0000000..7627a24
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/posix/tst-pathconf.c
ce426f
@@ -0,0 +1,176 @@
ce426f
+/* Test that values of pathconf and fpathconf are consistent for a file.
ce426f
+   Copyright (C) 2013 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include <fcntl.h>
ce426f
+#include <stdio.h>
ce426f
+#include <stdlib.h>
ce426f
+#include <string.h>
ce426f
+#include <unistd.h>
ce426f
+
ce426f
+
ce426f
+static void prepare (void);
ce426f
+#define PREPARE(argc, argv) prepare ()
ce426f
+
ce426f
+static int do_test (void);
ce426f
+#define TEST_FUNCTION do_test ()
ce426f
+
ce426f
+#include "../test-skeleton.c"
ce426f
+
ce426f
+static int dir_fd;
ce426f
+static char *dirbuf;
ce426f
+
ce426f
+static void
ce426f
+prepare (void)
ce426f
+{
ce426f
+  size_t test_dir_len = strlen (test_dir);
ce426f
+  static const char dir_name[] = "/tst-pathconf.XXXXXX";
ce426f
+
ce426f
+  size_t dirbuflen = test_dir_len + sizeof (dir_name);
ce426f
+  dirbuf = malloc (dirbuflen);
ce426f
+  if (dirbuf == NULL)
ce426f
+    {
ce426f
+      puts ("Out of memory");
ce426f
+      exit (1);
ce426f
+    }
ce426f
+
ce426f
+  snprintf (dirbuf, dirbuflen, "%s%s", test_dir, dir_name);
ce426f
+  if (mkdtemp (dirbuf) == NULL)
ce426f
+    {
ce426f
+      printf ("Cannot create temporary directory: %s\n", strerror (errno));
ce426f
+      exit (1);
ce426f
+    }
ce426f
+
ce426f
+  add_temp_file (dirbuf);
ce426f
+
ce426f
+  dir_fd = open (dirbuf, O_RDONLY);
ce426f
+  if (dir_fd == -1)
ce426f
+    {
ce426f
+      printf ("Cannot open directory: %s\n", strerror (errno));
ce426f
+      exit (1);
ce426f
+    }
ce426f
+}
ce426f
+
ce426f
+
ce426f
+static int
ce426f
+do_test (void)
ce426f
+{
ce426f
+  int ret = 0;
ce426f
+  static const char *fifo_name = "some-fifo";
ce426f
+
ce426f
+  size_t filenamelen = strlen (dirbuf) + strlen (fifo_name) + 2;
ce426f
+  char *filename = malloc (filenamelen);
ce426f
+
ce426f
+  snprintf (filename, filenamelen, "%s/%s", dirbuf, fifo_name);
ce426f
+
ce426f
+  /* Create a fifo in the directory.  */
ce426f
+  int e = mkfifo (filename, 0777);
ce426f
+  if (e == -1)
ce426f
+    {
ce426f
+      printf ("fifo creation failed (%s)\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+      goto out_nofifo;
ce426f
+    }
ce426f
+
ce426f
+  long dir_pathconf = pathconf (dirbuf, _PC_PIPE_BUF);
ce426f
+
ce426f
+  if (dir_pathconf < 0)
ce426f
+    {
ce426f
+      printf ("pathconf on directory failed: %s\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+      goto out_nofifo;
ce426f
+    }
ce426f
+
ce426f
+  long fifo_pathconf = pathconf (filename, _PC_PIPE_BUF);
ce426f
+
ce426f
+  if (fifo_pathconf < 0)
ce426f
+    {
ce426f
+      printf ("pathconf on file failed: %s\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+      goto out_nofifo;
ce426f
+    }
ce426f
+
ce426f
+  int fifo = open (filename, O_RDONLY | O_NONBLOCK);
ce426f
+
ce426f
+  if (fifo < 0)
ce426f
+    {
ce426f
+      printf ("fifo open failed (%s)\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+      goto out_nofifo;
ce426f
+    }
ce426f
+
ce426f
+  long dir_fpathconf = fpathconf (dir_fd, _PC_PIPE_BUF);
ce426f
+
ce426f
+  if (dir_fpathconf < 0)
ce426f
+    {
ce426f
+      printf ("fpathconf on directory failed: %s\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+      goto out;
ce426f
+    }
ce426f
+
ce426f
+  long fifo_fpathconf = fpathconf (fifo, _PC_PIPE_BUF);
ce426f
+
ce426f
+  if (fifo_fpathconf < 0)
ce426f
+    {
ce426f
+      printf ("fpathconf on file failed: %s\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+      goto out;
ce426f
+    }
ce426f
+
ce426f
+  if (fifo_pathconf != fifo_fpathconf)
ce426f
+    {
ce426f
+      printf ("fifo pathconf (%ld) != fifo fpathconf (%ld)\n", fifo_pathconf,
ce426f
+	      fifo_fpathconf);
ce426f
+      ret = 1;
ce426f
+      goto out;
ce426f
+    }
ce426f
+
ce426f
+  if (dir_pathconf != fifo_pathconf)
ce426f
+    {
ce426f
+      printf ("directory pathconf (%ld) != fifo pathconf (%ld)\n",
ce426f
+	      dir_pathconf, fifo_pathconf);
ce426f
+      ret = 1;
ce426f
+      goto out;
ce426f
+    }
ce426f
+
ce426f
+  if (dir_fpathconf != fifo_fpathconf)
ce426f
+    {
ce426f
+      printf ("directory fpathconf (%ld) != fifo fpathconf (%ld)\n",
ce426f
+	      dir_fpathconf, fifo_fpathconf);
ce426f
+      ret = 1;
ce426f
+      goto out;
ce426f
+    }
ce426f
+
ce426f
+out:
ce426f
+  close (fifo);
ce426f
+out_nofifo:
ce426f
+  close (dir_fd);
ce426f
+
ce426f
+  if (unlink (filename) != 0)
ce426f
+    {
ce426f
+      printf ("Could not remove fifo (%s)\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+    }
ce426f
+
ce426f
+  if (rmdir (dirbuf) != 0)
ce426f
+    {
ce426f
+      printf ("Could not remove directory (%s)\n", strerror (errno));
ce426f
+      ret = 1;
ce426f
+    }
ce426f
+
ce426f
+  return ret;
ce426f
+}
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/fpathconf.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/fpathconf.c
ce426f
index c971644..e8c4dc9 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/fpathconf.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/fpathconf.c
ce426f
@@ -33,7 +33,6 @@ __fpathconf (fd, name)
ce426f
      int name;
ce426f
 {
ce426f
   struct statfs fsbuf;
ce426f
-  int r;
ce426f
 
ce426f
   switch (name)
ce426f
     {
ce426f
@@ -49,12 +48,6 @@ __fpathconf (fd, name)
ce426f
     case _PC_CHOWN_RESTRICTED:
ce426f
       return __statfs_chown_restricted (__fstatfs (fd, &fsbuf), &fsbuf);
ce426f
 
ce426f
-    case _PC_PIPE_BUF:
ce426f
-      r = __fcntl (fd, F_GETPIPE_SZ);
ce426f
-      if (r > 0)
ce426f
-	return r;
ce426f
-      /* FALLTHROUGH */
ce426f
-
ce426f
     default:
ce426f
       return posix_fpathconf (fd, name);
ce426f
     }
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c
ce426f
index edc691e..de91a45 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c
ce426f
@@ -39,8 +39,6 @@ long int
ce426f
 __pathconf (const char *file, int name)
ce426f
 {
ce426f
   struct statfs fsbuf;
ce426f
-  int fd;
ce426f
-  int flags;
ce426f
 
ce426f
   switch (name)
ce426f
     {
ce426f
@@ -56,21 +54,6 @@ __pathconf (const char *file, int name)
ce426f
     case _PC_CHOWN_RESTRICTED:
ce426f
       return __statfs_chown_restricted (__statfs (file, &fsbuf), &fsbuf);
ce426f
 
ce426f
-    case _PC_PIPE_BUF:
ce426f
-      flags = O_RDONLY|O_NONBLOCK|O_NOCTTY;
ce426f
-#ifdef O_CLOEXEC
ce426f
-      flags |= O_CLOEXEC;
ce426f
-#endif
ce426f
-      fd = open_not_cancel_2 (file, flags);
ce426f
-      if (fd >= 0)
ce426f
-	{
ce426f
-	  long int r = __fcntl (fd, F_GETPIPE_SZ);
ce426f
-	  close_not_cancel_no_status (fd);
ce426f
-	  if (r > 0)
ce426f
-	    return r;
ce426f
-	}
ce426f
-      /* FALLTHROUGH */
ce426f
-
ce426f
     default:
ce426f
       return posix_pathconf (file, name);
ce426f
     }