From: John Wolfe Date: Fri, 29 Jul 2022 03:03:42 +0000 (-0700) Subject: Changes to common source files not directly applicable to open-vm-tools. X-Git-Tag: stable-12.1.0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6907610abb95f96c3e8a10389483bfe54efd3eee;p=thirdparty%2Fopen-vm-tools.git Changes to common source files not directly applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/include/hostinfo.h b/open-vm-tools/lib/include/hostinfo.h index 4373c2222..77a6d9742 100644 --- a/open-vm-tools/lib/include/hostinfo.h +++ b/open-vm-tools/lib/include/hostinfo.h @@ -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. */ diff --git a/open-vm-tools/lib/include/log.h b/open-vm-tools/lib/include/log.h index 0c533590e..21e9e7b75 100644 --- a/open-vm-tools/lib/include/log.h +++ b/open-vm-tools/lib/include/log.h @@ -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, diff --git a/open-vm-tools/lib/misc/hostinfo.c b/open-vm-tools/lib/misc/hostinfo.c index 352ee74aa..c0fe3fd2f 100644 --- a/open-vm-tools/lib/misc/hostinfo.c +++ b/open-vm-tools/lib/misc/hostinfo.c @@ -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; +} + diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index c06759341..d785d9228 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -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; } +