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.24-575-gf47ae51


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  f47ae5186624e5bb3a2d2b25be742b90a1eee3cd (commit)
       via  039c5a05cc905e3d48392e7ea9f85e339b7c068b (commit)
       via  5707a64d9462001f9c7c2e02d3f52cf8b0181658 (commit)
      from  a851999f61ad7ceabc2a945a3c31c60e8c914a4b (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=f47ae5186624e5bb3a2d2b25be742b90a1eee3cd

commit f47ae5186624e5bb3a2d2b25be742b90a1eee3cd
Author: Florian Weimer <fweimer@redhat.com>
Date:   Sat Dec 31 11:01:40 2016 +0100

    support: Implement --verbose option for test programs
    
    Some tests can produce rather verbose tracing information,
    and the --verbose option provides a standardized way to enable
    such logging output.

diff --git a/ChangeLog b/ChangeLog
index 7ab09eb..2938d87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2016-12-31  Florian Weimer  <fweimer@redhat.com>
 
+	* support/test-driver.h (TEST_DEFAULT_OPTIONS): Add --verbose.
+	(test_verbose): Declare.
+	* support/test-driver.c (main): Use TEST_DEFAULT_OPTIONS.
+	* support/support_test_main.c (default_options): Likewise.
+	(usage, support_test_main): Handle 'v'.
+	(test_verbose): Define.
+	* support/tst-support_record_failure.c (do_test): Use
+	test_verbose.
+	* support/tst-support_record_failure-2.sh (different_status): Add
+	--verbose test.
+
+2016-12-31  Florian Weimer  <fweimer@redhat.com>
+
 	* support/check.h (FAIL_RET, FAIL_EXIT, FAIL_EXIT1): Document that
 	test failures are recorded.
 	* support/check.c (support_print_failure_impl): Call
diff --git a/support/support_test_main.c b/support/support_test_main.c
index 8d31e2f..1c90986 100644
--- a/support/support_test_main.c
+++ b/support/support_test_main.c
@@ -37,8 +37,7 @@
 
 static const struct option default_options[] =
 {
-  { "direct", no_argument, NULL, OPT_DIRECT },
-  { "test-dir", required_argument, NULL, OPT_TESTDIR },
+  TEST_DEFAULT_OPTIONS
   { NULL, 0, NULL, 0 }
 };
 
@@ -67,6 +66,9 @@ usage (const struct option *options)
       printf ("%*s", 25 - indent, "");
       switch (options[i].val)
         {
+        case 'v':
+          printf ("Increase the output verbosity");
+          break;
         case OPT_DIRECT:
           printf ("Run the test directly (instead of forking & monitoring)");
           break;
@@ -164,7 +166,7 @@ run_test_function (int argc, char **argv, const struct test_config *config)
 static bool test_main_called;
 
 const char *test_dir = NULL;
-
+unsigned int test_verbose = 0;
 
 /* If test failure reporting has been linked in, it may contribute
    additional test failures.  */
@@ -215,6 +217,9 @@ support_test_main (int argc, char **argv, const struct test_config *config)
       case '?':
         usage (options);
         exit (1);
+      case 'v':
+        ++test_verbose;
+        break;
       case OPT_DIRECT:
         direct = 1;
         break;
diff --git a/support/test-driver.c b/support/test-driver.c
index 3a61b7b..a847c96 100644
--- a/support/test-driver.c
+++ b/support/test-driver.c
@@ -144,9 +144,7 @@ main (int argc, char **argv)
   struct option options[] =
     {
       CMDLINE_OPTIONS
-      { "direct", no_argument, NULL, OPT_DIRECT },
-      { "test-dir", required_argument, NULL, OPT_TESTDIR },
-      { NULL, 0, NULL, 0 }
+      TEST_DEFAULT_OPTIONS
     };
   test_config.options = &options;
 #endif
diff --git a/support/test-driver.h b/support/test-driver.h
index 7787e9c..f3f5c17 100644
--- a/support/test-driver.h
+++ b/support/test-driver.h
@@ -55,12 +55,18 @@ enum
 
 /* Options provided by the test driver.  */
 #define TEST_DEFAULT_OPTIONS                            \
+  { "verbose", no_argument, NULL, 'v' },                \
   { "direct", no_argument, NULL, OPT_DIRECT },          \
   { "test-dir", required_argument, NULL, OPT_TESTDIR }, \
 
 /* The directory the test should use for temporary files.  */
 extern const char *test_dir;
 
+/* The number of --verbose arguments specified during program
+   invocation.  This variable can be used to control the verbosity of
+   tests.  */
+extern unsigned int test_verbose;
+
 int support_test_main (int argc, char **argv, const struct test_config *);
 
 __END_DECLS
diff --git a/support/tst-support_record_failure-2.sh b/support/tst-support_record_failure-2.sh
index a96a60d..6fffd8a 100644
--- a/support/tst-support_record_failure-2.sh
+++ b/support/tst-support_record_failure-2.sh
@@ -54,13 +54,16 @@ different_status () {
     run_test 1 "error: 1 test failures" $direct --status=77
     run_test 2 "error: tst-support_record_failure.c:108: not true: false
 error: 1 test failures" $direct --test-verify
+    run_test 2 "error: tst-support_record_failure.c:108: not true: false
+info: execution passed failed TEST_VERIFY
+error: 1 test failures" $direct --test-verify --verbose
 }
 
 different_status
 different_status --direct
 
-run_test 1 "error: tst-support_record_failure.c:113: not true: false
+run_test 1 "error: tst-support_record_failure.c:115: not true: false
 error: 1 test failures" --test-verify-exit
 # --direct does not print the summary error message if exit is called.
-run_test 1 "error: tst-support_record_failure.c:113: not true: false" \
+run_test 1 "error: tst-support_record_failure.c:115: not true: false" \
 	 --direct --test-verify-exit
diff --git a/support/tst-support_record_failure.c b/support/tst-support_record_failure.c
index a999f70..75dd10f 100644
--- a/support/tst-support_record_failure.c
+++ b/support/tst-support_record_failure.c
@@ -106,6 +106,8 @@ do_test (void)
   if (test_verify)
     {
       TEST_VERIFY (false);
+      if (test_verbose)
+        printf ("info: execution passed failed TEST_VERIFY\n");
       return 2; /* Expected exit status.  */
     }
   if (test_verify_exit)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=039c5a05cc905e3d48392e7ea9f85e339b7c068b

commit 039c5a05cc905e3d48392e7ea9f85e339b7c068b
Author: Florian Weimer <fweimer@redhat.com>
Date:   Sat Dec 31 12:20:49 2016 +0100

    support: Use support_record_failure consistently
    
    This causes more test programs to link in the support_record_failure
    function, which triggers an early call to mmap from an ELF
    constructor, but this should not have side effects intefering
    with the functionality actually under test (unlike, say, a call
    to malloc).

diff --git a/ChangeLog b/ChangeLog
index e7b2fa1..7ab09eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
 2016-12-31  Florian Weimer  <fweimer@redhat.com>
 
+	* support/check.h (FAIL_RET, FAIL_EXIT, FAIL_EXIT1): Document that
+	test failures are recorded.
+	* support/check.c (support_print_failure_impl): Call
+	support_record_failure.
+	(support_exit_failure_impl): Call support_record_failure if status
+	indicates failure.
+	* support/delayed_exit.c (delayed_exit_thread): Use FAIL_EXIT1.
+	* support/xasprintf.c (xasprintf): Likewise.
+	* support/xfork.c (xfork): Likewise.
+	* support/xpthread_check_return.c (xpthread_check_return):
+	Likewise.
+	* support/xsocket.c (xsocket): Likeweise.
+	* support/xwaitpid.c (xwaitpid): Likewise.
+	* support/support_record_failure.c (struct test_failures): Adjust
+	to coding style.
+	* support/support_test_verify_impl.c (support_test_verify_impl):
+	Adjust error messages.
+	* support/tst-support_record_failure-2.sh (different_status):
+	Adjust error messages.
+
+2016-12-31  Florian Weimer  <fweimer@redhat.com>
+
 	* support/namespace.h: New file.
 	* support/support_become_root.c: Likewise.
 	* support/support_enter_network_namespace.c: Likewise.
diff --git a/support/check.c b/support/check.c
index 75fdf52..04d2503 100644
--- a/support/check.c
+++ b/support/check.c
@@ -21,6 +21,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <support/test-driver.h>
 
 static void
 print_failure (const char *file, int line, const char *format, va_list ap)
@@ -34,6 +35,7 @@ int
 support_print_failure_impl (const char *file, int line,
                             const char *format, ...)
 {
+  support_record_failure ();
   va_list ap;
   va_start (ap, format);
   print_failure (file, line, format, ap);
@@ -45,6 +47,8 @@ void
 support_exit_failure_impl (int status, const char *file, int line,
                            const char *format, ...)
 {
+  if (status != EXIT_SUCCESS && status != EXIT_UNSUPPORTED)
+    support_record_failure ();
   va_list ap;
   va_start (ap, format);
   print_failure (file, line, format, ap);
diff --git a/support/check.h b/support/check.h
index 92cb5d9..129bff2 100644
--- a/support/check.h
+++ b/support/check.h
@@ -23,15 +23,19 @@
 
 __BEGIN_DECLS
 
-/* Print failure message to standard output and return 1.  */
+/* Record a test failure, print the failure message to standard output
+   and return 1.  */
 #define FAIL_RET(...) \
   return support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__)
 
-/* Print failure message and terminate the process with STATUS.  */
+/* Print the failure message and terminate the process with STATUS.
+   Record a the process as failed if STATUS is neither EXIT_SUCCESS
+   nor EXIT_UNSUPPORTED.  */
 #define FAIL_EXIT(status, ...) \
   support_exit_failure_impl (status, __FILE__, __LINE__, __VA_ARGS__)
 
-/* Print failure message and terminate with exit status 1.  */
+/* Record a test failure, print the failure message and terminate with
+   exit status 1.  */
 #define FAIL_EXIT1(...) \
   support_exit_failure_impl (1, __FILE__, __LINE__, __VA_ARGS__)
 
diff --git a/support/delayed_exit.c b/support/delayed_exit.c
index d5b2e10..1384f5c 100644
--- a/support/delayed_exit.c
+++ b/support/delayed_exit.c
@@ -22,6 +22,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <support/check.h>
 #include <time.h>
 
 static void *
@@ -31,10 +32,7 @@ delayed_exit_thread (void *seconds_as_ptr)
   struct timespec delay = { seconds, 0 };
   struct timespec remaining = { 0 };
   if (nanosleep (&delay, &remaining) != 0)
-    {
-      printf ("error: nanosleep: %m\n");
-      exit (1);
-    }
+    FAIL_EXIT1 ("nanosleep: %m");
   /* Exit the process sucessfully.  */
   exit (0);
   return NULL;
diff --git a/support/support_record_failure.c b/support/support_record_failure.c
index 24b2d6e..30de2f6 100644
--- a/support/support_record_failure.c
+++ b/support/support_record_failure.c
@@ -36,8 +36,8 @@
    propagate to the parent process.  */
 struct test_failures
 {
-  unsigned counter;
-  unsigned failed;
+  unsigned int counter;
+  unsigned int failed;
 };
 static struct test_failures *state;
 
diff --git a/support/support_test_verify_impl.c b/support/support_test_verify_impl.c
index 28b1524..3b74e57 100644
--- a/support/support_test_verify_impl.c
+++ b/support/support_test_verify_impl.c
@@ -26,7 +26,7 @@ support_test_verify_impl (int status, const char *file, int line,
                           const char *expr)
 {
   support_record_failure ();
-  printf ("FAIL %s:%d: not true: %s\n", file, line, expr);
+  printf ("error: %s:%d: not true: %s\n", file, line, expr);
   if (status >= 0)
     exit (status);
 
diff --git a/support/tst-support_record_failure-2.sh b/support/tst-support_record_failure-2.sh
index 71af382..a96a60d 100644
--- a/support/tst-support_record_failure-2.sh
+++ b/support/tst-support_record_failure-2.sh
@@ -52,15 +52,15 @@ different_status () {
     run_test 1 "error: 1 test failures" $direct --status=1
     run_test 2 "error: 1 test failures" $direct --status=2
     run_test 1 "error: 1 test failures" $direct --status=77
-    run_test 2 "FAIL tst-support_record_failure.c:108: not true: false
+    run_test 2 "error: tst-support_record_failure.c:108: not true: false
 error: 1 test failures" $direct --test-verify
 }
 
 different_status
 different_status --direct
 
-run_test 1 "FAIL tst-support_record_failure.c:113: not true: false
+run_test 1 "error: tst-support_record_failure.c:113: not true: false
 error: 1 test failures" --test-verify-exit
 # --direct does not print the summary error message if exit is called.
-run_test 1 "FAIL tst-support_record_failure.c:113: not true: false" \
+run_test 1 "error: tst-support_record_failure.c:113: not true: false" \
 	 --direct --test-verify-exit
diff --git a/support/xasprintf.c b/support/xasprintf.c
index b9dc91b..6aa1fe6 100644
--- a/support/xasprintf.c
+++ b/support/xasprintf.c
@@ -21,6 +21,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <support/check.h>
 
 char *
 xasprintf (const char *format, ...)
@@ -29,10 +30,7 @@ xasprintf (const char *format, ...)
   va_start (ap, format);
   char *result;
   if (vasprintf (&result, format, ap) < 0)
-    {
-      printf ("error: asprintf: %m\n");
-      exit (1);
-    }
+    FAIL_EXIT1 ("asprintf: %m");
   va_end (ap);
   return result;
 }
diff --git a/support/xfork.c b/support/xfork.c
index 4b2ce91..6a2d9cc 100644
--- a/support/xfork.c
+++ b/support/xfork.c
@@ -20,15 +20,13 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <support/check.h>
 
 pid_t
 xfork (void)
 {
   pid_t result = fork ();
   if (result < 0)
-    {
-      printf ("error: fork: %m\n");
-      exit (1);
-    }
+    FAIL_EXIT1 ("fork: %m");
   return result;
 }
diff --git a/support/xpthread_check_return.c b/support/xpthread_check_return.c
index 8781ee1..398f945 100644
--- a/support/xpthread_check_return.c
+++ b/support/xpthread_check_return.c
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <support/check.h>
 
 void
 xpthread_check_return (const char *function, int value)
@@ -28,7 +29,6 @@ xpthread_check_return (const char *function, int value)
   if (value != 0)
     {
       errno = value;
-      printf ("error: %s: %m\n", function);
-      exit (1);
+      FAIL_EXIT1 ("%s: %m", function);
     }
 }
diff --git a/support/xsocket.c b/support/xsocket.c
index 9ebe63f..268a825 100644
--- a/support/xsocket.c
+++ b/support/xsocket.c
@@ -27,10 +27,6 @@ xsocket (int domain, int type, int protocol)
 {
   int fd = socket (domain, type, protocol);
   if (fd < 0)
-    {
-      support_record_failure ();
-      printf ("error: socket (%d, %d, %d): %m\n", domain, type, protocol);
-      exit (1);
-    }
+    FAIL_EXIT1 ("socket (%d, %d, %d): %m\n", domain, type, protocol);
   return fd;
 }
diff --git a/support/xwaitpid.c b/support/xwaitpid.c
index 5a6e540..f577535 100644
--- a/support/xwaitpid.c
+++ b/support/xwaitpid.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <support/check.h>
 #include <sys/wait.h>
 
 int
@@ -27,9 +28,6 @@ xwaitpid (int pid, int *status, int flags)
 {
   pid_t result = waitpid (pid, status, flags);
   if (result < 0)
-    {
-      printf ("error: waitpid: %m\n");
-      exit (1);
-    }
+    FAIL_EXIT1 ("waitpid: %m\n");
   return result;
 }

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5707a64d9462001f9c7c2e02d3f52cf8b0181658

commit 5707a64d9462001f9c7c2e02d3f52cf8b0181658
Author: Florian Weimer <fweimer@redhat.com>
Date:   Sat Dec 31 18:51:07 2016 +0100

    support: Helper functions for entering namespaces

diff --git a/ChangeLog b/ChangeLog
index 9685fde..e7b2fa1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2016-12-31  Florian Weimer  <fweimer@redhat.com>
 
+	* support/namespace.h: New file.
+	* support/support_become_root.c: Likewise.
+	* support/support_enter_network_namespace.c: Likewise.
+	* support/tst-support-namespace.c: Likewise.
+	* support/xsocket.c: Likewise.
+	* support/xsocket.h: Likewise.
+	* support/Makefile (libsupport-routines): Add support_become_root,
+	support_enter_network_namespace, xsocket.
+	(tests): Add tst-support-namespace.
+
+2016-12-31  Florian Weimer  <fweimer@redhat.com>
+
 	[BZ #17252]
 	* posix/unistd.h (getentropy): Declare for __USE_MISC, not just
 	__USE_GNU.
diff --git a/support/Makefile b/support/Makefile
index 4e9d42e..9544a08 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -30,6 +30,8 @@ libsupport-routines = \
   ignore_stderr \
   oom_error \
   set_fortify_handler \
+  support_become_root \
+  support_enter_network_namespace \
   support_record_failure \
   support_test_main \
   support_test_verify_impl \
@@ -54,6 +56,7 @@ libsupport-routines = \
   xpthread_spin_lock \
   xpthread_spin_unlock \
   xrealloc \
+  xsocket \
   xwaitpid \
 
 libsupport-static-only-routines := $(libsupport-routines)
@@ -65,6 +68,7 @@ endif
 
 tests = \
   README-testing \
+  tst-support-namespace \
   tst-support_record_failure \
 
 ifeq ($(run-built-tests),yes)
diff --git a/support/namespace.h b/support/namespace.h
new file mode 100644
index 0000000..4692907
--- /dev/null
+++ b/support/namespace.h
@@ -0,0 +1,53 @@
+/* Entering namespaces for test case isolation.
+   Copyright (C) 2016 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/>.  */
+
+#ifndef SUPPORT_NAMESPACE_H
+#define SUPPORT_NAMESPACE_H
+
+#include <stdbool.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+/* Attempts to become root (or acquire root-like privileges), possibly
+   with the help of user namespaces.  Return true if (restricted) root
+   privileges could be attained in some way.  Print diagnostics to
+   standard output.
+
+   Note that this function generally has to be called before a process
+   becomes multi-threaded, otherwise it may fail with insufficient
+   privileges on systems which would support this operation for
+   single-threaded processes.  */
+bool support_become_root (void);
+
+/* Enter a network namespace (and a UTS namespace if possible) and
+   configure the loopback interface.  Return true if a network
+   namespace could be created.  Print diagnostics to standard output.
+   If a network namespace could be created, but networking in it could
+   not be configured, terminate the process.  It is recommended to
+   call support_become_root before this function so that the process
+   has sufficient privileges.  */
+bool support_enter_network_namespace (void);
+
+/* Return true if support_enter_network_namespace managed to enter a
+   UTS namespace.  */
+bool support_in_uts_namespace (void);
+
+__END_DECLS
+
+#endif
diff --git a/support/support_become_root.c b/support/support_become_root.c
new file mode 100644
index 0000000..d13954c
--- /dev/null
+++ b/support/support_become_root.c
@@ -0,0 +1,40 @@
+/* Acquire root privileges.
+   Copyright (C) 2016 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 <support/namespace.h>
+
+#include <sched.h>
+#include <stdio.h>
+#include <unistd.h>
+
+bool
+support_become_root (void)
+{
+#ifdef CLONE_NEWUSER
+  if (unshare (CLONE_NEWUSER | CLONE_NEWNS) == 0)
+    /* Even if we do not have UID zero, we have extended privileges at
+       this point.  */
+    return true;
+#endif
+  if (setuid (0) != 0)
+    {
+      printf ("warning: could not become root outside namespace (%m)\n");
+      return false;
+    }
+  return true;
+}
diff --git a/support/support_enter_network_namespace.c b/support/support_enter_network_namespace.c
new file mode 100644
index 0000000..3af18e6
--- /dev/null
+++ b/support/support_enter_network_namespace.c
@@ -0,0 +1,74 @@
+/* Enter a network namespace.
+   Copyright (C) 2016 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 <support/namespace.h>
+
+#include <net/if.h>
+#include <sched.h>
+#include <stdio.h>
+#include <string.h>
+#include <support/check.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <xsocket.h>
+
+static bool in_uts_namespace;
+
+bool
+support_enter_network_namespace (void)
+{
+#ifdef CLONE_NEWUTS
+  if (unshare (CLONE_NEWUTS) == 0)
+    in_uts_namespace = true;
+  else
+    printf ("warning: unshare (CLONE_NEWUTS) failed: %m\n");
+#endif
+
+#ifdef CLONE_NEWNET
+  if (unshare (CLONE_NEWNET) == 0)
+    {
+      /* Bring up the loopback interface.  */
+      int fd = xsocket (AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+      struct ifreq req;
+      strcpy (req.ifr_name, "lo");
+      TEST_VERIFY_EXIT (ioctl (fd, SIOCGIFFLAGS, &req) == 0);
+      bool already_up = req.ifr_flags & IFF_UP;
+      if (already_up)
+        /* This means that we likely have not achieved isolation from
+           the parent namespace.  */
+        printf ("warning: loopback interface already exists"
+                " in new network namespace\n");
+      else
+        {
+          req.ifr_flags |= IFF_UP | IFF_RUNNING;
+          TEST_VERIFY_EXIT (ioctl (fd, SIOCSIFFLAGS, &req) == 0);
+        }
+      close (fd);
+
+      return !already_up;
+    }
+#endif
+  printf ("warning: could not enter network namespace\n");
+  return false;
+}
+
+bool
+support_in_uts_namespace (void)
+{
+  return in_uts_namespace;
+}
diff --git a/support/tst-support-namespace.c b/support/tst-support-namespace.c
new file mode 100644
index 0000000..bd2a2a6
--- /dev/null
+++ b/support/tst-support-namespace.c
@@ -0,0 +1,34 @@
+/* Test entering namespaces.
+   Copyright (C) 2016 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 <stdio.h>
+#include <support/namespace.h>
+
+static int
+do_test (void)
+{
+  if (support_become_root ())
+    printf ("info: acquired root-like privileges\n");
+  if (support_enter_network_namespace ())
+    printf ("info: entered network namespace\n");
+  if (support_in_uts_namespace ())
+    printf ("info: also entered UTS namespace\n");
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/support/xsocket.c b/support/xsocket.c
new file mode 100644
index 0000000..9ebe63f
--- /dev/null
+++ b/support/xsocket.c
@@ -0,0 +1,36 @@
+/* socket with error checking.
+   Copyright (C) 2016 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 <support/xsocket.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+
+int
+xsocket (int domain, int type, int protocol)
+{
+  int fd = socket (domain, type, protocol);
+  if (fd < 0)
+    {
+      support_record_failure ();
+      printf ("error: socket (%d, %d, %d): %m\n", domain, type, protocol);
+      exit (1);
+    }
+  return fd;
+}
diff --git a/support/xsocket.h b/support/xsocket.h
new file mode 100644
index 0000000..e9ff49e
--- /dev/null
+++ b/support/xsocket.h
@@ -0,0 +1,27 @@
+/* Error-checking wrappers for socket functions.
+   Copyright (C) 2016 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/>.  */
+
+#ifndef SUPPORT_XSOCKET_H
+#define SUPPORT_XSOCKET_H
+
+#include <sys/socket.h>
+#include <sys/types.h>
+
+int xsocket (int, int, int);
+
+#endif /* SUPPORT_XSOCKET_H */

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

Summary of changes:
 ChangeLog                                 |   47 ++++++++++++++++++
 support/Makefile                          |    4 ++
 support/check.c                           |    4 ++
 support/check.h                           |   10 +++-
 support/delayed_exit.c                    |    6 +--
 support/namespace.h                       |   53 ++++++++++++++++++++
 support/support_become_root.c             |   40 +++++++++++++++
 support/support_enter_network_namespace.c |   74 +++++++++++++++++++++++++++++
 support/support_record_failure.c          |    4 +-
 support/support_test_main.c               |   11 +++-
 support/support_test_verify_impl.c        |    2 +-
 support/test-driver.c                     |    4 +-
 support/test-driver.h                     |    6 ++
 support/tst-support-namespace.c           |   34 +++++++++++++
 support/tst-support_record_failure-2.sh   |    9 ++-
 support/tst-support_record_failure.c      |    2 +
 support/xasprintf.c                       |    6 +--
 support/xfork.c                           |    6 +--
 support/xpthread_check_return.c           |    4 +-
 support/xsocket.c                         |   32 ++++++++++++
 support/xsocket.h                         |   27 ++++++++++
 support/xwaitpid.c                        |    6 +--
 22 files changed, 358 insertions(+), 33 deletions(-)
 create mode 100644 support/namespace.h
 create mode 100644 support/support_become_root.c
 create mode 100644 support/support_enter_network_namespace.c
 create mode 100644 support/tst-support-namespace.c
 create mode 100644 support/xsocket.c
 create mode 100644 support/xsocket.h


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]