Commit 3e48109a authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

criu: Drop prlimit compat layer

Previously when we've been on early stage we
tried to workaround lack of prlimit libc call
simply providing own implementation,  but it
cause problems on some libc configurations so
simply use rlimit64 and __NR_prlimit64 syscall
directly.

The kernel must support __NR_prlimit64 syscall
and provide rlimit64 structure as well.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent c881d044
...@@ -14,7 +14,7 @@ ifeq ($(call pkg-config-check,libselinux),y) ...@@ -14,7 +14,7 @@ ifeq ($(call pkg-config-check,libselinux),y)
DEFINES += -DCONFIG_HAS_SELINUX DEFINES += -DCONFIG_HAS_SELINUX
endif endif
FEATURES_LIST := TCP_REPAIR PRLIMIT STRLCPY STRLCAT PTRACE_PEEKSIGINFO \ FEATURES_LIST := TCP_REPAIR STRLCPY STRLCAT PTRACE_PEEKSIGINFO \
SETPROCTITLE_INIT MEMFD SETPROCTITLE_INIT MEMFD
# $1 - config name # $1 - config name
......
#ifndef __CR_PRLIMIT_H__
#define __CR_PRLIMIT_H__
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "config.h"
#ifndef CONFIG_HAS_PRLIMIT
extern int prlimit(pid_t pid, int resource, const struct rlimit *new_rlimit, struct rlimit *old_rlimit);
#endif
#endif /* __CR_PRLIMIT_H__ */
...@@ -94,7 +94,6 @@ __NR_signalfd4 313 sys_signalfd (int fd, k_rtsigset_t *mask, size_t sizemask, ...@@ -94,7 +94,6 @@ __NR_signalfd4 313 sys_signalfd (int fd, k_rtsigset_t *mask, size_t sizemask,
__NR_rt_tgsigqueueinfo 322 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *info) __NR_rt_tgsigqueueinfo 322 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *info)
__NR_fanotify_init 323 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags) __NR_fanotify_init 323 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags)
__NR_fanotify_mark 324 sys_fanotify_mark (int fanotify_fd, unsigned int flags, u64 mask, int dfd, const char *pathname) __NR_fanotify_mark 324 sys_fanotify_mark (int fanotify_fd, unsigned int flags, u64 mask, int dfd, const char *pathname)
__NR_prlimit64 325 sys_prlimit64 (pid_t pid, unsigned int resource, const struct rlimit64 *new_rlim, struct rlimit64 *old_rlim)
__NR_open_by_handle_at 346 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags) __NR_open_by_handle_at 346 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags)
__NR_setns 350 sys_setns (int fd, int nstype) __NR_setns 350 sys_setns (int fd, int nstype)
__NR_kcmp 354 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) __NR_kcmp 354 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
......
...@@ -4,4 +4,3 @@ ccflags-y += -iquote $(obj) -iquote $(SRC_DIR) -iquote $(obj)/include -iquote $ ...@@ -4,4 +4,3 @@ ccflags-y += -iquote $(obj) -iquote $(SRC_DIR) -iquote $(obj)/include -iquote $
obj-y += cpu.o obj-y += cpu.o
obj-y += crtools.o obj-y += crtools.o
obj-y += prlimit.o
#ifndef __CR_PRLIMIT_H__
#define __CR_PRLIMIT_H__
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "config.h"
#ifndef CONFIG_HAS_PRLIMIT
extern int prlimit(pid_t pid, int resource, const struct rlimit *new_rlimit, struct rlimit *old_rlimit);
#endif
#endif /* __CR_PRLIMIT_H__ */
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "asm/page.h" #include "asm/page.h"
#include "asm/bitops.h" #include "asm/bitops.h"
#include "asm/int.h" #include "asm/int.h"
#include "asm/prlimit.h"
#include "images/core.pb-c.h" #include "images/core.pb-c.h"
......
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "asm/types.h"
#include "asm/prlimit.h"
#include "compiler.h"
#include "config.h"
#ifndef CONFIG_HAS_PRLIMIT
#ifndef RLIM64_INFINITY
# define RLIM64_INFINITY (~0ULL)
#endif
int prlimit(pid_t pid, int resource, const struct rlimit *new_rlimit, struct rlimit *old_rlimit)
{
struct rlimit64 new_rlimit64_mem;
struct rlimit64 old_rlimit64_mem;
struct rlimit64 *new_rlimit64 = NULL;
struct rlimit64 *old_rlimit64 = NULL;
int ret;
if (old_rlimit)
old_rlimit64 = &old_rlimit64_mem;
if (new_rlimit) {
if (new_rlimit->rlim_cur == RLIM_INFINITY)
new_rlimit64_mem.rlim_cur = RLIM64_INFINITY;
else
new_rlimit64_mem.rlim_cur = new_rlimit->rlim_cur;
if (new_rlimit->rlim_max == RLIM_INFINITY)
new_rlimit64_mem.rlim_max = RLIM64_INFINITY;
else
new_rlimit64_mem.rlim_max = new_rlimit->rlim_max;
new_rlimit64 = &new_rlimit64_mem;
}
ret = sys_prlimit64(pid, resource, new_rlimit64, old_rlimit64);
if (ret == 0 && old_rlimit) {
old_rlimit->rlim_cur = old_rlimit64_mem.rlim_cur;
if (old_rlimit->rlim_cur != old_rlimit64_mem.rlim_cur) {
if (new_rlimit) {
errno = EOVERFLOW;
return -1;
}
old_rlimit->rlim_cur = RLIM_INFINITY;
}
old_rlimit->rlim_max = old_rlimit64_mem.rlim_max;
if (old_rlimit->rlim_max != old_rlimit64_mem.rlim_max) {
if (new_rlimit) {
errno = EOVERFLOW;
return -1;
}
old_rlimit->rlim_max = RLIM_INFINITY;
}
} else if (ret) {
errno = -ret;
ret = -1;
}
return ret;
}
#endif /* CONFIG_HAS_PRLIMIT */
...@@ -86,7 +86,6 @@ __NR_timerfd_settime 325 sys_timerfd_settime (int ufd, int flags, const struct ...@@ -86,7 +86,6 @@ __NR_timerfd_settime 325 sys_timerfd_settime (int ufd, int flags, const struct
__NR_rt_tgsigqueueinfo 335 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *uinfo) __NR_rt_tgsigqueueinfo 335 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *uinfo)
__NR_fanotify_init 338 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags) __NR_fanotify_init 338 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags)
__NR_fanotify_mark 339 sys_fanotify_mark (int fanotify_fd, unsigned int flag, u32 mask, int dfd, const char *pathname) __NR_fanotify_mark 339 sys_fanotify_mark (int fanotify_fd, unsigned int flag, u32 mask, int dfd, const char *pathname)
__NR_prlimit64 340 sys_prlimit64 (pid_t pid, unsigned int resource, const struct rlimit64 *new_rlim, struct rlimit64 *old_rlim)
__NR_open_by_handle_at 342 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags) __NR_open_by_handle_at 342 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags)
__NR_setns 346 sys_setns (int fd, int nstype) __NR_setns 346 sys_setns (int fd, int nstype)
__NR_kcmp 349 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) __NR_kcmp 349 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
......
...@@ -97,7 +97,6 @@ __NR_signalfd4 289 sys_signalfd (int fd, k_rtsigset_t *mask, size_t sizemask ...@@ -97,7 +97,6 @@ __NR_signalfd4 289 sys_signalfd (int fd, k_rtsigset_t *mask, size_t sizemask
__NR_rt_tgsigqueueinfo 297 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *info) __NR_rt_tgsigqueueinfo 297 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *info)
__NR_fanotify_init 300 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags) __NR_fanotify_init 300 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags)
__NR_fanotify_mark 301 sys_fanotify_mark (int fanotify_fd, unsigned int flags, u64 mask, int dfd, const char *pathname) __NR_fanotify_mark 301 sys_fanotify_mark (int fanotify_fd, unsigned int flags, u64 mask, int dfd, const char *pathname)
__NR_prlimit64 302 sys_prlimit64 (pid_t pid, unsigned int resource, const struct rlimit64 *new_rlim, struct rlimit64 *old_rlim)
__NR_open_by_handle_at 304 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags) __NR_open_by_handle_at 304 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags)
__NR_setns 308 sys_setns (int fd, int nstype) __NR_setns 308 sys_setns (int fd, int nstype)
__NR_kcmp 312 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) __NR_kcmp 312 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
......
...@@ -307,9 +307,9 @@ static int dump_task_rlimits(int pid, TaskRlimitsEntry *rls) ...@@ -307,9 +307,9 @@ static int dump_task_rlimits(int pid, TaskRlimitsEntry *rls)
int res; int res;
for (res = 0; res <rls->n_rlimits ; res++) { for (res = 0; res <rls->n_rlimits ; res++) {
struct rlimit lim; struct rlimit64 lim;
if (prlimit(pid, res, NULL, &lim)) { if (syscall(__NR_prlimit64, pid, res, NULL, &lim)) {
pr_perror("Can't get rlimit %d", res); pr_perror("Can't get rlimit %d", res);
return -1; return -1;
} }
......
...@@ -2739,7 +2739,7 @@ static int prepare_rlimits(int pid, CoreEntry *core) ...@@ -2739,7 +2739,7 @@ static int prepare_rlimits(int pid, CoreEntry *core)
{ {
int i; int i;
TaskRlimitsEntry *rls = core->tc->rlimits; TaskRlimitsEntry *rls = core->tc->rlimits;
struct rlimit *r; struct rlimit64 *r;
rlims_cpos = rst_mem_align_cpos(RM_PRIVATE); rlims_cpos = rst_mem_align_cpos(RM_PRIVATE);
......
...@@ -151,7 +151,7 @@ struct task_restore_args { ...@@ -151,7 +151,7 @@ struct task_restore_args {
struct rst_aio_ring *rings; struct rst_aio_ring *rings;
unsigned int rings_n; unsigned int rings_n;
struct rlimit *rlims; struct rlimit64 *rlims;
unsigned int rlims_n; unsigned int rlims_n;
pid_t *helpers /* the TASK_HELPERS to wait on at the end of restore */; pid_t *helpers /* the TASK_HELPERS to wait on at the end of restore */;
......
...@@ -72,9 +72,6 @@ struct itimerspec; ...@@ -72,9 +72,6 @@ struct itimerspec;
#define CLONE_ALLNS (CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWCGROUP) #define CLONE_ALLNS (CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWCGROUP)
struct rlimit;
struct rlimit64;
struct krlimit { struct krlimit {
unsigned long rlim_cur; unsigned long rlim_cur;
unsigned long rlim_max; unsigned long rlim_max;
......
...@@ -386,14 +386,14 @@ static int service_fd_id = 0; ...@@ -386,14 +386,14 @@ static int service_fd_id = 0;
int init_service_fd(void) int init_service_fd(void)
{ {
struct rlimit rlimit; struct rlimit64 rlimit;
/* /*
* Service FDs are those that most likely won't * Service FDs are those that most likely won't
* conflict with any 'real-life' ones * conflict with any 'real-life' ones
*/ */
if (getrlimit(RLIMIT_NOFILE, &rlimit)) { if (syscall(__NR_prlimit64, getpid(), RLIMIT_NOFILE, NULL, &rlimit)) {
pr_perror("Can't get rlimit"); pr_perror("Can't get rlimit");
return -1; return -1;
} }
......
...@@ -12,24 +12,6 @@ int main(void) ...@@ -12,24 +12,6 @@ int main(void)
} }
endef endef
define FEATURE_TEST_PRLIMIT
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
int main(void)
{
struct rlimit limit = {
.rlim_cur = RLIM_INFINITY,
.rlim_max = RLIM_INFINITY,
};
return prlimit(getpid(), RLIMIT_CPU, &limit, NULL);
}
endef
define FEATURE_TEST_LIBBSD_DEV define FEATURE_TEST_LIBBSD_DEV
#include <bsd/string.h> #include <bsd/string.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment