2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 13:58:34 +00:00

sysctl: Use open_proc()

Many of sysctl_op-s we have read (or write) single entry.
In current implementaiton this results in two opens and
two closes for each -- open /proc/sys, then open the rest.

It's better to use open_proc() as the latter already have
fd for /proc cached.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Pavel Emelyanov 2017-04-14 19:56:40 +03:00 committed by Andrei Vagin
parent f830c2d8d0
commit 2c425ed67c

View File

@ -351,23 +351,15 @@ out:
static int __nonuserns_sysctl_op(struct sysctl_req *req, size_t nr_req, int op)
{
int dir, ret, exit_code = -1;;
dir = open("/proc/sys", O_RDONLY, O_DIRECTORY);
if (dir < 0) {
pr_perror("Can't open sysctl dir");
return -1;
}
int ret, exit_code = -1;;
while (nr_req--) {
int fd, flags;
int fd;
if (op == CTL_READ)
flags = O_RDONLY;
fd = open_proc(PROC_GEN, "sys/%s", req->name);
else
flags = O_WRONLY;
fd = openat(dir, req->name, flags);
fd = open_proc_rw(PROC_GEN, "sys/%s", req->name);
if (fd < 0) {
if (errno == ENOENT && (req->flags & CTL_FLAGS_OPTIONAL)) {
req++;
@ -394,7 +386,6 @@ static int __nonuserns_sysctl_op(struct sysctl_req *req, size_t nr_req, int op)
exit_code = 0;
out:
close(dir);
return exit_code;
}