PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/autogen-5.12/agen5/test/daemon.test

#
Korn Shell | 127 lines | 62 code | 21 blank | 44 comment | 8 complexity | 773bb2fba7f58020c31b78ef5f44b5ff MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, LGPL-3.0
  1. #! /bin/ksh
  2. # -*- Mode: Shell-script -*-
  3. # daemon.test --- test functionality of `for' function
  4. #
  5. # Time-stamp: "2011-02-02 12:00:31 bkorb"
  6. # Author: Bruce Korb <bkorb@gnu.org>
  7. ##
  8. ## This file is part of AutoGen.
  9. ## AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
  10. ##
  11. ## AutoGen is free software: you can redistribute it and/or modify it
  12. ## under the terms of the GNU General Public License as published by the
  13. ## Free Software Foundation, either version 3 of the License, or
  14. ## (at your option) any later version.
  15. ##
  16. ## AutoGen is distributed in the hope that it will be useful, but
  17. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. ## See the GNU General Public License for more details.
  20. ##
  21. ## You should have received a copy of the GNU General Public License along
  22. ## with this program. If not, see <http://www.gnu.org/licenses/>.
  23. ##
  24. #
  25. # ----------------------------------------------------------------------
  26. tdir=$( (mktemp -d $PWD/.daemon-XXXXXX.d) 2>/dev/null)
  27. test -z "${tdir}" && {
  28. tdir=$PWD/.daemon-$$.d
  29. rm -rf ${tdir}
  30. mkdir ${tdir} || exit 1
  31. }
  32. ag=`cd .. >/dev/null ; pwd`/autogen
  33. case $- in
  34. *x* ) setcmd="set -ex" ;;
  35. * ) setcmd='set -e' ;;
  36. esac
  37. cd ${tdir}
  38. exec 5> daemon-results
  39. cat > daemon.tpl <<_EOF_
  40. [= AutoGen5 Template =]
  41. This is from the [= (shell "echo $$") =] server.
  42. _EOF_
  43. run_thrice() {
  44. $setcmd
  45. sleep 1
  46. for f in 1 2 3
  47. do (
  48. cat > ${1} <<_EOF_
  49. AutoGen Definitions daemon.tpl;
  50. hello = yes;
  51. _EOF_
  52. sleep 1
  53. cat >&5 < ${2}
  54. ) &
  55. done
  56. sleep 1
  57. }
  58. do_run() {
  59. $setcmd
  60. $cmd &
  61. pid=$!
  62. while test ! -S ${1} -a ! -p ${1}
  63. do print -u2 No ${1}. Must delay.
  64. ( ps -p ${pid} > /dev/null 2>&1 ) || {
  65. print -u2 "autogen has gone away"
  66. exit 1
  67. }
  68. sleep 1
  69. done
  70. run_thrice "$@"
  71. ps -fp $pid
  72. kill -HUP ${pid} || \
  73. kill -TERM ${pid} || \
  74. kill -KILL ${pid}
  75. }
  76. ( ${ag} --daemon daemon-io --help > /dev/null 2>&1 ) || exit 0
  77. cmd="${ag} --daemon daemon-io -b dmn"
  78. do_run daemon-io-in daemon-io-out
  79. tmp=$(echo ${tdir} | ${SED} 's,.*/\.,,;s/\.d$//')
  80. pipe=$PWD/${tmp}
  81. cmd="${ag} --daemon unix:${pipe} -b dmn"
  82. do_run ${tmp} ${tmp}
  83. sleep 2
  84. exec 5>&-
  85. cat daemon-results
  86. cd ..
  87. rm -rf ${tdir}
  88. # No daemon-io-in. Must delay.
  89. # UID PID PPID C STIME TTY TIME CMD
  90. # bkorb 18431 18427 3 18:18 pts/1 00:00:00 /home/bkorb/ag/ag/agen5/.libs/lt
  91. # AutoGen aborting on signal 1 (Hangup) in state OPTIONS
  92. # No daemon-w0QjvL. Must delay.
  93. # ./daemon.test[71]: cannot create daemon-w0QjvL: No such device or address
  94. # ./daemon.test[71]: cannot create daemon-w0QjvL: No such device or address
  95. # ./daemon.test[71]: cannot create daemon-w0QjvL: No such device or address
  96. # UID PID PPID C STIME TTY TIME CMD
  97. # bkorb 18466 18427 3 18:18 pts/1 00:00:00 /home/bkorb/ag/ag/agen5/.libs/lt
  98. # AutoGen aborting on signal 1 (Hangup) in state OPTIONS
  99. # This is from the 18427 server.
  100. ## Local Variables:
  101. ## mode: shell-script
  102. ## indent-tabs-mode: nil
  103. ## sh-indentation: 2
  104. ## sh-basic-offset: 2
  105. ## End:
  106. # end of daemon.test