Blame SOURCES/0240-vmcore-use-findmnt-to-get-mountpoint.patch

a60cd7
From 79108d97e3b3d031c34c432634b305ce0becf716 Mon Sep 17 00:00:00 2001
a60cd7
From: Jakub Filak <jfilak@redhat.com>
a60cd7
Date: Thu, 16 Jun 2016 14:21:28 +0200
a60cd7
Subject: [PATCH] vmcore: use findmnt to get mountpoint
a60cd7
a60cd7
findmnt solves both problems:
a60cd7
* UUID=/LABEL=
a60cd7
* different device links
a60cd7
a60cd7
Related: rhbz#1147053
a60cd7
a60cd7
Signed-off-by: Jakub Filak <jfilak@redhat.com>
a60cd7
a60cd7
Conflicts:
a60cd7
	src/hooks/abrt_harvest_vmcore.py.in
a60cd7
---
a60cd7
 configure.ac                        |  2 +-
a60cd7
 src/hooks/Makefile.am               |  2 +-
a60cd7
 src/hooks/abrt_harvest_vmcore.py.in | 59 ++++++++++++++-----------------------
a60cd7
 3 files changed, 24 insertions(+), 39 deletions(-)
a60cd7
a60cd7
diff --git a/configure.ac b/configure.ac
a60cd7
index 20a7f27..02d7e0e 100644
a60cd7
--- a/configure.ac
a60cd7
+++ b/configure.ac
a60cd7
@@ -173,7 +173,7 @@ AC_ARG_ENABLE(doxygen-docs,
a60cd7
     [enable_doxygen_docs=no]
a60cd7
 )
a60cd7
 
a60cd7
-AC_PATH_PROG([BLKID], [BLKID], [/usr/sbin/blkid], [$PATH:/usr/sbin:/sbin])
a60cd7
+AC_PATH_PROG([FINDMNT], [findmnt], [/usr/bin/findmnt], [$PATH:/usr/sbin:/sbin])
a60cd7
 
a60cd7
 # Doxygen Documentation
a60cd7
 
a60cd7
diff --git a/src/hooks/Makefile.am b/src/hooks/Makefile.am
a60cd7
index 216cfc1..650a771 100644
a60cd7
--- a/src/hooks/Makefile.am
a60cd7
+++ b/src/hooks/Makefile.am
a60cd7
@@ -92,7 +92,7 @@ abrt-install-ccpp-hook: abrt-install-ccpp-hook.in
a60cd7
 abrt-harvest-vmcore: abrt_harvest_vmcore.py.in
a60cd7
 	sed -e s,\@CONF_DIR\@,\$(CONF_DIR)\,g \
a60cd7
 	    -e s,\@DEFAULT_DUMP_LOCATION\@,$(DEFAULT_DUMP_LOCATION),g \
a60cd7
-	    -e s,\@BLKID\@,$(BLKID),g \
a60cd7
+	    -e s,\@FINDMNT\@,$(FINDMNT),g \
a60cd7
 		$< >$@
a60cd7
 
a60cd7
 abrt-harvest-pstoreoops: abrt-harvest-pstoreoops.in
a60cd7
diff --git a/src/hooks/abrt_harvest_vmcore.py.in b/src/hooks/abrt_harvest_vmcore.py.in
a60cd7
index e71e5c9..6b2719e 100644
a60cd7
--- a/src/hooks/abrt_harvest_vmcore.py.in
a60cd7
+++ b/src/hooks/abrt_harvest_vmcore.py.in
a60cd7
@@ -18,6 +18,12 @@ from subprocess import Popen, PIPE
a60cd7
 import problem
a60cd7
 
a60cd7
 
a60cd7
+def errx(message, code=1):
a60cd7
+    sys.stderr.write(message)
a60cd7
+    sys.stderr.write("\n")
a60cd7
+    sys.stderr.flush()
a60cd7
+    sys.exit(code)
a60cd7
+
a60cd7
 def get_augeas(module, file_path):
a60cd7
     """
a60cd7
     A function for efficient configuration of Augeas.
a60cd7
@@ -32,49 +38,28 @@ def get_augeas(module, file_path):
a60cd7
 
a60cd7
 def get_mount_point(part_id):
a60cd7
     """
a60cd7
-    A function used to look up a mount point in mtab using
a60cd7
-    the provided identifier.
a60cd7
+    A function used to look up a mount point of the provided identifier
a60cd7
+    using 'findmnt' system utility.
a60cd7
 
a60cd7
     part_id - device node, label or uuid
a60cd7
     """
a60cd7
 
a60cd7
-    idtypes = {"UUID=":"-U", "PARTUUID=":"-U", "LABEL=":"-L", "PARTLABEL=":"-L"}
a60cd7
-
a60cd7
-    for typ, switch in idtypes.items():
a60cd7
-        if not part_id.startswith(typ):
a60cd7
-            continue
a60cd7
-
a60cd7
-        idf = part_id[len(typ):]
a60cd7
-        try:
a60cd7
-            proc = Popen(["@BLKID@", switch, idf], stdout=PIPE, stderr=PIPE)
a60cd7
-            out, err = proc.communicate()
a60cd7
-            if err:
a60cd7
-                sys.stderr.write("Failed 'blkid {0} {1}': {2}\n"
a60cd7
-                                 .format(switch, idf, err))
a60cd7
-                sys.exit(1)
a60cd7
-            if not out:
a60cd7
-                sys.stderr.write("No results from 'blkid {0} {1}'\n"
a60cd7
-                                 .format(switch, idf))
a60cd7
-                sys.exit(1)
a60cd7
-
a60cd7
-            part_id = out.strip()
a60cd7
-            break
a60cd7
-        except OSError as ex:
a60cd7
-            sys.stderr.write("Cannot run 'blkid {0} {1}': {2}\n"
a60cd7
-                              .format(switch, idf, str(ex)))
a60cd7
-            sys.exit(1)
a60cd7
+    try:
a60cd7
+        proc = Popen(["@FINDMNT@", "--noheadings", "--first-only", "--raw",
a60cd7
+                     "--evaluate", "--output", "TARGET", part_id],
a60cd7
+                     stdout=PIPE, stderr=PIPE)
a60cd7
+        out, err = proc.communicate()
a60cd7
+        if err:
a60cd7
+            errx("Error finding mountpoint of '{0}': {1}"
a60cd7
+                 .format(devpath, err))
a60cd7
+
a60cd7
+        result = out.strip()
a60cd7
+        if proc.returncode != 0 or not result:
a60cd7
+            errx("Cannot find mountpoint of '{0}'".format(part_id))
a60cd7
 
a60cd7
-    # look up the identifier in /etc/mtab
a60cd7
-    result = get_augeas("Fstab", "/etc/mtab").get("/files/etc/mtab/*"
a60cd7
-                                 "[spec=\"" + part_id + "\"]/file")
a60cd7
-    if result:
a60cd7
         return result
a60cd7
-    else:
a60cd7
-        # identifier not in the table
a60cd7
-        sys.stderr.write("Error: Cannot access partition '" + part_id +
a60cd7
-                         "', mount point not found in /etc/mtab!\n")
a60cd7
-        sys.exit(1)
a60cd7
-
a60cd7
+    except OSError as ex:
a60cd7
+        errx("Cannot run 'findmnt': {1}".format(str(ex)))
a60cd7
 
a60cd7
 def parse_kdump():
a60cd7
     """
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7