Skip to content

Commit

Permalink
socat wrapper: exit when apk process is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaEsmukov committed Feb 19, 2017
1 parent 8ffb3e4 commit 578207b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions hooks/socat
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ get_vpnservice_configuration_server() {
}

run_apk() {
is_vpnservice_not_running && failexit "process is not running. Launch the SocatVpnActivity and retry."

# todo capture exit code of a subshell
get_vpnservice_configuration

Expand All @@ -126,9 +128,10 @@ run_apk() {

trap "stop_vpnservice" SIGINT SIGTERM

# wait forever until a kill signal is received
while :; do
# todo detect service failures
is_vpnservice_not_running && failexit "process has stopped"

# wait forever until a kill signal is received
sleep 10 &
wait
done
Expand All @@ -143,6 +146,20 @@ stop_vpnservice() {
exit $?
}

is_vpnservice_not_running() {
# todo find a more reliable way to detect whether the service is running

# - `service list` / `service check` - works with system services only
# - `dumpsys activity services` - requires root or additional user permission

# If the process is absent, when both VpnService and BroadcastsListenerService
# are definitely not running.
# But is the process is present, they _might_ be running. But not certainly are.

pidof ru.esmukov.kpfu.lightningrodandroidvpnpoc > /dev/null
[ $? -ne 0 ] # negate error code
}


# todo [ "" != "$@" ] causes
# [: -d: unexpected operator/operand
Expand Down

0 comments on commit 578207b

Please sign in to comment.