]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix the command name for few linux processes.
authorOliver Kurth <okurth@vmware.com>
Wed, 3 Jul 2019 21:28:56 +0000 (14:28 -0700)
committerOliver Kurth <okurth@vmware.com>
Wed, 3 Jul 2019 21:28:56 +0000 (14:28 -0700)
ProcMgr library publishes the 'command name' attribute for
each process while listing down all the processes.  For doing this,
the commandline is first parsed from /proc/<PID>/cmdline file
and the part starting from the right-most '/' is considered as the
command name.  This is OK only if we have an absolute path for the
command binary.  Other wise, this may result in incorrect results.

For example:
sshd: root@pts/1
gdm-session-worker [pam/gdm-autologin]

Fixed the code to ignore the parsing if we do not have an absolute
path.

Note: There are two ways how the command name is retrieved for each
process.

1. /proc/<PID>/cmdline is parsed.

If (1) fails for some reason, then

2. /proc/<PID>/status is parsed.

There is no issue with (2). This changeset fixes the parsing issue only
with (1) approach mentioned above.

open-vm-tools/lib/procMgr/procMgrPosix.c

index 2f7711bdbdc02bc50882eb59a315fc2a24a28623..e38a6dbf60fbadce268928e4d6c0801d9cf6f249 100644 (file)
@@ -340,7 +340,6 @@ ProcMgr_ListProcesses(void)
       unsigned long long dummy;
       unsigned long long relativeStartTime;
       char *stringBegin;
-      char *cmdNameBegin;
       Bool cmdNameLookup = TRUE;
 
       /*
@@ -410,15 +409,22 @@ ProcMgr_ListProcesses(void)
                    * Store the command name.
                    * Find the last path separator, to get the cmd name.
                    * If no separator is found, then use the whole name.
+                   * This needs to be done only if there is an absolute
+                   * path for the binary. Else, the parsing may result
+                   * in incorrect results. Following are few examples:
+                   *
+                   *   sshd: root@pts/1
+                   *   gdm-session-worker [pam/gdm-autologin]
+                   *
                    */
-                  cmdNameBegin = strrchr(cmdLineTemp, '/');
-                  if (NULL == cmdNameBegin) {
-                     cmdNameBegin = cmdLineTemp;
-                  } else {
+                  char *cmdNameBegin = strrchr(cmdLineTemp, '/');
+                  if (NULL != cmdNameBegin && cmdLineTemp[0] == '/') {
                      /*
                       * Skip over the last separator.
                       */
                      cmdNameBegin++;
+                  } else {
+                     cmdNameBegin = cmdLineTemp;
                   }
                   procInfo.procCmdName = Unicode_Alloc(cmdNameBegin, STRING_ENCODING_DEFAULT);
                   if (procInfo.procCmdAbsPath != NULL &&