diff options
author | Denton Liu | 2020-12-31 14:00:42 -0800 |
---|---|---|
committer | Denton Liu | 2020-12-31 14:00:42 -0800 |
commit | 1304c0e70de9e99b4b129b015b62ca4f562e94a2 (patch) | |
tree | 514df6e710c7726cf65c18c2208b980e0e8c5a5c /crewlink-launcher | |
parent | 0c5ea71c389de4eca6d7c772ee67aaae35191d9e (diff) | |
download | aur-1304c0e70de9e99b4b129b015b62ca4f562e94a2.tar.gz |
Update to v1.2.1
* Rename crewlink to crewlink-launcher in case someone wants to run
vanilla crewlink.
* Install /usr/bin/crewlink as a link to /opt/CrewLink/crewlink.
* Modify launcher script to run a child process which sets
kernel.yama.ptrace_scope. This removes the craziness of running
crewlink with su so environment variables that are needed for
PulseAudio should be handled more transparently.
Diffstat (limited to 'crewlink-launcher')
-rwxr-xr-x | crewlink-launcher | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/crewlink-launcher b/crewlink-launcher new file mode 100755 index 000000000000..56d4b35dae1b --- /dev/null +++ b/crewlink-launcher @@ -0,0 +1,73 @@ +#!/bin/sh + +error () { + echo "$1" >&2 + exit 1 +} + +process_tree () { + children=$(cat /proc/"$1"/task/*/children) + echo "$1" + for p in $children + do + process_tree "$p" + done +} + +set_sysctl () { + pid="$1" + if test -z "$pid" + then + error "no pid given" + fi + + key='kernel.yama.ptrace_scope' + old_value=$(sysctl -n "$key") + + sysctl "$key=0" || error "unable to run 'sysctl $key=0'" + trap 'sysctl "$key=$old_value"' EXIT + trap 'exit' INT + + while kill -s 0 "$pid" >/dev/null 2>&1 + do + sleep 1 + done +} + +while test "$#" -gt 0 +do + case "$1" in + --set-sysctl) + set_sysctl "$2" + shift + exit 0 + ;; + *) + error "unknown option: $1" + ;; + esac + shift +done + +sudo -b "$0" --set-sysctl "$$" >/dev/null +crewlink & + +cl_pid="$!" +max_procs=0 + +# This is a dirty, dirty hack. This is required because closing the window +# doesn't result in the process tree dying. Some zygote processes are left +# behind. Instead of letting crewlink clean up after itself, detect when some +# processes have died and just kill off the rest. +while true +do + sleep 1 + cur_procs=$(process_tree "$cl_pid" | wc -l) + if test "$(( max_procs - 1 > cur_procs ))" = 1 + then + break + fi + max_procs="$cur_procs" +done +kill "$cl_pid" +wait |