aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/os/process.c')
-rw-r--r--src/nvim/os/process.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c
index e70bc71961..f4d95e141b 100644
--- a/src/nvim/os/process.c
+++ b/src/nvim/os/process.c
@@ -6,10 +6,21 @@
/// psutil is a good reference for cross-platform syscall voodoo:
/// https://github.com/giampaolo/psutil/tree/master/psutil/arch
-#include <uv.h> // for HANDLE (win32)
+#include <assert.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <uv.h>
-#ifdef WIN32
-# include <tlhelp32.h> // for CreateToolhelp32Snapshot
+#include "nvim/log.h"
+#include "nvim/memory.h"
+#include "nvim/os/process.h"
+
+#ifdef MSWIN
+# include <tlhelp32.h>
+
+# include "nvim/api/private/helpers.h"
#endif
#if defined(__FreeBSD__) // XXX: OpenBSD ?
@@ -27,18 +38,11 @@
# include <sys/sysctl.h>
#endif
-#include "nvim/api/private/helpers.h"
-#include "nvim/globals.h"
-#include "nvim/log.h"
-#include "nvim/os/os.h"
-#include "nvim/os/os_defs.h"
-#include "nvim/os/process.h"
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "os/process.c.generated.h"
+# include "os/process.c.generated.h" // IWYU pragma: export
#endif
-#ifdef WIN32
+#ifdef MSWIN
static bool os_proc_tree_kill_rec(HANDLE process, int sig)
{
if (process == NULL) {
@@ -114,7 +118,7 @@ int os_proc_children(int ppid, int **proc_list, size_t *proc_count)
*proc_list = NULL;
*proc_count = 0;
-#ifdef WIN32
+#ifdef MSWIN
PROCESSENTRY32 pe;
// Snapshot of all processes.
@@ -215,7 +219,7 @@ int os_proc_children(int ppid, int **proc_list, size_t *proc_count)
return 0;
}
-#ifdef WIN32
+#ifdef MSWIN
/// Gets various properties of the process identified by `pid`.
///
/// @param pid Process to inspect.
@@ -260,5 +264,16 @@ Dictionary os_proc_info(int pid)
/// Return true if process `pid` is running.
bool os_proc_running(int pid)
{
- return uv_kill(pid, 0) == 0;
+ int err = uv_kill(pid, 0);
+ // If there is no error the process must be running.
+ if (err == 0) {
+ return true;
+ }
+ // If the error is ESRCH then the process is not running.
+ if (err == UV_ESRCH) {
+ return false;
+ }
+ // If the process is running and owned by another user we get EPERM. With
+ // other errors the process might be running, assuming it is then.
+ return true;
}