From 81c9444cd556094856b6ae6da07edfa54857fc66 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 1 Mar 2022 23:34:19 +0100 Subject: [PATCH] devices/lvm2.lv: separate stdout and stderr In all invocations of `subprocess.run` stderr and stdout were both combined in a shared pipe, but lvm sometimes spits out notices and informational messages on stderr and thus potentially interfering with the data we are interested in on stdout. Separate the two. --- devices/org.osbuild.lvm2.lv | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/devices/org.osbuild.lvm2.lv b/devices/org.osbuild.lvm2.lv index bfcaa9e8..af8eedaa 100755 --- a/devices/org.osbuild.lvm2.lv +++ b/devices/org.osbuild.lvm2.lv @@ -67,12 +67,12 @@ class LVService(devices.DeviceService): ] res = subprocess.run(cmd, check=False, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stdout=subprocess.DEVNULL, + stderr=subprocess.PIPE, encoding="UTF-8") if res.returncode != 0: - data = res.stdout.strip() + data = res.stderr.strip() msg = f"Failed to set LV device ({fullname}) status: {data}" raise RuntimeError(msg) @@ -90,7 +90,7 @@ class LVService(devices.DeviceService): res = subprocess.run(cmd, check=False, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=subprocess.PIPE, encoding="UTF-8") if res.returncode == 5: @@ -101,7 +101,7 @@ class LVService(devices.DeviceService): continue if res.returncode != 0: - json.dump({"error": res.stdout.strip()}, sys.stdout) + json.dump({"error": res.stderr.strip()}, sys.stdout) return 1 vg_name = res.stdout.strip() @@ -125,11 +125,11 @@ class LVService(devices.DeviceService): res = subprocess.run(cmd, check=False, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=subprocess.PIPE, encoding="UTF-8") if res.returncode != 0: - raise RuntimeError(res.stdout.strip()) + raise RuntimeError(res.stderr.strip()) data = res.stdout.strip() devnum = list(map(int, data.split(";")))