aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2021-03-08 11:17:03 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2021-03-08 17:32:50 +0100
commitb6960925c6d4917362e1631b1ffe4a5a76c67099 (patch)
tree1496f9d16d3060fc73ba80f0757d3b0c5ce887cb
parentac56a4d04e8e32c84cf67b65cc47c5325e036f12 (diff)
downloadvis-lspc-b6960925c6d4917362e1631b1ffe4a5a76c67099.tar.gz
vis-lspc-b6960925c6d4917362e1631b1ffe4a5a76c67099.zip
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.
-rw-r--r--init.lua22
1 files changed, 19 insertions, 3 deletions
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