~mil/sxmo-devel

sxmo-utils: sxmo_wakelock.sh: add a run mode to lock and unlock afterward a command v1 APPLIED

Willow Barraco: 1
 sxmo_wakelock.sh: add a run mode to lock and unlock afterward a command

 2 files changed, 26 insertions(+), 13 deletions(-)
#1214382 test.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/51661/mbox | git am -3
Learn more about email & git

[PATCH sxmo-utils] sxmo_wakelock.sh: add a run mode to lock and unlock afterward a command Export this patch

This also remove the automatic lock from the sxmo_rtcwake.sh script. The
user now have to use this cron line to do the same thing:

* * * * * sxmo_rtcwake.sh sxmo_wakelock.sh run sleep 10

This separate both behaviors, and allow more combinations.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
---
 scripts/core/sxmo_rtcwake.sh  | 13 +------------
 scripts/core/sxmo_wakelock.sh | 26 +++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/scripts/core/sxmo_rtcwake.sh b/scripts/core/sxmo_rtcwake.sh
index 5a91f40a..4eff917a 100755
--- a/scripts/core/sxmo_rtcwake.sh
+++ b/scripts/core/sxmo_rtcwake.sh
@@ -7,16 +7,5 @@

. sxmo_common.sh

# We can have multiple cronjobs at the same time
sxmo_wakelock.sh lock sxmo_executing_cronjob_$$ infinite
sxmo_wakelock.sh unlock sxmo_waiting_cronjob

finish() {
	sxmo_wakelock.sh unlock sxmo_executing_cronjob_$$
	exit 0
}

trap 'finish' TERM INT EXIT

sxmo_log "Running $*"
"$@"
exec "$@"
diff --git a/scripts/core/sxmo_wakelock.sh b/scripts/core/sxmo_wakelock.sh
index 26064992..ed1552eb 100644
--- a/scripts/core/sxmo_wakelock.sh
+++ b/scripts/core/sxmo_wakelock.sh
@@ -11,6 +11,7 @@ Usage: $(basename "$0") ACTION
	isenabled
	lock <lock-name> <duration|nanosec|infinite>
	unlock <lock-name>
	run <cmd...>
duration: <value><unit>
value: integer
unit: ms|s|mn|h (milisec, sec, minute, hour)
@@ -39,7 +40,6 @@ lock() {
		infinite)
			sxmo_debug "lock $1 infinite"
			echo "$1" | doas tee -a /sys/power/wake_lock > /dev/null
			exit
			;;
		*ms)
			_validint "${2%ms}"
@@ -88,6 +88,30 @@ case "$cmd" in
	isenabled) isenabled "$@";;
	lock) lock "$@";;
	unlock) unlock "$@";;
	run)
		finish() {
			if [ -n "$cmdpid" ]; then
				kill "$cmdpid" 2> /dev/null
			fi
			unlock "sxmo_wakelock_$$"
			exit
	}

		if isenabled; then
			lock "sxmo_wakelock_$$" infinite
			trap finish INT TERM EXIT
		else
			cat <<-EOF >&2
				Warning: we can't wakelock, we can't make sure no suspension will occurs...
			EOF
		fi

		"$@" &
		cmdpid=$!
		wait "$cmdpid"

		unset cmdpid
		;;
	*)
		sxmo_log "warning: sxmo_wakelock.sh $*"
		usage; exit 1;;
-- 
2.45.0
sxmo-utils/patches/test.yml: SUCCESS in 23s

[sxmo_wakelock.sh: add a run mode to lock and unlock afterward a command][0] from [Willow Barraco][1]

[0]: https://lists.sr.ht/~mil/sxmo-devel/patches/51661
[1]: mailto:contact@willowbarraco.fr

✓ #1214382 SUCCESS sxmo-utils/patches/test.yml https://builds.sr.ht/~mil/job/1214382
Marked as applied!