a52f674
From 817a2d0c98ca035e2a906c04a4e2509103c583b1 Mon Sep 17 00:00:00 2001
a52f674
From: Matt Mullins <mokomull@gmail.com>
a52f674
Date: Mon, 24 Feb 2014 15:03:52 -0800
a52f674
Subject: [PATCH] core: do not segfault if /proc/swaps cannot be opened
a52f674
a52f674
The refactoring in f84b1b1ff9b1261 ('core: do not segfault if swap
a52f674
activity happens when /proc/swaps is not open') caused
a52f674
swap_dispatch_reload and swap_enumerate to continue even if fopen()
a52f674
failed with ENOENT.
a52f674
a52f674
This should instead be modified to return from swap_dispatch_reload and
a52f674
swap_enumerate, rather than continuing to load the list of swaps when
a52f674
m->proc_swaps is NULL.
a52f674
a52f674
https://bugzilla.redhat.com/show_bug.cgi?id=1069393
a52f674
---
a52f674
 src/core/swap.c | 6 +++---
a52f674
 1 file changed, 3 insertions(+), 3 deletions(-)
a52f674
a52f674
diff --git a/src/core/swap.c b/src/core/swap.c
a52f674
index 727bb95..3c009da 100644
a52f674
--- a/src/core/swap.c
a52f674
+++ b/src/core/swap.c
a52f674
@@ -1074,7 +1074,7 @@ static int open_proc_swaps(Manager *m) {
a52f674
 
a52f674
                 m->proc_swaps = fopen("/proc/swaps", "re");
a52f674
                 if (!m->proc_swaps)
a52f674
-                        return (errno == ENOENT) ? 0 : -errno;
a52f674
+                        return -errno;
a52f674
 
a52f674
                 m->swap_watch.type = WATCH_SWAP;
a52f674
                 m->swap_watch.fd = fileno(m->proc_swaps);
a52f674
@@ -1097,7 +1097,7 @@ int swap_dispatch_reload(Manager *m) {
a52f674
 
a52f674
         r = open_proc_swaps(m);
a52f674
         if (r < 0)
a52f674
-                return r;
a52f674
+                return (r == -ENOENT) ? 0 : r;
a52f674
 
a52f674
         return swap_fd_event(m, EPOLLPRI);
a52f674
 }
a52f674
@@ -1250,7 +1250,7 @@ static int swap_enumerate(Manager *m) {
a52f674
 
a52f674
         r = open_proc_swaps(m);
a52f674
         if (r < 0)
a52f674
-                return r;
a52f674
+                return (r == -ENOENT) ? 0 : r;
a52f674
 
a52f674
         r = swap_load_proc_swaps(m, false);
a52f674
         if (r < 0)