/*********************************************************
- * Copyright (C) 2002-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2002-2019 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
typedef struct ProcMgrProcInfo {
ProcMgr_Pid procId;
char *procCmdName; // UTF-8
+#if defined(__linux__) || defined(_WIN32)
+ char *procCmdAbsPath; // UTF-8
+#endif
char *procCmdLine; // UTF-8
char *procOwner; // UTF-8
#if defined(_WIN32)
#endif
ProcMgrProcInfoArray *ProcMgr_ListProcesses(void);
+
+#if defined(_WIN32)
+ProcMgrProcInfoArray *ProcMgr_ListProcessesEx(void);
+#endif
+
void ProcMgr_FreeProcList(ProcMgrProcInfoArray *procList);
Bool ProcMgr_KillByPid(ProcMgr_Pid procId);
procList = Util_SafeCalloc(1, sizeof *procList);
ProcMgrProcInfoArray_Init(procList, 0);
procInfo.procCmdName = NULL;
+ procInfo.procCmdAbsPath = NULL;
procInfo.procCmdLine = NULL;
procInfo.procOwner = NULL;
continue;
}
+ if (snprintf(cmdFilePath,
+ sizeof cmdFilePath,
+ "/proc/%s/exe",
+ ent->d_name) != -1) {
+ int exeLen;
+ char exeRealPath[1024];
+
+ exeLen = readlink(cmdFilePath, exeRealPath, sizeof exeRealPath -1);
+ if (exeLen != -1) {
+ exeRealPath[exeLen] = '\0';
+ procInfo.procCmdAbsPath =
+ Unicode_Alloc(exeRealPath, STRING_ENCODING_DEFAULT);
+ }
+ }
+
if (numRead > 0) {
for (replaceLoop = 0 ; replaceLoop < numRead ; replaceLoop++) {
if ('\0' == cmdLineTemp[replaceLoop]) {
cmdNameBegin++;
}
procInfo.procCmdName = Unicode_Alloc(cmdNameBegin, STRING_ENCODING_DEFAULT);
+ if (procInfo.procCmdAbsPath != NULL &&
+ cmdLineTemp[0] == '/') {
+ procInfo.procCmdAbsPath =
+ Unicode_Alloc(cmdLineTemp, STRING_ENCODING_DEFAULT);
+ }
cmdNameLookup = FALSE;
}
* Store the command name.
*/
procInfo.procCmdName = Unicode_Alloc(cmdLineTemp, STRING_ENCODING_DEFAULT);
+ if (procInfo.procCmdAbsPath != NULL &&
+ cmdLineTemp[0] == '/') {
+ procInfo.procCmdAbsPath = Unicode_Alloc(cmdLineTemp, STRING_ENCODING_DEFAULT);
+ }
}
}
* Store the command line string pointer in dynbuf.
*/
if (cmdLineTemp) {
+ int i;
+
+ /*
+ * Chop off the trailing whitespace characters.
+ */
+ for (i = strlen(cmdLineTemp) - 1 ;
+ i >= 0 && cmdLineTemp[i] == ' ' ;
+ i--) {
+ cmdLineTemp[i] = '\0';
+ }
+
procInfo.procCmdLine = Unicode_Alloc(cmdLineTemp, STRING_ENCODING_DEFAULT);
} else {
procInfo.procCmdLine = Unicode_Alloc("", STRING_ENCODING_UTF8);
if (!ProcMgrProcInfoArray_Push(procList, procInfo)) {
Warning("%s: failed to expand DynArray - out of memory\n",
__FUNCTION__);
+ free(cmdLineTemp);
+ free(cmdStatTemp);
goto abort;
}
procInfo.procCmdName = NULL;
+ procInfo.procCmdAbsPath = NULL;
procInfo.procCmdLine = NULL;
procInfo.procOwner = NULL;
next_entry:
+ free(procInfo.procCmdName);
+ procInfo.procCmdName = NULL;
+ free(procInfo.procCmdAbsPath);
+ procInfo.procCmdAbsPath = NULL;
+
free(cmdLineTemp);
free(cmdStatTemp);
} // while readdir
closedir(dir);
free(procInfo.procCmdName);
+ free(procInfo.procCmdAbsPath);
free(procInfo.procCmdLine);
free(procInfo.procOwner);
for (i = 0; i < procCount; i++) {
ProcMgrProcInfo *procInfo = ProcMgrProcInfoArray_AddressOf(procList, i);
free(procInfo->procCmdName);
+#if defined(__linux__)
+ free(procInfo->procCmdAbsPath);
+#endif
free(procInfo->procCmdLine);
free(procInfo->procOwner);
}