summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2018-02-13 14:42:59 -0600
committerJohn Klug <john.klug@multitech.com>2018-02-13 14:42:59 -0600
commitb60cc85d54024eca35069742f3032ef17e5a946e (patch)
tree64bcb8a4fca894ca45ce313aed02b2504c2f3d97
parentbc15567513ad3daa7f62288b31ed222e449871f5 (diff)
downloadmeta-mlinux-b60cc85d54024eca35069742f3032ef17e5a946e.tar.gz
meta-mlinux-b60cc85d54024eca35069742f3032ef17e5a946e.tar.bz2
meta-mlinux-b60cc85d54024eca35069742f3032ef17e5a946e.zip
Fix stalled ntpd startup on certain systems
-rwxr-xr-xrecipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh76
-rwxr-xr-xrecipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh78
2 files changed, 105 insertions, 49 deletions
diff --git a/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh b/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh
index 9fd3f7f..6c9c126 100755
--- a/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh
+++ b/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh
@@ -5,6 +5,10 @@
# This is to know when to set the system
# and hardware clock, and when
# it is safe to start ntp.
+# DEBUG=1 to set debug
+NAME=gpsd_ubx_fixed
+shopt -s expand_aliases
+alias LG=logger\ -t\ ${NAME}
if [[ -r /etc/default/gpsd ]] ; then
. /etc/default/gpsd
else
@@ -20,38 +24,62 @@ function rm_gps_file
rm -f "${GPS_FIXFILE}"
fi
}
+function kill_it
+{
+ cmd=$1
+ pid=$2
+ sig=$3
+ ((DEBUG)) && LG -p user.info "terminating $cmd(${pid}) with SIG${sig}"
+ kill -SIG${sig} ${pid} >/dev/null 2>&1
+ result=$?
+ ((DEBUG)) && LG -p user.info "kill -SIG${sig} ${pid} result is $result"
+}
+
# Most exits are errors, so remove the GPS fix file.
trap rm_gps_file EXIT
if ! [[ -x /usr/bin/gpsmon ]] ; then
- logger -p user.err "gpsd_ubx_3dfix.sh: Please install gpsmon"
+ LG -p user.err "Please install gpsmon"
exit 0
fi
-
# Terminate gpsmon after 10 seconds if it is our child
+# gpsmon has issues with terminals and stalling on terminal
+# read of the console.
(
sleep 10
- ppid=$$
- # echo "looking for shell ${ppid}"
- gpsmonpid=$(ps -o pid,ppid,comm -e | egrep "[[:space:]]${ppid}[[:space:]]+gpsmon$" | sed -r 's/^[[:space:]]*([0-9]*)[[:space:]]+.*/\1/')
- # echo sleeper TERM found pid $gpsmonpid
- if ((${#gpsmonpid})) ; then
- logger -p user.info "terminating gpscat(${gpsmonpid}) with SIGTERM"
- kill ${gpsmonpid}
- else
+ # We use BASHPID because our parent, $$, may have already exited, and
+ # then ps will not work. BASHPID is the current subshell.
+ ppid=$BASHPID
+ pgid=$(ps --no-heading -o pgid -p $ppid)
+
+ if ((${#pgid} == 0)) ; then
+ LG -p user.err "Could not find a pgid for $ppid"
+ ps -fjp $ppid | LG -p user.error
+ fi
+
+ gpsmonpid=$(pgrep -lg $pgid | egrep '[[:space:]]gpsmon$' | sed 's/[[:space:]].*//')
+ ((DEBUG)) && LG -p user.info "$pgid is pgid $gpsmonpid is gpsmonpid"
+ # Find the gpsmonpid that is our grandchild
+ ((didkill=0))
+
+ # for loop is in case gpsmonpid has children.
+ for p in ${gpsmonpid} ; do
+ if ((${#p})) ; then
+ kill_it gpsmon $p TERM
+ ((didkill=p))
+ break
+ fi
+ done
+ if ((didkill == 0)) ; then
exit 0
fi
+ # Do a sigkill to be sure.
sleep 2
- gpsmonpid=$(ps -o pid,ppid,comm -e | egrep "[[:space:]]${ppid}[[:space:]]+gpsmon$" | sed -r 's/^[[:space:]]*([0-9]*)[[:space:]]+.*/\1/')
- # echo sleeper KILL found pid $gpsmonpid
- if ((${#gpsmonpid})) ; then
- logger -p user.info "terminating gpscat(${gpsmonpid}) with SIGKILL"
- kill -9 ${gpsmonpid}
- fi
+ kill_it gpsmon $didkill KILL
) &
-
+
fix=""
status=""
@@ -84,12 +112,12 @@ stuff="$(gpsmon -a 2>&1 | {
})"
if ((${#stuff} == 0)) ; then
- logger -p user.err No data from GPS
+ LG -p user.err "No data from GPS"
exit 1
fi
if [[ -t 1 ]] ; then
- stty echo icanon
+ stty echo icanon 2>/dev/null
fi
OIFS=${IFS}
@@ -108,8 +136,8 @@ case $status in
((fixOK=0))
;;
*)
- logger -p user.err "Is GPSD running?"
- logger -p user.err "FIX OK field should be single hex digit: gpsmon data: $stuff"
+ LG -p user.err "Is GPSD running?"
+ LG -p user.err "FIX OK field should be single hex digit: gpsmon data: $stuff"
exit 1
break
;;
@@ -119,7 +147,7 @@ esac
if ((fixOK == 0)) ; then
- logger -p user.err "Problem with the GPS fix. The fix is an even value, \"$status\", and should be an odd value. fixOK=${fixOK}"
+ LG -p user.err "Problem with the GPS fix. The fix is an even value, \"$status\", and should be an odd value. fixOK=${fixOK}"
exit 1
# Retry later. How?
fi
@@ -129,14 +157,14 @@ fi
for x in $GPSFIX ; do
# echo test $x with $fix
if [[ $x == $fix ]] ; then
- logger user.info "GPS has fix $fix found in list GPSFIX: $GPSFIX"
+ LG -p user.info "GPS has fix $fix found in list GPSFIX: $GPSFIX"
echo $x >"${GPS_FIXFILE}"
GPS_FIXFILE=""
exit 0
fi
done
-logger -p user.info "GPS fix is bad: $fix and should be one of: $GPSFIX"
+LG -p user.info "GPS fix is bad: $fix and should be one of: $GPSFIX"
# Start later
exit 1
diff --git a/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh b/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
index 5644d57..f74e7b0 100755
--- a/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
+++ b/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
@@ -1,36 +1,63 @@
#!/bin/bash
# PPS= 1484247472.29561104 clock= 1484247990.00000000 offset= 517.704388959
+# DEBUG=1 to set debug
+NAME=gpsd_ubx_settime
+shopt -s expand_aliases
+alias LG="logger -t $NAME"
+function kill_it
+{
+ cmd=$1
+ pid=$2
+ sig=$3
+ ((DEBUG)) && LG -p user.info "terminating $cmd(${pid}) with SIG${sig}"
+ kill -SIG${sig} ${pid}
+ result=$?
+ ((DEBUG)) && LG -p user.info "kill -SIG${sig} ${pid} result is $result"
+}
trap "stty echo icanon" exit
OIFS=$IFS
IFS=$'\n'
-if ! /usr/sbin/gpsd_ubx_fixed ; then
- logger -s -p user.warn "GPS does not have a fix yet. Try again later."
+if ! /usr/sbin/gpsd_ubx_fixed </dev/null ; then
+ LG -s -p user.warn "GPS does not have a fix yet. Try again later."
exit 1
fi
-# This shell script is shaped by two things:
-# Lousy performance of sed and grep when used with gpsmon
-# Need to terminate
-# Terminate gpsmon after 10 seconds if it is our child
-(
- sleep 10
- ppid=$$
- gpsmonpid=$(ps -o pid,ppid,comm -e | egrep "[[:space:]]${ppid}[[:space:]]+gpsmon$" | sed -r 's/^[[:space:]]*([0-9]*)[[:space:]]+.*/\1/')
- if ((${#gpsmonpid})) ; then
- logger -p user.info "terminating gpscat(${gpsmonpid}) with SIGTERM"
- kill ${gpsmonpid}
- else
- exit 0
- fi
- sleep 2
- gpsmonpid=$(ps -o pid,ppid,comm -e | egrep "[[:space:]]${ppid}[[:space:]]+gpsmon$" | sed -r 's/^[[:space:]]*([0-9]*)[[:space:]]+.*/\1/')
- if ((${#gpsmonpid})) ; then
- logger -p user.info "terminating gpscat(${gpsmonpid}) with SIGKILL"
- kill -9 ${gpsmonpid}
- fi
-) &
-
+
+
+# Terminate gpsmon after 10 seconds if it is our child
+# gpsmon has issues with terminals and stalling on terminal
+# read of the console.
+(
+ sleep 10
+ ppid=$BASHPID
+ pgid=$(ps --no-heading -o pgid -p $ppid)
+
+ if ((${#pgid} == 0)) ; then
+ LG -p user.err "Could not find a pgid for $ppid"
+ ps -fjp $ppid | LG -p user.error
+ fi
+
+ gpsmonpid=$(pgrep -lg $pgid | egrep '[[:space:]]gpsmon$' | sed 's/[[:space:]].*//')
+ ((DEBUG)) && LG -p user.info "$pgid is pgid $gpsmonpid is gpsmonpid"
+ # Find the gpsmonpid that is our grandchild
+ ((didkill=0))
+
+ # for loop is in case gpsmonpid has children.
+ for p in ${gpsmonpid} ; do
+ if ((${#p})) ; then
+ kill_it gpsmon $p TERM
+ ((didkill=p))
+ break
+ fi
+ done
+ if ((didkill == 0)) ; then
+ exit 0
+ fi
+ # Do a sigkill to be sure.
+ sleep 2
+ kill_it gpsmon $didkill KILL
+) &
epoch=$(gpsmon -a 2>&1 | ( while read ln ; do
if [[ $ln =~ ^[[:space:]]*PPS=.*clock=[[:space:]]*([0-9]*)\. ]] ; then
@@ -39,9 +66,10 @@ epoch=$(gpsmon -a 2>&1 | ( while read ln ; do
fi
done ))
if [[ $epoch =~ ^[0-9]+$ ]] ; then
+ LG -p user.warn "Updating time to epoch time, ${epoch}."
date +%s -s @${epoch} >/dev/null
else
- logger user.err "gpsmon output is bad."
+ LG -p user.err "gpsmon output is bad."
exit 1
fi
exit 0