From 2c425ed67c904aa358f1fb2d3ff52f11ebf2827a Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 14 Apr 2017 19:56:40 +0300 Subject: [PATCH] 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 Signed-off-by: Andrei Vagin --- criu/sysctl.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/criu/sysctl.c b/criu/sysctl.c index 1f3c9af90..f1e110ed3 100644 --- a/criu/sysctl.c +++ b/criu/sysctl.c @@ -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; }