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

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