increased verbosity in various scripts, and do not run xargs kill when argument is empty (cleaner and clearer stderr messages)

master
Maarten van Gompel 4 years ago
parent ca88d3029e
commit 1608ab1ae4
  1. 10
      programs/sxmo_screenlock.c
  2. 11
      scripts/core/sxmo_appmenu.sh
  3. 2
      scripts/core/sxmo_rotateautotoggle.sh
  4. 2
      scripts/core/sxmo_statusbar.sh
  5. 2
      scripts/core/sxmo_statusbarupdate.sh
  6. 20
      scripts/modem/sxmo_modemcall.sh
  7. 18
      scripts/modem/sxmo_modemmonitor.sh
  8. 2
      scripts/notifications/sxmo_notificationmonitor.sh

@ -180,7 +180,7 @@ configuresuspendsettingsandwakeupsources()
void void
die(const char *err, ...) die(const char *err, ...)
{ {
fprintf(stderr, "Error: %s", err); fprintf(stderr, "Screenlock error: %s\n", err);
state = StateDead; state = StateDead;
syncstate(); syncstate();
exit(1); exit(1);
@ -192,6 +192,7 @@ sigterm()
state = StateDead; state = StateDead;
syncstate(); syncstate();
if (wakeinterval) close(rtc_fd); if (wakeinterval) close(rtc_fd);
fprintf(stderr, "Screenlock terminating on signal\n");
exit(0); exit(0);
} }
@ -476,7 +477,7 @@ main(int argc, char **argv) {
wakeinterval = (time_t) atoi(argv[++i]); wakeinterval = (time_t) atoi(argv[++i]);
} else if(!strcmp(argv[i], "--setuid")) { } else if(!strcmp(argv[i], "--setuid")) {
if (setuid(0)) if (setuid(0))
die("setuid(0) failed\n"); die("setuid(0) failed");
} else { } else {
fprintf(stderr, "Invalid argument: %s\n", argv[i]); fprintf(stderr, "Invalid argument: %s\n", argv[i]);
return 2; return 2;
@ -484,10 +485,12 @@ main(int argc, char **argv) {
} }
if (!(dpy = XOpenDisplay(NULL))) if (!(dpy = XOpenDisplay(NULL)))
die("Cannot open display\n"); die("Cannot open display");
if (wakeinterval) init_rtc(); if (wakeinterval) init_rtc();
fprintf(stderr, "Screenlock starting\n");
XkbSetDetectableAutoRepeat(dpy, True, NULL); XkbSetDetectableAutoRepeat(dpy, True, NULL);
screen = XDefaultScreen(dpy); screen = XDefaultScreen(dpy);
XSync(dpy, 0); XSync(dpy, 0);
@ -507,5 +510,6 @@ main(int argc, char **argv) {
ioctl(rtc_fd, RTC_AIE_OFF, 0); ioctl(rtc_fd, RTC_AIE_OFF, 0);
close(rtc_fd); close(rtc_fd);
} }
fprintf(stderr, "Screenlock terminating normally\n");
return 0; return 0;
} }

@ -4,13 +4,18 @@ WIN=$(xdotool getwindowfocus)
NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications
gracefulexit() { gracefulexit() {
echo "Gracefully exiting $0" echo "Gracefully exiting $0">&2
kill -9 0 kill -9 0
} }
programchoicesinit() { programchoicesinit() {
XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")" XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")"
WMCLASS="${1:-$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)}" WMCLASS="${1:-$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)}"
if [ -z "$XPROPOUT" ]; then
echo "sxmo_appmenu: detected no active window, no problem, opening system menu" >&2
else
echo "sxmo_appmenu: opening menu for wmclass $WMCLASS" >&2
fi
if echo "$WMCLASS" | grep -i "scripts"; then if echo "$WMCLASS" | grep -i "scripts"; then
# Scripts menu # Scripts menu
@ -441,7 +446,7 @@ mainloop() {
LOOP="$(echo "$PROGCHOICES" | grep -m1 -F "$PICKED" | cut -d '^' -f2)" LOOP="$(echo "$PROGCHOICES" | grep -m1 -F "$PICKED" | cut -d '^' -f2)"
CMD="$(echo "$PROGCHOICES" | grep -m1 -F "$PICKED" | cut -d '^' -f3)" CMD="$(echo "$PROGCHOICES" | grep -m1 -F "$PICKED" | cut -d '^' -f3)"
DMENUIDX="$(echo "$PROGCHOICES" | grep -m1 -F -n "$PICKED" | cut -d ':' -f1)" DMENUIDX="$(echo "$PROGCHOICES" | grep -m1 -F -n "$PICKED" | cut -d ':' -f1)"
echo "Eval: <$CMD> from picked <$PICKED> with loop <$LOOP>" echo "sxmo_appmenu: Eval: <$CMD> from picked <$PICKED> with loop <$LOOP>">&2
if echo "$LOOP" | grep 1; then if echo "$LOOP" | grep 1; then
eval "$CMD" eval "$CMD"
mainloop mainloop
@ -452,7 +457,7 @@ mainloop() {
) & wait ) & wait
} }
pgrep -f "$(command -v sxmo_appmenu.sh)" | grep -Ev "^${$}$" | xargs kill -TERM pgrep -f "$(command -v sxmo_appmenu.sh)" | grep -Ev "^${$}$" | xargs -r kill -TERM
DMENUIDX=0 DMENUIDX=0
PICKED="" PICKED=""
ARGS="$*" ARGS="$*"

@ -9,7 +9,7 @@ FILE_X="$(find /sys/bus/iio/devices/iio:device*/ -iname in_accel_x_raw)"
autorotatedisable() { autorotatedisable() {
notify-send "Autorotate disabled" notify-send "Autorotate disabled"
pgrep -f "$(command -v sxmo_rotateautotoggle.sh)" | grep -Ev "^${$}$" | xargs kill -9 pgrep -f "$(command -v sxmo_rotateautotoggle.sh)" | grep -Ev "^${$}$" | xargs -r kill -9
exit 0 exit 0
} }

@ -1,6 +1,6 @@
#!/usr/bin/env sh #!/usr/bin/env sh
trap "update" USR1 trap "update" USR1
pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs kill -9 pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs -r kill -9
update() { update() {
# In-call.. show length of call # In-call.. show length of call

@ -1,2 +1,2 @@
#!/usr/bin/env sh #!/usr/bin/env sh
pgrep -f "$(command -v sxmo_statusbar.sh)" | xargs kill -USR1 & pgrep -f "$(command -v sxmo_statusbar.sh)" | xargs -r kill -USR1 &

@ -27,7 +27,7 @@ finish() {
fi fi
setsid -f sh -c 'sleep 2; sxmo_statusbarupdate.sh' setsid -f sh -c 'sleep 2; sxmo_statusbarupdate.sh'
if [ -n "$1" ]; then if [ -n "$1" ]; then
echo "$1">&2 echo "sxmo_modemcall: $1">&2
notify-send "$1" notify-send "$1"
fi fi
kill -9 0 kill -9 0
@ -43,7 +43,7 @@ gracefulexit() {
modem_cmd_errcheck() { modem_cmd_errcheck() {
RES="$(mmcli "$@" 2>&1)" RES="$(mmcli "$@" 2>&1)"
OK="$?" OK="$?"
echo "Command: mmcli $*">&2 echo "sxmo_modemcall: Command: mmcli $*">&2
if [ "$OK" != 0 ]; then finish "Problem executing mmcli command!\n$RES"; fi if [ "$OK" != 0 ]; then finish "Problem executing mmcli command!\n$RES"; fi
echo "$RES" echo "$RES"
} }
@ -86,7 +86,7 @@ toggleflagset() {
acceptcall() { acceptcall() {
CALLID="$1" CALLID="$1"
echo "Attempting to initialize CALLID $CALLID">&2 echo "sxmo_modemcall: Attempting to initialize CALLID $CALLID">&2
DIRECTION="$( DIRECTION="$(
mmcli --voice-status -o "$CALLID" -K | mmcli --voice-status -o "$CALLID" -K |
grep call.properties.direction | grep call.properties.direction |
@ -96,17 +96,17 @@ acceptcall() {
if [ "$DIRECTION" = "outgoing" ]; then if [ "$DIRECTION" = "outgoing" ]; then
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --start modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --start
log_event "call_start" "$CALLID" log_event "call_start" "$CALLID"
echo "Started call $CALLID">&2 echo "sxmo_modemcall: Started call $CALLID">&2
elif [ "$DIRECTION" = "incoming" ]; then elif [ "$DIRECTION" = "incoming" ]; then
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/pickup" ]; then if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/pickup" ]; then
echo "Invoking pickup hook (async)">&2 echo "sxmo_modemcall: Invoking pickup hook (async)">&2
"$XDG_CONFIG_HOME/sxmo/hooks/pickup" & "$XDG_CONFIG_HOME/sxmo/hooks/pickup" &
fi fi
touch "$CACHEDIR/${CALLID}.pickedupcall" #this signals that we picked this call up touch "$CACHEDIR/${CALLID}.pickedupcall" #this signals that we picked this call up
#to other asynchronously running processes #to other asynchronously running processes
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept
log_event "call_pickup" "$CALLID" log_event "call_pickup" "$CALLID"
echo "Picked up call $CALLID">&2 echo "sxmo_modemcall: Picked up call $CALLID">&2
else else
finish "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>" finish "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>"
fi fi
@ -157,13 +157,13 @@ incallmonitor() {
finish "Call with $NUMBER terminated" finish "Call with $NUMBER terminated"
fi fi
fi fi
echo "Call still in progress">&2 echo "sxmo_modemcall: Call still in progress">&2
sleep 3 sleep 3
done done
} }
incallmenuloop() { incallmenuloop() {
echo "Current flags are $FLAGS">&2 echo "sxmo_modemcall: Current flags are $FLAGS">&2
CHOICES=" CHOICES="
$([ "$WINDOWIFIED" = 0 ] && echo Windowify || echo Unwindowify) ^ togglewindowify $([ "$WINDOWIFIED" = 0 ] && echo Windowify || echo Unwindowify) ^ togglewindowify
$([ "$WINDOWIFIED" = 0 ] && echo 'Screenlock ^ togglewindowify; sxmo_screenlock &') $([ "$WINDOWIFIED" = 0 ] && echo 'Screenlock ^ togglewindowify; sxmo_screenlock &')
@ -188,11 +188,11 @@ incallmenuloop() {
dmenu -idx $DMENUIDX -l 14 "$([ "$WINDOWIFIED" = 0 ] && echo "-c" || echo "-wm")" -fn "Terminus-30" -p "$NUMBER" | dmenu -idx $DMENUIDX -l 14 "$([ "$WINDOWIFIED" = 0 ] && echo "-c" || echo "-wm")" -fn "Terminus-30" -p "$NUMBER" |
( (
PICKED="$(cat)"; PICKED="$(cat)";
echo "Picked is $PICKED">&2 echo "sxmo_modemcall: Picked is $PICKED">&2
echo "$PICKED" | grep -Ev "." echo "$PICKED" | grep -Ev "."
CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d'^' -f2) CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d'^' -f2)
DMENUIDX=$(echo "$(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1)" - 1 | bc) DMENUIDX=$(echo "$(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1)" - 1 | bc)
echo "Eval in call context: $CMD">&2 echo "sxmo_modemcall: Eval in call context: $CMD">&2
eval "$CMD" eval "$CMD"
incallmenuloop incallmenuloop
) & wait # E.g. bg & wait to allow for SIGINT propogation ) & wait # E.g. bg & wait to allow for SIGINT propogation

@ -5,13 +5,13 @@ CACHEDIR="$XDG_CACHE_HOME"/sxmo
trap "gracefulexit" INT TERM trap "gracefulexit" INT TERM
err() { err() {
echo "$1">&2 echo "sxmo_modemmonitor: Error: $1">&2
notify-send "$1" notify-send "$1"
gracefulexit gracefulexit
} }
gracefulexit() { gracefulexit() {
echo "gracefully exiting $0!">&2 echo "sxmo_modemmonitor: gracefully exiting (on signal or after error)">&2
kill -9 0 kill -9 0
} }
@ -67,13 +67,13 @@ checkforfinishedcalls() {
if [ -f "$CACHEDIR/${FINISHEDCALLID}.pickedupcall" ]; then if [ -f "$CACHEDIR/${FINISHEDCALLID}.pickedupcall" ]; then
#this call was picked up #this call was picked up
pkill -f sxmo_modemcall.sh #kill call (softly) in case it is still in progress (remote party hung up) pkill -f sxmo_modemcall.sh #kill call (softly) in case it is still in progress (remote party hung up)
echo "Finished call from $FINISHEDNUMBER">&2 echo "sxmo_modemmonitor: Finished call from $FINISHEDNUMBER">&2
rm -f "$CACHEDIR/${FINISHEDCALLID}.pickedupcall" rm -f "$CACHEDIR/${FINISHEDCALLID}.pickedupcall"
printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv"
else else
#this is a missed call #this is a missed call
# Add a notification for every missed call # Add a notification for every missed call
echo "Missed call from $FINISHEDNUMBER">&2 echo "sxmo_modemmonitor: Missed call from $FINISHEDNUMBER">&2
printf %b "$TIME\tcall_missed\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv" printf %b "$TIME\tcall_missed\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv"
CONTACT="$(lookupcontactname "$FINISHEDNUMBER")" CONTACT="$(lookupcontactname "$FINISHEDNUMBER")"
@ -95,12 +95,12 @@ checkforincomingcalls() {
echo "$VOICECALLID" | grep -v . && rm -f "$NOTIFDIR/incomingcall*" && return echo "$VOICECALLID" | grep -v . && rm -f "$NOTIFDIR/incomingcall*" && return
# Determine the incoming phone number # Determine the incoming phone number
echo "Incoming Call:" echo "sxmo_modemmonitor: Incoming Call:">&2
INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID") INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID")
CONTACTNAME=$(lookupcontactname "$INCOMINGNUMBER") CONTACTNAME=$(lookupcontactname "$INCOMINGNUMBER")
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then
echo "Invoking ring hook (async)">&2 echo "sxmo_modemmonitor: Invoking ring hook (async)">&2
"$XDG_CONFIG_HOME/sxmo/hooks/ring" "$CONTACTNAME" & "$XDG_CONFIG_HOME/sxmo/hooks/ring" "$CONTACTNAME" &
else else
sxmo_vibratepine 2500 & sxmo_vibratepine 2500 &
@ -116,7 +116,7 @@ checkforincomingcalls() {
none \ none \
"Pickup - $CONTACTNAME" & "Pickup - $CONTACTNAME" &
echo "Call from number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)">&2 echo "sxmo_modemmonitor: Call from number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)">&2
} }
checkfornewtexts() { checkfornewtexts() {
@ -139,7 +139,7 @@ checkfornewtexts() {
TIME="$(echo "$TEXTDATA" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" TIME="$(echo "$TEXTDATA" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')"
mkdir -p "$LOGDIR/$NUM" mkdir -p "$LOGDIR/$NUM"
echo "Text from number: $NUM (TEXTID: $TEXTID)">&2 echo "sxmo_modemmonitor: Text from number: $NUM (TEXTID: $TEXTID)">&2
printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt" printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt"
printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv" printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv"
mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID" mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID"
@ -185,5 +185,7 @@ mainloop() {
wait wait
} }
echo "sxmo_modemmonitor: starting -- $(date)" >&2
rm -f "$CACHEDIR"/*.pickedupcall 2>/dev/null #new session, forget all calls we picked up previously rm -f "$CACHEDIR"/*.pickedupcall 2>/dev/null #new session, forget all calls we picked up previously
mainloop mainloop
echo "sxmo_modemmonitor: exiting -- $(date)" >&2

@ -78,7 +78,7 @@ monitorforaddordelnotifs() {
done done
} }
pgrep -f "$(command -v sxmo_notificationmonitor.sh)" | grep -Ev "^${$}$" | xargs kill pgrep -f "$(command -v sxmo_notificationmonitor.sh)" | grep -Ev "^${$}$" | xargs -r kill
rm -f "$NOTIFDIR"/incomingcall rm -f "$NOTIFDIR"/incomingcall
recreateexistingnotifs recreateexistingnotifs
syncled syncled

Loading…
Cancel
Save