increased verbosity in various scripts, and do not run xargs kill when argument is empty (cleaner and clearer stderr messages)
This commit is contained in:
		
							parent
							
								
									ca88d3029e
								
							
						
					
					
						commit
						1608ab1ae4
					
				
					 8 changed files with 39 additions and 28 deletions
				
			
		| 
						 | 
				
			
			@ -180,7 +180,7 @@ configuresuspendsettingsandwakeupsources()
 | 
			
		|||
void
 | 
			
		||||
die(const char *err, ...)
 | 
			
		||||
{
 | 
			
		||||
	fprintf(stderr, "Error: %s", err);
 | 
			
		||||
	fprintf(stderr, "Screenlock error: %s\n", err);
 | 
			
		||||
	state = StateDead;
 | 
			
		||||
	syncstate();
 | 
			
		||||
	exit(1);
 | 
			
		||||
| 
						 | 
				
			
			@ -192,6 +192,7 @@ sigterm()
 | 
			
		|||
	state = StateDead;
 | 
			
		||||
	syncstate();
 | 
			
		||||
	if (wakeinterval) close(rtc_fd);
 | 
			
		||||
	fprintf(stderr, "Screenlock terminating on signal\n");
 | 
			
		||||
	exit(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -476,7 +477,7 @@ main(int argc, char **argv) {
 | 
			
		|||
			wakeinterval = (time_t) atoi(argv[++i]);
 | 
			
		||||
		} else if(!strcmp(argv[i], "--setuid")) {
 | 
			
		||||
			if (setuid(0))
 | 
			
		||||
				die("setuid(0) failed\n");
 | 
			
		||||
				die("setuid(0) failed");
 | 
			
		||||
		} else {
 | 
			
		||||
			fprintf(stderr, "Invalid argument: %s\n", argv[i]);
 | 
			
		||||
			return 2;
 | 
			
		||||
| 
						 | 
				
			
			@ -484,10 +485,12 @@ main(int argc, char **argv) {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (!(dpy = XOpenDisplay(NULL)))
 | 
			
		||||
		die("Cannot open display\n");
 | 
			
		||||
		die("Cannot open display");
 | 
			
		||||
 | 
			
		||||
	if (wakeinterval) init_rtc();
 | 
			
		||||
 | 
			
		||||
	fprintf(stderr, "Screenlock starting\n");
 | 
			
		||||
 | 
			
		||||
	XkbSetDetectableAutoRepeat(dpy, True, NULL);
 | 
			
		||||
	screen = XDefaultScreen(dpy);
 | 
			
		||||
	XSync(dpy, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -507,5 +510,6 @@ main(int argc, char **argv) {
 | 
			
		|||
		ioctl(rtc_fd, RTC_AIE_OFF, 0);
 | 
			
		||||
		close(rtc_fd);
 | 
			
		||||
	}
 | 
			
		||||
	fprintf(stderr, "Screenlock terminating normally\n");
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,13 +4,18 @@ WIN=$(xdotool getwindowfocus)
 | 
			
		|||
NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications
 | 
			
		||||
 | 
			
		||||
gracefulexit() {
 | 
			
		||||
	echo "Gracefully exiting $0"
 | 
			
		||||
	echo "Gracefully exiting $0">&2
 | 
			
		||||
	kill -9 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
programchoicesinit() {
 | 
			
		||||
	XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")"
 | 
			
		||||
	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
 | 
			
		||||
		# Scripts menu
 | 
			
		||||
| 
						 | 
				
			
			@ -441,7 +446,7 @@ mainloop() {
 | 
			
		|||
		LOOP="$(echo "$PROGCHOICES" | grep -m1 -F "$PICKED" | cut -d '^' -f2)"
 | 
			
		||||
		CMD="$(echo "$PROGCHOICES" | grep -m1 -F "$PICKED" | cut -d '^' -f3)"
 | 
			
		||||
		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
 | 
			
		||||
			eval "$CMD"
 | 
			
		||||
			mainloop
 | 
			
		||||
| 
						 | 
				
			
			@ -452,7 +457,7 @@ mainloop() {
 | 
			
		|||
	) & 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
 | 
			
		||||
PICKED=""
 | 
			
		||||
ARGS="$*"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ FILE_X="$(find /sys/bus/iio/devices/iio:device*/ -iname in_accel_x_raw)"
 | 
			
		|||
 | 
			
		||||
autorotatedisable() {
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
#!/usr/bin/env sh
 | 
			
		||||
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() {
 | 
			
		||||
	# In-call.. show length of call
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,2 +1,2 @@
 | 
			
		|||
#!/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
 | 
			
		||||
	setsid -f sh -c 'sleep 2; sxmo_statusbarupdate.sh'
 | 
			
		||||
	if [ -n "$1" ]; then
 | 
			
		||||
		echo "$1">&2
 | 
			
		||||
		echo "sxmo_modemcall: $1">&2
 | 
			
		||||
		notify-send "$1"
 | 
			
		||||
	fi
 | 
			
		||||
	kill -9 0
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +43,7 @@ gracefulexit() {
 | 
			
		|||
modem_cmd_errcheck() {
 | 
			
		||||
	RES="$(mmcli "$@" 2>&1)"
 | 
			
		||||
	OK="$?"
 | 
			
		||||
	echo "Command: mmcli $*">&2
 | 
			
		||||
	echo "sxmo_modemcall: Command: mmcli $*">&2
 | 
			
		||||
	if [ "$OK" != 0 ]; then finish "Problem executing mmcli command!\n$RES"; fi
 | 
			
		||||
	echo "$RES"
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +86,7 @@ toggleflagset() {
 | 
			
		|||
 | 
			
		||||
acceptcall() {
 | 
			
		||||
	CALLID="$1"
 | 
			
		||||
	echo "Attempting to initialize CALLID $CALLID">&2
 | 
			
		||||
	echo "sxmo_modemcall: Attempting to initialize CALLID $CALLID">&2
 | 
			
		||||
	DIRECTION="$(
 | 
			
		||||
		mmcli --voice-status -o "$CALLID" -K |
 | 
			
		||||
		grep call.properties.direction |
 | 
			
		||||
| 
						 | 
				
			
			@ -96,17 +96,17 @@ acceptcall() {
 | 
			
		|||
	if [ "$DIRECTION" = "outgoing" ]; then
 | 
			
		||||
		modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --start
 | 
			
		||||
		log_event "call_start" "$CALLID"
 | 
			
		||||
		echo "Started call $CALLID">&2
 | 
			
		||||
		echo "sxmo_modemcall: Started call $CALLID">&2
 | 
			
		||||
	elif [ "$DIRECTION" = "incoming" ]; 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" &
 | 
			
		||||
		fi
 | 
			
		||||
		touch "$CACHEDIR/${CALLID}.pickedupcall" #this signals that we picked this call up
 | 
			
		||||
											     #to other asynchronously running processes
 | 
			
		||||
		modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept
 | 
			
		||||
		log_event "call_pickup" "$CALLID"
 | 
			
		||||
		echo "Picked up call $CALLID">&2
 | 
			
		||||
		echo "sxmo_modemcall: Picked up call $CALLID">&2
 | 
			
		||||
	else
 | 
			
		||||
		finish "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>"
 | 
			
		||||
	fi
 | 
			
		||||
| 
						 | 
				
			
			@ -157,13 +157,13 @@ incallmonitor() {
 | 
			
		|||
				finish "Call with $NUMBER terminated"
 | 
			
		||||
			fi
 | 
			
		||||
		fi
 | 
			
		||||
		echo "Call still in progress">&2
 | 
			
		||||
		echo "sxmo_modemcall: Call still in progress">&2
 | 
			
		||||
		sleep 3
 | 
			
		||||
	done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
incallmenuloop() {
 | 
			
		||||
	echo "Current flags are $FLAGS">&2
 | 
			
		||||
	echo "sxmo_modemcall: Current flags are $FLAGS">&2
 | 
			
		||||
	CHOICES="
 | 
			
		||||
		$([ "$WINDOWIFIED" = 0 ] && echo Windowify || echo Unwindowify)   ^ togglewindowify
 | 
			
		||||
		$([ "$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" |
 | 
			
		||||
		(
 | 
			
		||||
			PICKED="$(cat)";
 | 
			
		||||
			echo "Picked is $PICKED">&2
 | 
			
		||||
			echo "sxmo_modemcall: Picked is $PICKED">&2
 | 
			
		||||
			echo "$PICKED" | grep -Ev "."
 | 
			
		||||
			CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d'^' -f2)
 | 
			
		||||
			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"
 | 
			
		||||
			incallmenuloop
 | 
			
		||||
		) & wait # E.g. bg & wait to allow for SIGINT propogation
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,13 +5,13 @@ CACHEDIR="$XDG_CACHE_HOME"/sxmo
 | 
			
		|||
trap "gracefulexit" INT TERM
 | 
			
		||||
 | 
			
		||||
err() {
 | 
			
		||||
	echo "$1">&2
 | 
			
		||||
	echo "sxmo_modemmonitor: Error: $1">&2
 | 
			
		||||
	notify-send "$1"
 | 
			
		||||
	gracefulexit
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gracefulexit() {
 | 
			
		||||
	echo "gracefully exiting $0!">&2
 | 
			
		||||
	echo "sxmo_modemmonitor: gracefully exiting (on signal or after error)">&2
 | 
			
		||||
	kill -9 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -67,13 +67,13 @@ checkforfinishedcalls() {
 | 
			
		|||
		if [ -f "$CACHEDIR/${FINISHEDCALLID}.pickedupcall" ]; then
 | 
			
		||||
			#this call was picked 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"
 | 
			
		||||
			printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv"
 | 
			
		||||
		else
 | 
			
		||||
			#this is a 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"
 | 
			
		||||
 | 
			
		||||
			CONTACT="$(lookupcontactname "$FINISHEDNUMBER")"
 | 
			
		||||
| 
						 | 
				
			
			@ -95,12 +95,12 @@ checkforincomingcalls() {
 | 
			
		|||
	echo "$VOICECALLID" | grep -v . && rm -f "$NOTIFDIR/incomingcall*" && return
 | 
			
		||||
 | 
			
		||||
	# Determine the incoming phone number
 | 
			
		||||
	echo "Incoming Call:"
 | 
			
		||||
	echo "sxmo_modemmonitor: Incoming Call:">&2
 | 
			
		||||
	INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID")
 | 
			
		||||
	CONTACTNAME=$(lookupcontactname "$INCOMINGNUMBER")
 | 
			
		||||
 | 
			
		||||
	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" &
 | 
			
		||||
	else
 | 
			
		||||
		sxmo_vibratepine 2500 &
 | 
			
		||||
| 
						 | 
				
			
			@ -116,7 +116,7 @@ checkforincomingcalls() {
 | 
			
		|||
		none \
 | 
			
		||||
		"Pickup - $CONTACTNAME" &
 | 
			
		||||
 | 
			
		||||
	echo "Call from number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)">&2
 | 
			
		||||
	echo "sxmo_modemmonitor: Call from number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)">&2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
checkfornewtexts() {
 | 
			
		||||
| 
						 | 
				
			
			@ -139,7 +139,7 @@ checkfornewtexts() {
 | 
			
		|||
		TIME="$(echo "$TEXTDATA" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')"
 | 
			
		||||
 | 
			
		||||
		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 "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv"
 | 
			
		||||
		mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID"
 | 
			
		||||
| 
						 | 
				
			
			@ -185,5 +185,7 @@ mainloop() {
 | 
			
		|||
	wait
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
echo "sxmo_modemmonitor: starting -- $(date)" >&2
 | 
			
		||||
rm -f "$CACHEDIR"/*.pickedupcall 2>/dev/null #new session, forget all calls we picked up previously
 | 
			
		||||
mainloop
 | 
			
		||||
echo "sxmo_modemmonitor: exiting -- $(date)" >&2
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -78,7 +78,7 @@ monitorforaddordelnotifs() {
 | 
			
		|||
	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
 | 
			
		||||
recreateexistingnotifs
 | 
			
		||||
syncled
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue