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