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