@@ -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;
+}