linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: Punit Agrawal <punitagrawal@gmail.com>
Cc: linux-rt-users@vger.kernel.org,
	Punit Agrawal <punit1.agrawal@toshiba.co.jp>
Subject: Re: [PATCH v2] rteval: services.py: Fix incorrect detection of container environment
Date: Mon, 13 Sep 2021 09:33:20 -0400 (EDT)	[thread overview]
Message-ID: <6f4a1723-8084-537-9362-53c6d32d57a1@redhat.com> (raw)
In-Reply-To: <20210913080625.2017964-1-punitagrawal@gmail.com>



On Mon, 13 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 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
> 
> 

Signed-off-by: John Kacur <jkacur@redhat.com>


      reply	other threads:[~2021-09-13 13:35 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     ` [PATCH v2] " Punit Agrawal
2021-09-13 13:33       ` John Kacur [this message]

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=6f4a1723-8084-537-9362-53c6d32d57a1@redhat.com \
    --to=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=punit1.agrawal@toshiba.co.jp \
    --cc=punitagrawal@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).