diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-03-11 21:47:12 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-03-16 10:55:12 +0100 |
commit | dbad797edd4636f830abd7ade1138a1a27ac30d2 (patch) | |
tree | 9fbad52284a75fdba28fc4da40da9b1560f4099c /src/nvim/api/vim.c | |
parent | de86f824835b1556cc0070dd5720cdae484a0296 (diff) | |
download | rneovim-dbad797edd4636f830abd7ade1138a1a27ac30d2.tar.gz rneovim-dbad797edd4636f830abd7ade1138a1a27ac30d2.tar.bz2 rneovim-dbad797edd4636f830abd7ade1138a1a27ac30d2.zip |
API: nvim_get_proc_children()
ref https://github.com/libuv/libuv/pull/836
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index dad67c5e4b..850f892c18 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -33,6 +33,7 @@ #include "nvim/syntax.h" #include "nvim/getchar.h" #include "nvim/os/input.h" +#include "nvim/os/process.h" #include "nvim/viml/parser/expressions.h" #include "nvim/viml/parser/parser.h" #include "nvim/ui.h" @@ -1478,3 +1479,36 @@ Array nvim_list_uis(void) { return ui_array(); } + +/// Gets the immediate children of process `pid`. +/// +/// @return Array of child process ids, or empty array if process not found. +Array nvim_get_proc_children(Integer pid, Error *err) + FUNC_API_SINCE(4) +{ + Array proc_array = ARRAY_DICT_INIT; + int *proc_list = NULL; + + if (pid <= 0 || pid > INT_MAX) { + api_set_error(err, kErrorTypeException, "Invalid pid: %d", pid); + goto end; + } + + size_t proc_count; + int rv = os_proc_children((int)pid, &proc_list, &proc_count); + if (rv == 1) { + goto end; // Process not found; return empty list. + } else if (rv != 0) { + api_set_error(err, kErrorTypeException, + "Failed to get process children. pid=%d error=%d", pid, rv); + goto end; + } + + for (size_t i = 0; i < proc_count; i++) { + ADD(proc_array, INTEGER_OBJ(proc_list[i])); + } + +end: + xfree(proc_list); + return proc_array; +} |