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.

119 lines
2.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2011 OpenWrt.org
  3. START=50
  4. STOP=10
  5. USE_PROCD=1
  6. PROG="/usr/sbin/xinetd"
  7. PIDFILE="/var/run/xinetd.pid"
  8. CONF_FILE="/etc/config/xinetd"
  9. GENERATED_CONF_FILE="/var/run/xinetd.conf"
  10. ServiceEntry="false"
  11. ListName=""
  12. ListValue=""
  13. # redefined callback for sections when calling config_load
  14. config_cb() {
  15. # write out last list option (from last section) if exist and clear
  16. if [ "$ListName" != "" ]; then
  17. echo -e "\t$ListName = $ListVals" >> $GENERATED_CONF_FILE
  18. fi
  19. ListName=""
  20. ListVals=""
  21. # "close" last service entry (from last section) if exist
  22. if [ "$ServiceEntry" = "true" ]; then # at least one service section "opened"
  23. echo "}" >> $GENERATED_CONF_FILE # "close" open service section in config
  24. ServiceEntry="false"
  25. fi
  26. if [ $# -eq 0 ]; then # end of config reached
  27. return
  28. fi
  29. local type="$1"
  30. local name="$2"
  31. if [ "$type" = "service" ]; then
  32. if [ "$ServiceEntry" = "true" ]; then
  33. echo "}" >> $GENERATED_CONF_FILE # "close" previous opened service section in config
  34. fi
  35. ServiceEntry="true"
  36. echo "" >> $GENERATED_CONF_FILE
  37. echo "service $name" >> $GENERATED_CONF_FILE
  38. echo "{" >> $GENERATED_CONF_FILE
  39. # redefined callback for options when calling config_load
  40. option_cb() {
  41. local option="$1"
  42. local value="$2"
  43. [ -n "$value" ] && echo -e "\t$option = $value" >> $GENERATED_CONF_FILE
  44. }
  45. # redefined callback for lists when calling config_load
  46. list_cb() {
  47. local name="$1"
  48. local value="$2"
  49. # write out last list option if new list starts
  50. if [ "$ListName" != "" -a "$ListName" != "$name" ]; then
  51. echo -e "\t$ListName = $ListVals" >> $GENERATED_CONF_FILE
  52. ListName=""
  53. ListVals=""
  54. fi
  55. # new list option
  56. if [ -z "$ListName" ]; then
  57. ListName="$name"
  58. ListVals="$value"
  59. else
  60. ListVals="$ListVals $value"
  61. fi
  62. }
  63. else # ignore non 'service' sections
  64. return 0
  65. fi
  66. }
  67. generate_config() {
  68. echo "# Auto-generated config file from $CONF_FILE" > $GENERATED_CONF_FILE
  69. echo "# Do not edit, changes to this file will be lost on upgrades" >> $GENERATED_CONF_FILE
  70. echo "" >> $GENERATED_CONF_FILE
  71. echo "defaults" >> $GENERATED_CONF_FILE
  72. echo "{" >> $GENERATED_CONF_FILE
  73. echo "" >> $GENERATED_CONF_FILE
  74. echo "}" >> $GENERATED_CONF_FILE
  75. echo "" >> $GENERATED_CONF_FILE
  76. echo "includedir /etc/xinetd.d" >> $GENERATED_CONF_FILE
  77. config_load xinetd
  78. }
  79. start_service() {
  80. generate_config
  81. procd_open_instance
  82. procd_set_param command $PROG -dontfork -f $GENERATED_CONF_FILE -pidfile $PIDFILE
  83. procd_set_param respawn
  84. procd_close_instance
  85. }
  86. service_triggers() {
  87. procd_add_reload_trigger "xinetd"
  88. }