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

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