From b6960925c6d4917362e1631b1ffe4a5a76c67099 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 8 Mar 2021 11:17:03 +0100 Subject: introduce a fallback to get our pid if /proc/self/stat is not available Obviously not all vis users are running Linux therefore vis-lspc uses sh -c "echo $PPID" as fallback if /proc/self/stat is not available. --- init.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 145d21e..02c030a 100644 --- a/init.lua +++ b/init.lua @@ -33,9 +33,25 @@ else end -- get vis's pid to pass it to the language servers -local vis_proc_file = assert(io.open('/proc/self/stat', 'r')) -local vis_pid = vis_proc_file:read('*n') -vis_proc_file:close() +local vis_pid +do + local vis_proc_file = io.open('/proc/self/stat', 'r') + if vis_proc_file then + vis_pid = vis_proc_file:read('*n') + vis_proc_file:close() + + else -- fallback if /proc/self/stat + local p = io.popen('sh -c "echo $PPID"') + local out = p:read('*a') + local success, _, status = p:close() + + if not success then + lspc_err('sh failed with exit code: ' .. status) + end + vis_pid = tonumber(out) + end +end +assert(vis_pid) -- forward declaration of our client table local lspc -- cgit v1.2.3