Files
sxmo-utils/scripts/core/sxmo_keyboard.sh
Jochen Sprickerhof ae7fd89b46 Use pkill -f for $KEYBOARD
Some pkill implementations match on /proc/pid/stat which is limited to
15 characters [1]. $KEYBOARD defaults to svkbd-mobile-intl which is more
then 15 characters, so use -f to match the full string. Note that sxmo
uses busybox pkill by default which does not have this limit.

[1] https://manpages.debian.org/buster/procps/pgrep.1.en.html (Notes)

This patch was previously applied, and then reverted by a careless
refactor, restore it.

Signed-off-by: Anjandev Momi <anjan@momi.ca>
Signed-off-by: Aren Moynihan <aren@peacevolution.org>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2023-10-03 22:06:51 +02:00

41 lines
772 B
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
isopen() {
if [ -z "$KEYBOARD" ]; then
exit 0 # ssh/tty usage by example
fi
pidof "$KEYBOARD" > /dev/null
}
open() {
if [ -n "$KEYBOARD" ]; then
#Note: KEYBOARD_ARGS is not quoted by design as it may includes a pipe and further tools
# shellcheck disable=SC2086
isopen || eval "$KEYBOARD" $KEYBOARD_ARGS &
fi
}
close() {
if [ -n "$KEYBOARD" ]; then # avoid killing everything !
pkill -f "$KEYBOARD"
fi
}
if [ "$1" = "toggle" ]; then
close || open
elif [ "$1" = "close" ]; then
if isopen; then
close
fi
elif [ "$1" = "isopen" ]; then
isopen || exit 1
else
open
fi