serial 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. #
  3. # serial 1.43 2004/07/01 17:26:26 (David Hinds)
  4. #
  5. # Initialize or shutdown a PCMCIA serial device
  6. #
  7. # The first argument should be either 'start' or 'stop'. The second
  8. # argument is the base name for the device.
  9. #
  10. # The script passes an extended device address to 'serial.opts' in the
  11. # ADDRESS variable, to retrieve device-specific configuration options.
  12. # The address format is "scheme,socket,instance" where "scheme" is the
  13. # PCMCIA configuration scheme, "socket" is the socket number, and
  14. # "instance" is used to number multiple ports on a single card.
  15. #
  16. if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi
  17. # Get device attributes
  18. get_info $DEVICE
  19. # Load site-specific settings
  20. ADDRESS="$SCHEME,$SOCKET,$INSTANCE"
  21. start_fn () { return; }
  22. stop_fn () { return; }
  23. . $0.opts
  24. # Newer kernels deprecate use of "cua" devices, but we need to
  25. # keep track of them anyway, if the device files are present
  26. NR=`expr $MINOR - 64`
  27. if [ -c /dev/cua1 ] ; then
  28. CALLOUT=cua$NR
  29. else
  30. CALLOUT=$DEVICE
  31. fi
  32. case "$ACTION" in
  33. 'start')
  34. [ -n "$VERBOSE" -a -n "$INFO" ] && echo "$INFO"
  35. if [ ! -c /dev/$DEVICE ] ; then
  36. cd /dev ; log ./MAKEDEV $DEVICE
  37. fi
  38. if [ -n "$LINK" ] ; then
  39. if [ -L $LINK ] ; then rm $LINK ; fi
  40. if match `uname -r` "2.[2-9].*" ; then
  41. ln -s /dev/$DEVICE $LINK
  42. else
  43. ln -s /dev/$CALLOUT $LINK
  44. fi
  45. fi
  46. if [ -x /bin/setserial ] ; then
  47. # Workaround for serial driver bug
  48. IRQ=`setserial /dev/$DEVICE | sed -e 's/.*IRQ: //'`
  49. setserial /dev/$DEVICE irq 0 ; setserial /dev/$DEVICE irq $IRQ
  50. if [ -n "$SERIAL_OPTS" ] ; then
  51. log setserial /dev/$DEVICE $SERIAL_OPTS
  52. fi
  53. fi
  54. if [ -n "$INITTAB" ] ; then
  55. echo "S$NR:12345:respawn:$INITTAB $DEVICE" >> /etc/inittab
  56. telinit q
  57. fi
  58. start_fn $DEVICE
  59. ;;
  60. 'check')
  61. is_true $NO_CHECK && exit 0
  62. if [ -n "$INITTAB" ] ; then
  63. do_fuser -v /dev/$DEVICE /dev/$CALLOUT $LINK | grep -v getty \
  64. | grep -q /dev/$DEVICE && exit 1
  65. else
  66. do_fuser -s /dev/$DEVICE /dev/$CALLOUT $LINK && exit 1
  67. fi
  68. ;;
  69. 'cksum')
  70. chk_simple "$NEW_SCHEME,$SOCKET,$INSTANCE" || exit 1
  71. ;;
  72. 'stop')
  73. if [ -n "$INITTAB" ] ; then
  74. grep -v $DEVICE /etc/inittab > /etc/inittab.new
  75. mv /etc/inittab.new /etc/inittab
  76. telinit q
  77. fi
  78. do_fuser -k /dev/$DEVICE /dev/$CALLOUT $LINK > /dev/null
  79. if [ -L "$LINK" ] ; then rm $LINK ; fi
  80. stop_fn $DEVICE
  81. ;;
  82. 'suspend')
  83. do_fuser -k -STOP /dev/$DEVICE /dev/$CALLOUT > /dev/null
  84. ;;
  85. 'resume')
  86. if [ -n "$SERIAL_OPTS" ] ; then
  87. setserial /dev/$DEVICE $SERIAL_OPTS
  88. fi
  89. do_fuser -k -CONT /dev/$DEVICE /dev/$CALLOUT $LINK > /dev/null
  90. ;;
  91. *)
  92. usage
  93. ;;
  94. esac
  95. exit 0