[v5,1/2] support: Add support_enter_time_namespace
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
Commit Message
Enter a time namespace, where the new namespace isolates clock
values. It requires either a root-like privileges (done with
support_become_root) or a previous user namespace (CLONE_NEWUSER).
A time namespace is similar to a pid namespace in the way how it is
created: unshare(CLONE_NEWTIME) system call creates a new time
namespace, but doesn't set it to the current process. Then all
children of the process will be born in the new time namespace.
It will be used on posix_spawn tests to exercise the BZ #29115
fix, where clone (CLONE_VFORK | CLONE_VM) fails if the process
enter a time namespace.
---
support/Makefile | 1 +
support/namespace.h | 5 ++++
support/support_enter_time_namespace.c | 34 ++++++++++++++++++++++++++
3 files changed, 40 insertions(+)
create mode 100644 support/support_enter_time_namespace.c
@@ -56,6 +56,7 @@ libsupport-routines = \
support_descriptors \
support_enter_mount_namespace \
support_enter_network_namespace \
+ support_enter_time_namespace \
support_format_address_family \
support_format_addrinfo \
support_format_dns_packet \
@@ -56,6 +56,11 @@ bool support_enter_network_namespace (void);
not affect the host system afterwards. */
bool support_enter_mount_namespace (void);
+/* Enter a time namespace, where the new namespace isolates clock
+ values. It requires either a root-like privileges (done with
+ support_become_root) or a previous user namespace (CLONE_NEWUSER). */
+bool support_enter_time_namespace (void);
+
/* Return true if support_enter_network_namespace managed to enter a
UTS namespace. */
bool support_in_uts_namespace (void);
new file mode 100644
@@ -0,0 +1,34 @@
+/* Enter a time namespace.
+ Copyright (C) 2022 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
+ <https://www.gnu.org/licenses/>. */
+
+#include <support/namespace.h>
+
+#include <sched.h>
+#include <stdio.h>
+
+bool
+support_enter_time_namespace (void)
+{
+#ifdef CLONE_NEWTIME
+ if (unshare (CLONE_NEWTIME) == 0)
+ return true;
+ else
+ printf ("warning: unshare (CLONE_NEWTIME) failed: %m\n");
+#endif /* CLONE_NEWNS */
+ return false;
+}