diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-03-14 23:26:37 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-03-16 10:55:12 +0100 |
commit | 12af7016e23e7b7f507dc99a1b73e64d0bb5ccf3 (patch) | |
tree | 1a62ca6d82a3ab67784442c3115b215b898ab17c /src/nvim/api/vim.c | |
parent | dbad797edd4636f830abd7ade1138a1a27ac30d2 (diff) | |
download | rneovim-12af7016e23e7b7f507dc99a1b73e64d0bb5ccf3.tar.gz rneovim-12af7016e23e7b7f507dc99a1b73e64d0bb5ccf3.tar.bz2 rneovim-12af7016e23e7b7f507dc99a1b73e64d0bb5ccf3.zip |
nvim_get_proc_children: fallback to shell
/proc/…/children may be unavailable because of an unset kernel option.
Fallback to `pgrep` invoked in a shell.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 850f892c18..9f1f395c28 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1482,7 +1482,7 @@ Array nvim_list_uis(void) /// Gets the immediate children of process `pid`. /// -/// @return Array of child process ids, or empty array if process not found. +/// @return Array of child process ids. Empty array if process not found. Array nvim_get_proc_children(Integer pid, Error *err) FUNC_API_SINCE(4) { @@ -1490,17 +1490,27 @@ Array nvim_get_proc_children(Integer pid, Error *err) int *proc_list = NULL; if (pid <= 0 || pid > INT_MAX) { - api_set_error(err, kErrorTypeException, "Invalid pid: %d", pid); + api_set_error(err, kErrorTypeException, "Invalid pid: %" PRId64, 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); + if (rv != 0) { + // syscall failed (possibly because of kernel options), try shelling out. + Array a = ARRAY_DICT_INIT; + ADD(a, INTEGER_OBJ(pid)); + String s = cstr_to_string("return vim._os_proc_children(select(1, ...))"); + Object o = nvim_execute_lua(s, a, err); + api_free_string(s); + api_free_array(a); + if (o.type == kObjectTypeArray) { + proc_array = o.data.array; + } else if (!ERROR_SET(err)) { + api_set_error(err, kErrorTypeException, + "Failed to get process children. pid=%" PRId64 " error=%d", + pid, rv); + } goto end; } |