summaryrefslogtreecommitdiff
path: root/m4/ax_check_uts_namespace.m4
diff options
context:
space:
mode:
authorYu Jiung <jiung.yu@samsung.com>2016-11-10 16:24:08 +0900
committerYu Jiung <jiung.yu@samsung.com>2016-11-10 16:25:02 +0900
commit8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8 (patch)
tree81f0750d91aa467df3ee81cf30d22a65db2e6685 /m4/ax_check_uts_namespace.m4
parentccccebb78520ec3a26a18370936516b12ae5d53a (diff)
parent45e88a8337839e5fd88519bc55467053d521c9f6 (diff)
downloadc-ares-submit/tizen_4.0_base/20170828.000001.tar.gz
c-ares-submit/tizen_4.0_base/20170828.000001.tar.bz2
c-ares-submit/tizen_4.0_base/20170828.000001.zip
Conflicts: packaging/c-ares.spec Change-Id: I1ec10e394aed3ef19ee21fefbe3aba7d7a615c74
Diffstat (limited to 'm4/ax_check_uts_namespace.m4')
-rw-r--r--m4/ax_check_uts_namespace.m476
1 files changed, 76 insertions, 0 deletions
diff --git a/m4/ax_check_uts_namespace.m4 b/m4/ax_check_uts_namespace.m4
new file mode 100644
index 0000000..cf7b145
--- /dev/null
+++ b/m4/ax_check_uts_namespace.m4
@@ -0,0 +1,76 @@
+# -*- Autoconf -*-
+
+# SYNOPSIS
+#
+# AX_CHECK_UTS_NAMESPACE
+#
+# DESCRIPTION
+#
+# This macro checks whether the local system supports Linux UTS namespaces.
+# Also requires user namespaces to be available, so that non-root users
+# can enter the namespace.
+# If so, it calls AC_DEFINE(HAVE_UTS_NAMESPACE).
+
+AC_DEFUN([AX_CHECK_UTS_NAMESPACE],[dnl
+ AC_CACHE_CHECK([whether UTS namespaces are supported],
+ ax_cv_uts_namespace,[
+ AC_LANG_PUSH([C])
+ AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#define _GNU_SOURCE
+#include <sched.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int utsfn(void *d) {
+ char buffer[1024];
+ const char *name = "autoconftest";
+ int rc = sethostname(name, strlen(name));
+ if (rc != 0) return 1;
+ gethostname(buffer, 1024);
+ return (strcmp(buffer, name) != 0);
+}
+
+char st2[1024*1024];
+int fn(void *d) {
+ pid_t child;
+ int rc, status;
+ usleep(100000); /* synchronize by sleep */
+ if (getuid() != 0) return 1;
+ child = clone(utsfn, st2 + 1024*1024, CLONE_NEWUTS|SIGCHLD, 0);
+ if (child < 0) return 1;
+ rc = waitpid(child, &status, 0);
+ if (rc <= 0) return 1;
+ if (!WIFEXITED(status)) return 1;
+ return WEXITSTATUS(status);
+}
+char st[1024*1024];
+int main() {
+ char buffer[1024];
+ int rc, status, fd;
+ pid_t child = clone(fn, st + 1024*1024, CLONE_NEWUSER|SIGCHLD, 0);
+ if (child < 0) return 1;
+
+ sprintf(buffer, "/proc/%d/uid_map", child);
+ fd = open(buffer, O_CREAT|O_WRONLY|O_TRUNC, 0755);
+ sprintf(buffer, "0 %d 1\n", getuid());
+ write(fd, buffer, strlen(buffer));
+ close(fd);
+
+ rc = waitpid(child, &status, 0);
+ if (rc <= 0) return 1;
+ if (!WIFEXITED(status)) return 1;
+ return WEXITSTATUS(status);
+}
+]])
+ ],[ax_cv_uts_namespace=yes],[ax_cv_uts_namespace=no],[ax_cv_uts_namespace=no])
+ AC_LANG_POP([C])
+ ])
+ if test "$ax_cv_uts_namespace" = yes; then
+ AC_DEFINE([HAVE_UTS_NAMESPACE],[1],[Whether UTS namespaces are available])
+ fi
+]) # AX_CHECK_UTS_NAMESPACE