From: Punit Agrawal <punitagrawal@gmail.com>
To: jkacur@redhat.com
Cc: linux-rt-users@vger.kernel.org,
Punit Agrawal <punit1.agrawal@toshiba.co.jp>
Subject: [PATCH v2] rteval: services.py: Fix incorrect detection of container environment
Date: Mon, 13 Sep 2021 17:06:25 +0900 [thread overview]
Message-ID: <20210913080625.2017964-1-punitagrawal@gmail.com> (raw)
In-Reply-To: <d18a85b5-d591-a21b-c7fc-93655f7963c@redhat.com>
From: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
rteval mistakenly detects that it is running inside a container even
though it is running directly on the host. On further investigation
this was found to be due to change in behaviour around byte strings
and strings when going from python2 to python3.
In python3 process output (stdout, stderr) for processes executed via
Popen() is retuned as byte strings and byte strings are not equivalent
to strings, i.e., b'' == '' is False.
Update all call sites for Popen() to include "text=True"
argument - this ensures that the process output is returned as a
string.
Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
---
v1 -> v2:
* Update Popen() calls to return strings for process output
---
rteval/sysinfo/services.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/rteval/sysinfo/services.py b/rteval/sysinfo/services.py
index 06ff5ae9cd0c..283109b9b234 100644
--- a/rteval/sysinfo/services.py
+++ b/rteval/sysinfo/services.py
@@ -62,11 +62,11 @@ class SystemServices:
if not [1 for p in reject if fnmatch.fnmatch(servicename, p)] \
and os.access(service, os.X_OK):
cmd = '%s -qs "\(^\|\W\)status)" %s' % (getcmdpath('grep'), service)
- c = subprocess.Popen(cmd, shell=True)
+ c = subprocess.Popen(cmd, shell=True, text=True)
c.wait()
if c.returncode == 0:
cmd = ['env', '-i', 'LANG="%s"' % os.environ['LANG'], 'PATH="%s"' % os.environ['PATH'], 'TERM="%s"' % os.environ['TERM'], service, 'status']
- c = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ c = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
c.wait()
if c.returncode == 0 and (c.stdout.read() or c.stderr.read()):
ret_services[servicename] = 'running'
@@ -81,9 +81,9 @@ class SystemServices:
ret_services = {}
cmd = '%s list-unit-files -t service --no-legend' % getcmdpath('systemctl')
self.__log(Log.DEBUG, "cmd: %s" % cmd)
- c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
for p in c.stdout:
- # p are lines like "servicename.service status"
+ # p are lines like b'servicename.service status'
v = p.strip().split()
ret_services[v[0].split('.')[0]] = v[1]
return ret_services
@@ -91,7 +91,7 @@ class SystemServices:
def services_get(self):
cmd = [getcmdpath('ps'), '-ocomm=', '1']
- c = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ c = subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True)
self.__init = c.stdout.read().strip()
if self.__init == 'systemd':
self.__log(Log.DEBUG, "Using systemd to get services status")
--
2.32.0
next prev parent reply other threads:[~2021-09-13 8:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 8:05 [PATCH 0/2] rteval: Miscellaneous fixes Punit Agrawal
2021-09-09 8:05 ` [PATCH 1/2] rteval: osinfo.py: Fix RT kernel detection Punit Agrawal
2021-09-10 16:30 ` John Kacur
2021-09-09 8:05 ` [PATCH 2/2] rteval: services.py: Fix incorrect detection of container environment Punit Agrawal
2021-09-12 14:59 ` John Kacur
2021-09-13 7:47 ` Punit Agrawal
2021-09-13 8:06 ` Punit Agrawal [this message]
2021-09-13 13:33 ` [PATCH v2] " John Kacur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210913080625.2017964-1-punitagrawal@gmail.com \
--to=punitagrawal@gmail.com \
--cc=jkacur@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=punit1.agrawal@toshiba.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox