You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gpsd.hotplug 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. #
  3. # This script is the gpsd udev handler for add/remove events on matched USB
  4. # devices. It expects to see the following environment variables:
  5. #
  6. # ACTION = either "add" or "remove"
  7. # DEVNAME = the full name of the USB device that was just activated
  8. #
  9. # It will accept from /etc/sysconfig/gpsd the following config variables:
  10. #
  11. # CONTROL_SOCKET = location of the gpsd control socket
  12. # OPTIONS = options to be passed to gpsd on launch
  13. #
  14. # It hands off to gpsdctl for the actual communication with the daemon.
  15. #
  16. # Do not introduce bashims into this script, as we want it to continue to
  17. # work under Ubuntu.
  18. #
  19. # This file is Copyright (c) 2010 by the GPSD project
  20. # SPDX-License-Identifier: BSD-2-clause
  21. PATH=/usr/sbin:$PATH
  22. export PATH
  23. if [ -r /etc/default/gpsd ]; then
  24. . /etc/default/gpsd
  25. elif [ -r /etc/conf.d/gpsd ]; then
  26. . /etc/conf.d/gpsd
  27. elif [ -r /etc/sysconfig/gpsd ]; then
  28. . /etc/sysconfig/gpsd
  29. GPSD_OPTIONS=$OPTIONS
  30. GPSD_SOCKET=$CONTROL_SOCKET
  31. fi
  32. if [ -n "$GPSD_OPTIONS" ]; then
  33. export GPSD_OPTIONS
  34. fi
  35. if [ -n "$GPSD_SOCKET" ]; then
  36. export GPSD_SOCKET
  37. fi
  38. if [ -n "$USBAUTO" ]; then
  39. [ "$USBAUTO" = "true" ] || exit 0
  40. fi
  41. if [ "$ACTION" = "remove" ] ; then
  42. if echo $DEVLINKS | grep -q /dev/gps; then
  43. :
  44. else
  45. exit 0
  46. fi
  47. fi
  48. logger -t "gpsd.hotplug" -p daemon.info "$ACTION" "$DEVNAME"
  49. if [ -z "$DEVNAME" ]
  50. then
  51. logger -t gpsd.hotplug -p daemon.err "no device"
  52. exit 0
  53. fi
  54. # In recent versions of udev, the gpsd script runs in series with
  55. # the task that creates the real /dev/ttyUSBn device
  56. # node. Unfortunately, the gpsd script runs BEFORE the creation of
  57. # the node, and the node is not created until after you kill the
  58. # gpsd script, because the gpsd script waits forever for the node
  59. # to appear.
  60. #
  61. # This is a race condition, and is best fixed by running the
  62. # actual wait/hotplug portion in the background.
  63. {
  64. #logger -t gpsd.hotplug -p daemon.info "waiting for" $DEVNAME
  65. while [ -x $DEVNAME ]
  66. do
  67. sleep 1
  68. done
  69. #logger -t gpsd.hotplug -p daemon.info $DEVNAME "is active"
  70. gpsdctl $ACTION $DEVNAME
  71. } &