From 26f38328d66f4bd525e9d21a9245ba4c54d6ca10 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 20 Jan 2012 22:10:47 -0500 Subject: [PATCH] add prlimit syscall wrapper --- arch/i386/bits/syscall.h | 2 ++ include/sys/resource.h | 8 ++++++++ src/misc/prlimit.c | 8 ++++++++ 3 files changed, 18 insertions(+) create mode 100644 src/misc/prlimit.c diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h index 8d673186..1147e9f3 100644 --- a/arch/i386/bits/syscall.h +++ b/arch/i386/bits/syscall.h @@ -470,6 +470,7 @@ static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __ #define __NR_inotify_init1 332 #define __NR_preadv 333 #define __NR_pwritev 334 +#define __NR_prlimit64 340 /* fixup legacy 16-bit junk */ #undef __NR_lchown @@ -881,6 +882,7 @@ static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __ #define SYS_inotify_init1 332 #define SYS_preadv 333 #define SYS_pwritev 334 +#define SYS_prlimit64 340 /* fixup legacy 16-bit junk */ #undef SYS_lchown diff --git a/include/sys/resource.h b/include/sys/resource.h index b9189028..cb39923f 100644 --- a/include/sys/resource.h +++ b/include/sys/resource.h @@ -9,6 +9,10 @@ extern "C" { #define __NEED_time_t #define __NEED_struct_timeval +#ifdef _GNU_SOURCE +#define __NEED_pid_t +#endif + #include typedef unsigned long long rlim_t; @@ -49,6 +53,10 @@ int getrusage (int, struct rusage *); int getpriority (int, id_t); int setpriority (int, id_t, int); +#ifdef _GNU_SOURCE +int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); +#endif + #define PRIO_PROCESS 0 #define PRIO_PGRP 1 #define PRIO_USER 2 diff --git a/src/misc/prlimit.c b/src/misc/prlimit.c new file mode 100644 index 00000000..b9dbb446 --- /dev/null +++ b/src/misc/prlimit.c @@ -0,0 +1,8 @@ +#include +#include +#include "syscall.h" + +int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) +{ + return syscall(SYS_prlimit64, pid, resource, new_limit, old_limit); +} -- 2.25.1