From: Punit Agrawal <punitagrawal@gmail.com>
To: John Kacur <jkacur@redhat.com>
Cc: linux-rt-users@vger.kernel.org, punit1.agrawal@toshiba.co.jp
Subject: Re: [PATCH 2/2] rteval: services.py: Fix incorrect detection of container environment
Date: Mon, 13 Sep 2021 16:47:19 +0900 [thread overview]
Message-ID: <87y2809at4.fsf@stealth> (raw)
In-Reply-To: <d18a85b5-d591-a21b-c7fc-93655f7963c@redhat.com> (John Kacur's message of "Sun, 12 Sep 2021 10:59:34 -0400 (EDT)")
John Kacur <jkacur@redhat.com> writes:
> On Thu, 9 Sep 2021, Punit Agrawal wrote:
>
>> 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 byte strings are not equivalent to strings, i.e., b'' == ''
>> is False. The string comparison functions in services.py are still
>> relying on the old behaviour in python2 where they were equivalent.
>>
>> Update the byte string processing by converting them to string.
>>
>> Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
>> ---
>> rteval/sysinfo/services.py | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/rteval/sysinfo/services.py b/rteval/sysinfo/services.py
>> index 06ff5ae9cd0c..94857aea6be4 100644
>> --- a/rteval/sysinfo/services.py
>> +++ b/rteval/sysinfo/services.py
>> @@ -83,8 +83,8 @@ class SystemServices:
>> self.__log(Log.DEBUG, "cmd: %s" % cmd)
>> c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>> for p in c.stdout:
>> - # p are lines like "servicename.service status"
>> - v = p.strip().split()
>> + # p are lines like b'servicename.service status'
>> + v = p.decode().strip().split()
>> ret_services[v[0].split('.')[0]] = v[1]
>> return ret_services
>>
>> @@ -92,7 +92,7 @@ class SystemServices:
>> def services_get(self):
>> cmd = [getcmdpath('ps'), '-ocomm=', '1']
>> c = subprocess.Popen(cmd, stdout=subprocess.PIPE)
>> - self.__init = c.stdout.read().strip()
>> + self.__init = c.stdout.read().decode().strip()
>> if self.__init == 'systemd':
>> self.__log(Log.DEBUG, "Using systemd to get services status")
>> return self.__get_services_systemd()
>> --
>> 2.32.0
>>
>>
>
> Thanks, this looks good, I'm wondering however if the same result could be
> achieved by appending text=True to the subprocess command in each of those
> methods? Would you like to test that and send me a new patch?
Thanks for the suggestion - I missed the "text=True" in the Popen() when
going through the documentation.
I will send a new version converting all Popen() sites in the file.
[...]
next prev parent reply other threads:[~2021-09-13 7:47 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 [this message]
2021-09-13 8:06 ` [PATCH v2] " Punit Agrawal
2021-09-13 13:33 ` 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=87y2809at4.fsf@stealth \
--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