]> git.proxmox.com Git - mirror_lxc.git/commitdiff
android: add prlimit implementation for 32bit
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 14 Apr 2017 21:25:11 +0000 (23:25 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 14 Apr 2017 22:18:31 +0000 (00:18 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
configure.ac
src/include/prlimit.c [new file with mode: 0644]
src/include/prlimit.h [new file with mode: 0644]
src/lxc/Makefile.am
src/lxc/conf.c

index 287d57f559216cab1e2f2a4339f6bd9e9f99becb..4db75cfb517ce779b86d14f0b128db94ba29aae2 100644 (file)
@@ -665,6 +665,10 @@ AC_CHECK_FUNCS([fgetln],
        AM_CONDITIONAL(HAVE_FGETLN, true)
        AC_DEFINE(HAVE_FGETLN,1,[Have fgetln]),
        AM_CONDITIONAL(HAVE_FGETLN, false))
+AC_CHECK_FUNCS([prlimit],
+       AM_CONDITIONAL(HAVE_PRLIMIT, true)
+       AC_DEFINE(HAVE_PRLIMIT,1,[Have prlimit]),
+       AM_CONDITIONAL(HAVE_PRLIMIT, false))
 
 # Check for some libraries
 AC_SEARCH_LIBS(sem_open, [rt pthread])
diff --git a/src/include/prlimit.c b/src/include/prlimit.c
new file mode 100644 (file)
index 0000000..3718f14
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <linux/types.h> /* __le64, __l32 ... */
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/vfs.h>
+
+#if defined(__LP64__)
+#error This code is only needed on 32-bit systems!
+#endif
+
+#define RLIM64_INFINITY (~0ULL)
+
+typedef uint64_t u64;
+
+// There is no prlimit system call, so we need to use prlimit64.
+int prlimit(pid_t pid, int resource, const struct rlimit *n32, struct rlimit *o32)
+{
+       struct rlimit64 n64;
+       if (n32 != NULL) {
+               n64.rlim_cur = (n32->rlim_cur == RLIM_INFINITY)
+                                  ? RLIM64_INFINITY
+                                  : n32->rlim_cur;
+               n64.rlim_max = (n32->rlim_max == RLIM_INFINITY)
+                                  ? RLIM64_INFINITY
+                                  : n32->rlim_max;
+       }
+
+       struct rlimit64 o64;
+       int result = prlimit64(
+           pid, resource, (n32 != NULL) ? (const struct rlimit64 *)&n64 : NULL,
+           (o32 != NULL) ? &o64 : NULL);
+
+       if (result != -1 && o32 != NULL) {
+               o32->rlim_cur = (o64.rlim_cur == RLIM64_INFINITY)
+                                   ? RLIM_INFINITY
+                                   : o64.rlim_cur;
+               o32->rlim_max = (o64.rlim_max == RLIM64_INFINITY)
+                                   ? RLIM_INFINITY
+                                   : o64.rlim_max;
+       }
+
+       return result;
+}
diff --git a/src/include/prlimit.h b/src/include/prlimit.h
new file mode 100644 (file)
index 0000000..ab19b37
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _PRLIMIT_H
+#define _PRLIMIT_H
+
+#include <linux/resource.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#define RLIM_SAVED_CUR RLIM_INFINITY
+#define RLIM_SAVED_MAX RLIM_INFINITY
+
+int prlimit(pid_t, int, const struct rlimit*, struct rlimit*);
+int prlimit64(pid_t, int, const struct rlimit64*, struct rlimit64*);
+
+#endif
index d7c05d6fec6415a52429e350956af3f3232c03b2..a6a69decf193a740aac2329129149abe463e1c27 100644 (file)
@@ -40,6 +40,9 @@ noinst_HEADERS += \
        ../include/ifaddrs.h \
        ../include/openpty.h \
        ../include/lxcmntent.h
+if !HAVE_PRLIMIT
+noinst_HEADERS += ../include/prlimit.h
+endif
 endif
 
 if !HAVE_GETLINE
@@ -130,6 +133,9 @@ liblxc_la_SOURCES += \
        ../include/ifaddrs.c ../include/ifaddrs.h \
        ../include/openpty.c ../include/openpty.h \
        ../include/lxcmntent.c ../include/lxcmntent.h
+if !HAVE_PRLIMIT
+liblxc_la_SOURCES += ../include/prlimit.c ../include/prlimit.h
+endif
 endif
 
 if !HAVE_GETLINE
index 530a57ed15859970f89627580029a0e9008dca34..b600c275ab9dd80e09192a98bdf4f0dea5a04619 100644 (file)
@@ -99,6 +99,9 @@
 
 #if IS_BIONIC
 #include <../include/lxcmntent.h>
+#ifndef HAVE_PRLIMIT
+#include <../include/prlimit.h>
+#endif
 #else
 #include <mntent.h>
 #endif