API: nvim_get_proc_children()

ref https://github.com/libuv/libuv/pull/836
This commit is contained in:
Justin M. Keyes
2018-03-11 21:47:12 +01:00
parent de86f82483
commit dbad797edd
4 changed files with 188 additions and 4 deletions

View File

@@ -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;
}