doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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