This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch master updated. glibc-2.26.9000-749-g1ffe1cc


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  1ffe1ccb6ec5771765f1f6f0c439ed07bf345d67 (commit)
      from  456b40a97f7e867803b2f47f5fcd3f1fa4bc1f6e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=1ffe1ccb6ec5771765f1f6f0c439ed07bf345d67

commit 1ffe1ccb6ec5771765f1f6f0c439ed07bf345d67
Author: Florian Weimer <fweimer@redhat.com>
Date:   Sun Nov 12 09:53:06 2017 +0100

    support: Add xstrndup, xunlink, xreadlink, support_create_temp_directory

diff --git a/ChangeLog b/ChangeLog
index 61f97ed..32b57bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-11-12  Florian Weimer  <fweimer@redhat.com>
+
+	* support/support.h (xstrndup): Declare.
+	* support/xunistd.h (xunlink, xreadlink): Declare.
+	* support/temp_file.h (support_create_temp_directory): Declare.
+	* support/temp_file.c (support_create_temp_directory): New function.
+	* support/support_chroot.c (support_chroot_create): Use it.
+	* support/xreadlink.c: New file.
+	* support/xstrndup.c: Likewise.
+	* support/xunlink.c: Likewise.
+	* support/tst-xreadlink.c: Likewise.
+
 2017-11-11  John David Anglin  <danglin@gcc.gnu.org>
 
 	* sysdeps/hppa/fpu/libm-test-ulps: Update clog10_downward ulps.
diff --git a/support/Makefile b/support/Makefile
index 027a663..dafb173 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -109,19 +109,22 @@ libsupport-routines = \
   xpthread_once \
   xpthread_rwlock_init \
   xpthread_rwlock_rdlock \
-  xpthread_rwlock_wrlock \
   xpthread_rwlock_unlock \
+  xpthread_rwlock_wrlock \
   xpthread_rwlockattr_init \
   xpthread_rwlockattr_setkind_np \
   xpthread_sigmask \
   xpthread_spin_lock \
   xpthread_spin_unlock \
+  xreadlink \
   xrealloc \
   xrecvfrom \
   xsendto \
   xsetsockopt \
   xsocket \
   xstrdup \
+  xstrndup \
+  xunlink \
   xwaitpid \
   xwrite \
 
@@ -138,6 +141,7 @@ tests = \
   tst-support_capture_subprocess \
   tst-support_format_dns_packet \
   tst-support_record_failure \
+  tst-xreadlink \
 
 ifeq ($(run-built-tests),yes)
 tests-special = \
diff --git a/support/support.h b/support/support.h
index 4b5f04c..bbba803 100644
--- a/support/support.h
+++ b/support/support.h
@@ -68,6 +68,7 @@ void *xrealloc (void *p, size_t n);
 char *xasprintf (const char *format, ...)
   __attribute__ ((format (printf, 1, 2), malloc));
 char *xstrdup (const char *);
+char *xstrndup (const char *, size_t);
 
 __END_DECLS
 
diff --git a/support/support_chroot.c b/support/support_chroot.c
index f3ef551..f6fad18 100644
--- a/support/support_chroot.c
+++ b/support/support_chroot.c
@@ -46,10 +46,11 @@ support_chroot_create (struct support_chroot_configuration conf)
 {
   struct support_chroot *chroot = xmalloc (sizeof (*chroot));
 
-  chroot->path_chroot = xasprintf ("%s/tst-resolv-res_init-XXXXXX", test_dir);
-  if (mkdtemp (chroot->path_chroot) == NULL)
-    FAIL_EXIT1 ("mkdtemp (\"%s\"): %m", chroot->path_chroot);
-  add_temp_file (chroot->path_chroot);
+  {
+    char *template = xasprintf ("%s/tst-resolv-res_init-XXXXXX", test_dir);
+    chroot->path_chroot = support_create_temp_directory (template);
+    free (template);
+  }
 
   /* Create the /etc directory in the chroot environment.  */
   char *path_etc = xasprintf ("%s/etc", chroot->path_chroot);
diff --git a/support/temp_file.c b/support/temp_file.c
index fdb2477..cbd54e2 100644
--- a/support/temp_file.c
+++ b/support/temp_file.c
@@ -86,6 +86,19 @@ create_temp_file (const char *base, char **filename)
   return fd;
 }
 
+char *
+support_create_temp_directory (const char *base)
+{
+  char *base_copy = xstrdup (base);
+  if (mkdtemp (base_copy) == NULL)
+    {
+      printf ("error: mkdtemp (\"%s\"): %m", base);
+      exit (1);
+    }
+  add_temp_file (base_copy);
+  return base_copy;
+}
+
 /* Helper functions called by the test skeleton follow.  */
 
 void
diff --git a/support/temp_file.h b/support/temp_file.h
index 6fed8df..dfefe58 100644
--- a/support/temp_file.h
+++ b/support/temp_file.h
@@ -32,6 +32,11 @@ void add_temp_file (const char *name);
    *FILENAME.  */
 int create_temp_file (const char *base, char **filename);
 
+/* Create a temporary directory and schedule it for deletion.  BASE
+   must end with the six characters "XXXXXX".  Return the name of the
+   temporary directory.  The caller should free the string.  */
+char *support_create_temp_directory (const char *base);
+
 __END_DECLS
 
 #endif /* SUPPORT_TEMP_FILE_H */
diff --git a/support/tst-xreadlink.c b/support/tst-xreadlink.c
new file mode 100644
index 0000000..cb2c12a
--- /dev/null
+++ b/support/tst-xreadlink.c
@@ -0,0 +1,72 @@
+/* Test the xreadlink function.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+
+static int
+do_test (void)
+{
+  char *dir = support_create_temp_directory ("/tmp/tst-xreadlink-XXXXXX");
+  char *symlink_name = xasprintf ("%s/symlink", dir);
+  add_temp_file (symlink_name);
+
+  /* The limit 10000 is arbitrary and simply there to prevent an
+     attempt to exhaust all available disk space.  */
+  for (int size = 1; size < 10000; ++size)
+    {
+      char *contents = xmalloc (size + 1);
+      for (int i = 0; i < size; ++i)
+        contents[i] = 'a' + (rand () % 26);
+      contents[size] = '\0';
+      if (symlink (contents, symlink_name) != 0)
+        {
+          if (errno == ENAMETOOLONG)
+            {
+              printf ("info: ENAMETOOLONG failure at %d bytes\n", size);
+              free (contents);
+              break;
+            }
+          FAIL_EXIT1 ("symlink (%d bytes): %m", size);
+        }
+
+      char *readlink_result = xreadlink (symlink_name);
+      TEST_VERIFY (strcmp (readlink_result, contents) == 0);
+      free (readlink_result);
+      xunlink (symlink_name);
+      free (contents);
+    }
+
+  /* Create an empty file to suppress the temporary file deletion
+     warning.  */
+  xclose (xopen (symlink_name, O_WRONLY | O_CREAT, 0));
+
+  free (symlink_name);
+  free (dir);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/support/temp_file.h b/support/xreadlink.c
similarity index 50%
copy from support/temp_file.h
copy to support/xreadlink.c
index 6fed8df..aec58a2 100644
--- a/support/temp_file.h
+++ b/support/xreadlink.c
@@ -1,5 +1,5 @@
-/* Declarations for temporary file handling.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+/* Error-checking, allocating wrapper for readlink.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,22 +16,29 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef SUPPORT_TEMP_FILE_H
-#define SUPPORT_TEMP_FILE_H
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/* Schedule a temporary file for deletion on exit.  */
-void add_temp_file (const char *name);
-
-/* Create a temporary file.  Return the opened file descriptor on
-   success, or -1 on failure.  Write the file name to *FILENAME if
-   FILENAME is not NULL.  In this case, the caller is expected to free
-   *FILENAME.  */
-int create_temp_file (const char *base, char **filename);
-
-__END_DECLS
-
-#endif /* SUPPORT_TEMP_FILE_H */
+#include <scratch_buffer.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <xunistd.h>
+
+char *
+xreadlink (const char *path)
+{
+  struct scratch_buffer buf;
+  scratch_buffer_init (&buf);
+
+  while (true)
+    {
+      ssize_t count = readlink (path, buf.data, buf.length);
+      if (count < 0)
+        FAIL_EXIT1 ("readlink (\"%s\"): %m", path);
+      if (count < buf.length)
+        {
+          char *result = xstrndup (buf.data, count);
+          scratch_buffer_free (&buf);
+          return result;
+        }
+      if (!scratch_buffer_grow (&buf))
+        FAIL_EXIT1 ("scratch_buffer_grow in xreadlink");
+    }
+}
diff --git a/support/temp_file.h b/support/xstrndup.c
similarity index 58%
copy from support/temp_file.h
copy to support/xstrndup.c
index 6fed8df..d59a283 100644
--- a/support/temp_file.h
+++ b/support/xstrndup.c
@@ -1,4 +1,4 @@
-/* Declarations for temporary file handling.
+/* strndup with error checking.
    Copyright (C) 2016-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,22 +16,15 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef SUPPORT_TEMP_FILE_H
-#define SUPPORT_TEMP_FILE_H
+#include <support/support.h>
 
-#include <sys/cdefs.h>
+#include <string.h>
 
-__BEGIN_DECLS
-
-/* Schedule a temporary file for deletion on exit.  */
-void add_temp_file (const char *name);
-
-/* Create a temporary file.  Return the opened file descriptor on
-   success, or -1 on failure.  Write the file name to *FILENAME if
-   FILENAME is not NULL.  In this case, the caller is expected to free
-   *FILENAME.  */
-int create_temp_file (const char *base, char **filename);
-
-__END_DECLS
-
-#endif /* SUPPORT_TEMP_FILE_H */
+char *
+xstrndup (const char *s, size_t length)
+{
+  char *p = strndup (s, length);
+  if (p == NULL)
+    oom_error ("strndup", length);
+  return p;
+}
diff --git a/support/xunistd.h b/support/xunistd.h
index c947bfd..05c2626 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -38,6 +38,11 @@ int xopen (const char *path, int flags, mode_t);
 void xstat (const char *path, struct stat64 *);
 void xmkdir (const char *path, mode_t);
 void xchroot (const char *path);
+void xunlink (const char *path);
+
+/* Read the link at PATH.  The caller should free the returned string
+   with free.  */
+char *xreadlink (const char *path);
 
 /* Close the file descriptor.  Ignore EINTR errors, but terminate the
    process on other errors.  */
diff --git a/support/temp_file.h b/support/xunlink.c
similarity index 54%
copy from support/temp_file.h
copy to support/xunlink.c
index 6fed8df..f94ee11 100644
--- a/support/temp_file.h
+++ b/support/xunlink.c
@@ -1,5 +1,5 @@
-/* Declarations for temporary file handling.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+/* Error-checking wrapper for unlink.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,22 +16,12 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef SUPPORT_TEMP_FILE_H
-#define SUPPORT_TEMP_FILE_H
+#include <support/check.h>
+#include <support/xunistd.h>
 
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/* Schedule a temporary file for deletion on exit.  */
-void add_temp_file (const char *name);
-
-/* Create a temporary file.  Return the opened file descriptor on
-   success, or -1 on failure.  Write the file name to *FILENAME if
-   FILENAME is not NULL.  In this case, the caller is expected to free
-   *FILENAME.  */
-int create_temp_file (const char *base, char **filename);
-
-__END_DECLS
-
-#endif /* SUPPORT_TEMP_FILE_H */
+void
+xunlink (const char *path)
+{
+  if (unlink (path) != 0)
+    FAIL_EXIT1 ("unlink (\"%s\"): %m", path);
+}

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                |   12 +++++++
 support/Makefile         |    6 +++-
 support/support.h        |    1 +
 support/support_chroot.c |    9 +++--
 support/temp_file.c      |   13 ++++++++
 support/temp_file.h      |    5 +++
 support/tst-xreadlink.c  |   72 ++++++++++++++++++++++++++++++++++++++++++++++
 support/xreadlink.c      |   44 ++++++++++++++++++++++++++++
 support/xstrndup.c       |   30 +++++++++++++++++++
 support/xunistd.h        |    5 +++
 support/xunlink.c        |   27 +++++++++++++++++
 11 files changed, 219 insertions(+), 5 deletions(-)
 create mode 100644 support/tst-xreadlink.c
 create mode 100644 support/xreadlink.c
 create mode 100644 support/xstrndup.c
 create mode 100644 support/xunlink.c


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]