]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes to common source files not directly applicable to open-vm-tools.
authorJohn Wolfe <jwolfe@vmware.com>
Fri, 29 Jul 2022 03:03:42 +0000 (20:03 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Fri, 29 Jul 2022 03:03:42 +0000 (20:03 -0700)
open-vm-tools/lib/include/hostinfo.h
open-vm-tools/lib/include/log.h
open-vm-tools/lib/misc/hostinfo.c
open-vm-tools/lib/misc/hostinfoPosix.c

index 4373c22225f328ea393ef7b20edafaa1d615eb36..77a6d9742491f8cff245ccc6690e260704f29207 100644 (file)
@@ -48,6 +48,14 @@ typedef enum {
    HOSTINFO_PROCESS_QUERY_UNKNOWN  // Process existence cannot be determined
 } HostinfoProcessQuery;
 
+typedef struct HostinfoProcessSnapshot HostinfoProcessSnapshot;
+
+HostinfoProcessSnapshot *Hostinfo_AcquireProcessSnapshot(void);
+void Hostinfo_ReleaseProcessSnapshot(HostinfoProcessSnapshot *s);
+
+HostinfoProcessQuery Hostinfo_QueryProcessSnapshot(HostinfoProcessSnapshot *s,
+                                                   int pid);
+
 HostinfoProcessQuery Hostinfo_QueryProcessExistence(int pid);
 
 /* This macro defines the current version of the structured header. */
index 0c533590e1b18dade0816159cc0301864d035d97..21e9e7b7540834e82f370df5fa6a550d5a2052fa 100644 (file)
@@ -612,7 +612,8 @@ Log_MakeTimeString(Bool millisec,
                    size_t max);
 
 typedef Bool (LogMayDeleteFunc)(void *userData,
-                                const char *fileName);
+                                const char *fileName,
+                                uint32 *pid);
 
 Bool
 Log_BoundNumFiles(const LogOutput *output,
index 352ee74aa9a41fe8088785532ca900b55f216957..c0fe3fd2fb742190a7b4978b0faa86ce9969e2ad 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2022 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
@@ -335,3 +335,41 @@ Hostinfo_GetOSDetailedData(void)
 
    return detailedData;
 }
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Hostinfo_QueryProcessExistence --
+ *
+ *      Determine if a PID is "alive" or "dead". Failing to be able to
+ *      do this perfectly, do not make any assumption - say the answer
+ *      is unknown.
+ *
+ * Results:
+ *      HOSTINFO_PROCESS_QUERY_ALIVE    Process is alive
+ *      HOSTINFO_PROCESS_QUERY_DEAD     Process is dead
+ *      HOSTINFO_PROCESS_QUERY_UNKNOWN  Don't know
+ *
+ * Side effects:
+ *      None
+ *
+ *----------------------------------------------------------------------
+ */
+
+HostinfoProcessQuery
+Hostinfo_QueryProcessExistence(int pid)  // IN:
+{
+   HostinfoProcessQuery ret;
+   HostinfoProcessSnapshot *s = Hostinfo_AcquireProcessSnapshot();
+
+   if (s == NULL) {
+      return HOSTINFO_PROCESS_QUERY_UNKNOWN;
+   }
+
+   ret = Hostinfo_QueryProcessSnapshot(s, pid);
+
+   Hostinfo_ReleaseProcessSnapshot(s);
+
+   return ret;
+}
+
index c0675934119eb1d7df57c1b4f1ebdd9b8ac404c5..d785d9228431cd2156a4d6ecf462c360e8b120a3 100644 (file)
@@ -4396,11 +4396,67 @@ Hostinfo_GetLibraryPath(void *addr)  // IN
 /*
  *----------------------------------------------------------------------
  *
- * Hostinfo_QueryProcessExistence --
+ * Hostinfo_AcquireProcessSnapshot --
  *
- *      Determine if a PID is "alive" or "dead". Failing to be able to
- *      do this perfectly, do not make any assumption - say the answer
- *      is unknown.
+ *      Acquire a snapshot of the process table. On POSIXen, this is
+ *      a NOP.
+ *
+ * Results:
+ *      !NULL - A process snapshot pointer.
+ *
+ * Side effects:
+ *      None
+ *
+ *----------------------------------------------------------------------
+ */
+
+struct HostinfoProcessSnapshot {
+   int dummy;
+};
+
+static HostinfoProcessSnapshot hostinfoProcessSnapshot = { 0 };
+
+HostinfoProcessSnapshot *
+Hostinfo_AcquireProcessSnapshot(void)
+{
+   return &hostinfoProcessSnapshot;
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Hostinfo_ReleaseProcessSnapshot --
+ *
+ *      Release a snapshot of the process table. On POSIXen, this is
+ *      a NOP.
+ *
+ * Results:
+ *      None
+ *
+ * Side effects:
+ *      None
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+Hostinfo_ReleaseProcessSnapshot(HostinfoProcessSnapshot *s)  // IN/OPT:
+{
+   if (s != NULL) {
+      VERIFY(s == &hostinfoProcessSnapshot);
+   }
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Hostinfo_QueryProcessSnapshot --
+ *
+ *      Determine if a PID is "alive" or "dead" within the specified
+ *      process snapshot. Failing to be able to do this perfectly,
+ *      do not make any assumption - say the answer is unknown.
  *
  * Results:
  *      HOSTINFO_PROCESS_QUERY_ALIVE    Process is alive
@@ -4414,12 +4470,14 @@ Hostinfo_GetLibraryPath(void *addr)  // IN
  */
 
 HostinfoProcessQuery
-Hostinfo_QueryProcessExistence(int pid)  // IN:
+Hostinfo_QueryProcessSnapshot(HostinfoProcessSnapshot *s,  // IN:
+                              int pid)                     // IN:
 {
    HostinfoProcessQuery ret;
-   int err = (kill(pid, 0) == -1) ? errno : 0;
 
-   switch (err) {
+   ASSERT(s != NULL);
+
+   switch ((kill(pid, 0) == -1) ? errno : 0) {
    case 0:
    case EPERM:
       ret = HOSTINFO_PROCESS_QUERY_ALIVE;
@@ -4434,3 +4492,4 @@ Hostinfo_QueryProcessExistence(int pid)  // IN:
 
    return ret;
 }
+