Commit 2c425ed6 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

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: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent f830c2d8
......@@ -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;
}
......
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