Ack. Interdiff is:
diff --git a/lib/utils/process.py b/lib/utils/process.py
index d5760af..268ff54 100644
--- a/lib/utils/process.py
+++ b/lib/utils/process.py
@@ -761,11 +761,11 @@ def _GetProcStatusPath(pid):
def GetProcCmdline(pid):
- """Returns the command line of a pid.
+ """Returns the command line of a pid as a list of arguments.
@type pid: int
@param pid: Process ID
- @rtype: string
+ @rtype: list of string
@raise EnvironmentError: If the process does not exist
@@ -773,9 +773,9 @@ def GetProcCmdline(pid):
proc_path = "/proc/%d/cmdline" % pid
with open(proc_path, 'r') as f:
nulled_cmdline = f.read()
- # Spaces are replaced with nul chars in the command line - let's turn
them
- # back
- return nulled_cmdline.replace('\x00', ' ')
+ # Individual arguments are separated by nul chars in the contents of the
proc
+ # file
+ return nulled_cmdline.split('\x00')
def IsProcessAlive(pid):
diff --git a/test/py/ganeti.utils.process_unittest.py b/test/py/
ganeti.utils.process_unittest.py
index a889a09..5b2107f 100755
--- a/test/py/ganeti.utils.process_unittest.py
+++ b/test/py/ganeti.utils.process_unittest.py
@@ -748,8 +748,8 @@ class GetCmdline(unittest.TestCase):
sample_cmd = "sleep 2; true"
pid = subprocess.Popen(sample_cmd, shell=True).pid
cmdline = utils.GetProcCmdline(pid)
- # Due to the shell prefix which could vary amongst test environments,
the
- # best we can do barring painful parsing is check for substrings
+ # As the popen will quote and pass on the sample_cmd, it should be
returned
+ # by the function as an element in the list of arguments
self.assertTrue(sample_cmd in cmdline)
On Thu, Jun 11, 2015 at 1:51 PM, Klaus Aehlig <[email protected]> wrote:
> > + proc_path = "/proc/%d/cmdline" % pid
> > + with open(proc_path, 'r') as f:
> > + nulled_cmdline = f.read()
> > + # Spaces are replaced with nul chars in the command line - let's turn
> them
> > + # back
> > + return nulled_cmdline.replace('\x00', ' ')
>
> I don't think that spaces are replaced by 0 characters; instead the
> individual
> arguments are concatenated with 0 characters as separators. This is not
> the same,
> as command-line arguments may contain spaces.
>
> --
> Klaus Aehlig
> Google Germany GmbH, Dienerstr. 12, 80331 Muenchen
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores
>
Hrvoje Ribicic
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg