1
0

init-functions 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. #!/bin/sh
  2. ########################################################################
  3. #
  4. # Begin /lib/lsb/init-funtions
  5. #
  6. # Description : Run Level Control Functions
  7. #
  8. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  9. # : DJ Lucas - dj@linuxfromscratch.org
  10. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  11. #
  12. # Version : LFS 7.0
  13. #
  14. # Notes : With code based on Matthias Benkmann's simpleinit-msb
  15. # http://winterdrache.de/linux/newboot/index.html
  16. #
  17. # The file should be located in /lib/lsb
  18. #
  19. ########################################################################
  20. ## Environmental setup
  21. # Setup default values for environment
  22. umask 022
  23. export PATH="/bin:/usr/bin:/sbin:/usr/sbin"
  24. ## Screen Dimensions
  25. # Find current screen size
  26. if [ -z "${COLUMNS}" ]; then
  27. COLUMNS=$(stty size)
  28. COLUMNS=${COLUMNS##* }
  29. fi
  30. # When using remote connections, such as a serial port, stty size returns 0
  31. if [ "${COLUMNS}" = "0" ]; then
  32. COLUMNS=80
  33. fi
  34. ## Measurements for positioning result messages
  35. COL=$((${COLUMNS} - 8))
  36. WCOL=$((${COL} - 2))
  37. ## Set Cursor Position Commands, used via echo
  38. SET_COL="\\033[${COL}G" # at the $COL char
  39. SET_WCOL="\\033[${WCOL}G" # at the $WCOL char
  40. CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char
  41. CURS_ZERO="\\033[0G"
  42. ## Set color commands, used via echo
  43. # Please consult `man console_codes for more information
  44. # under the "ECMA-48 Set Graphics Rendition" section
  45. #
  46. # Warning: when switching from a 8bit to a 9bit font,
  47. # the linux console will reinterpret the bold (1;) to
  48. # the top 256 glyphs of the 9bit font. This does
  49. # not affect framebuffer consoles
  50. NORMAL="\\033[0;39m" # Standard console grey
  51. SUCCESS="\\033[1;32m" # Success is green
  52. WARNING="\\033[1;33m" # Warnings are yellow
  53. FAILURE="\\033[1;31m" # Failures are red
  54. INFO="\\033[1;36m" # Information is light cyan
  55. BRACKET="\\033[1;34m" # Brackets are blue
  56. # Distro Information
  57. DISTRO="Linux From Scratch" # The distro name as displayed
  58. DISTRO_CONTACT="lfs-dev@linuxfromscratch.org" # Bug report address
  59. DISTRO_MINI="LFS" # Short name used in filenames for distro config
  60. # Use a colored prefix
  61. BMPREFIX=" "
  62. SUCCESS_PREFIX="${SUCCESS} * ${NORMAL}"
  63. FAILURE_PREFIX="${FAILURE}*****${NORMAL}"
  64. WARNING_PREFIX="${WARNING} *** ${NORMAL}"
  65. BOOTLOG=/run/var/bootlog
  66. KILLDELAY=3
  67. # Set any user specified environment variables e.g. HEADLESS
  68. [ -r /etc/sysconfig/rc.site ] && . /etc/sysconfig/rc.site
  69. ################################################################################
  70. # start_daemon() #
  71. # Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] #
  72. # #
  73. # Purpose: This runs the specified program as a daemon #
  74. # #
  75. # Inputs: -f: (force) run the program even if it is already running. #
  76. # -n nicelevel: specify a nice level. See 'man nice(1)'. #
  77. # -p pidfile: use the specified file to determine PIDs. #
  78. # pathname: the complete path to the specified program #
  79. # args: additional arguments passed to the program (pathname) #
  80. # #
  81. # Return values (as defined by LSB exit codes): #
  82. # 0 - program is running or service is OK #
  83. # 1 - generic or unspecified error #
  84. # 2 - invalid or excessive argument(s) #
  85. # 5 - program is not installed #
  86. ################################################################################
  87. start_daemon()
  88. {
  89. local force=""
  90. local nice="0"
  91. local pidfile=""
  92. local pidlist=""
  93. local retval=""
  94. # Process arguments
  95. while true
  96. do
  97. case "${1}" in
  98. -f)
  99. force="1"
  100. shift 1
  101. ;;
  102. -n)
  103. nice="${2}"
  104. shift 2
  105. ;;
  106. -p)
  107. pidfile="${2}"
  108. shift 2
  109. ;;
  110. -*)
  111. return 2
  112. ;;
  113. *)
  114. program="${1}"
  115. break
  116. ;;
  117. esac
  118. done
  119. # Check for a valid program
  120. if [ ! -e "${program}" ]; then return 5; fi
  121. # Execute
  122. if [ -z "${force}" ]; then
  123. if [ -z "${pidfile}" ]; then
  124. # Determine the pid by discovery
  125. pidlist=`pidofproc "${1}"`
  126. retval="${?}"
  127. else
  128. # The PID file contains the needed PIDs
  129. # Note that by LSB requirement, the path must be given to pidofproc,
  130. # however, it is not used by the current implementation or standard.
  131. pidlist=`pidofproc -p "${pidfile}" "${1}"`
  132. retval="${?}"
  133. fi
  134. # Return a value ONLY
  135. # It is the init script's (or distribution's functions) responsibilty
  136. # to log messages!
  137. case "${retval}" in
  138. 0)
  139. # Program is already running correctly, this is a
  140. # succesful start.
  141. return 0
  142. ;;
  143. 1)
  144. # Program is not running, but an invalid pid file exists
  145. # remove the pid file and continue
  146. rm -f "${pidfile}"
  147. ;;
  148. 3)
  149. # Program is not running and no pidfile exists
  150. # do nothing here, let start_deamon continue.
  151. ;;
  152. *)
  153. # Others as returned by status values shall not be interpreted
  154. # and returned as an unspecified error.
  155. return 1
  156. ;;
  157. esac
  158. fi
  159. # Do the start!
  160. nice -n "${nice}" "${@}"
  161. }
  162. ################################################################################
  163. # killproc() #
  164. # Usage: killproc [-p pidfile] pathname [signal] #
  165. # #
  166. # Purpose: Send control signals to running processes #
  167. # #
  168. # Inputs: -p pidfile, uses the specified pidfile #
  169. # pathname, pathname to the specified program #
  170. # signal, send this signal to pathname #
  171. # #
  172. # Return values (as defined by LSB exit codes): #
  173. # 0 - program (pathname) has stopped/is already stopped or a #
  174. # running program has been sent specified signal and stopped #
  175. # successfully #
  176. # 1 - generic or unspecified error #
  177. # 2 - invalid or excessive argument(s) #
  178. # 5 - program is not installed #
  179. # 7 - program is not running and a signal was supplied #
  180. ################################################################################
  181. killproc()
  182. {
  183. local pidfile
  184. local program
  185. local prefix
  186. local progname
  187. local signal="-TERM"
  188. local fallback="-KILL"
  189. local nosig
  190. local pidlist
  191. local retval
  192. local pid
  193. local delay="30"
  194. local piddead
  195. local dtime
  196. # Process arguments
  197. while true; do
  198. case "${1}" in
  199. -p)
  200. pidfile="${2}"
  201. shift 2
  202. ;;
  203. *)
  204. program="${1}"
  205. if [ -n "${2}" ]; then
  206. signal="${2}"
  207. fallback=""
  208. else
  209. nosig=1
  210. fi
  211. # Error on additional arguments
  212. if [ -n "${3}" ]; then
  213. return 2
  214. else
  215. break
  216. fi
  217. ;;
  218. esac
  219. done
  220. # Check for a valid program
  221. if [ ! -e "${program}" ]; then return 5; fi
  222. # Check for a valid signal
  223. check_signal "${signal}"
  224. if [ "${?}" -ne "0" ]; then return 2; fi
  225. # Get a list of pids
  226. if [ -z "${pidfile}" ]; then
  227. # determine the pid by discovery
  228. pidlist=`pidofproc "${1}"`
  229. retval="${?}"
  230. else
  231. # The PID file contains the needed PIDs
  232. # Note that by LSB requirement, the path must be given to pidofproc,
  233. # however, it is not used by the current implementation or standard.
  234. pidlist=`pidofproc -p "${pidfile}" "${1}"`
  235. retval="${?}"
  236. fi
  237. # Return a value ONLY
  238. # It is the init script's (or distribution's functions) responsibilty
  239. # to log messages!
  240. case "${retval}" in
  241. 0)
  242. # Program is running correctly
  243. # Do nothing here, let killproc continue.
  244. ;;
  245. 1)
  246. # Program is not running, but an invalid pid file exists
  247. # Remove the pid file.
  248. rm -f "${pidfile}"
  249. # This is only a success if no signal was passed.
  250. if [ -n "${nosig}" ]; then
  251. return 0
  252. else
  253. return 7
  254. fi
  255. ;;
  256. 3)
  257. # Program is not running and no pidfile exists
  258. # This is only a success if no signal was passed.
  259. if [ -n "${nosig}" ]; then
  260. return 0
  261. else
  262. return 7
  263. fi
  264. ;;
  265. *)
  266. # Others as returned by status values shall not be interpreted
  267. # and returned as an unspecified error.
  268. return 1
  269. ;;
  270. esac
  271. # Perform different actions for exit signals and control signals
  272. check_sig_type "${signal}"
  273. if [ "${?}" -eq "0" ]; then # Signal is used to terminate the program
  274. # Account for empty pidlist (pid file still exists and no
  275. # signal was given)
  276. if [ "${pidlist}" != "" ]; then
  277. # Kill the list of pids
  278. for pid in ${pidlist}; do
  279. kill -0 "${pid}" 2> /dev/null
  280. if [ "${?}" -ne "0" ]; then
  281. # Process is dead, continue to next and assume all is well
  282. continue
  283. else
  284. kill "${signal}" "${pid}" 2> /dev/null
  285. # Wait up to ${delay}/10 seconds to for "${pid}" to
  286. # terminate in 10ths of a second
  287. while [ "${delay}" -ne "0" ]; do
  288. kill -0 "${pid}" 2> /dev/null || piddead="1"
  289. if [ "${piddead}" = "1" ]; then break; fi
  290. sleep 0.1
  291. delay="$(( ${delay} - 1 ))"
  292. done
  293. # If a fallback is set, and program is still running, then
  294. # use the fallback
  295. if [ -n "${fallback}" -a "${piddead}" != "1" ]; then
  296. kill "${fallback}" "${pid}" 2> /dev/null
  297. sleep 1
  298. # Check again, and fail if still running
  299. kill -0 "${pid}" 2> /dev/null && return 1
  300. else
  301. # just check one last time and if still alive, fail
  302. sleep 1
  303. kill -0 "${pid}" 2> /dev/null && return 1
  304. fi
  305. fi
  306. done
  307. fi
  308. # Check for and remove stale PID files.
  309. if [ -z "${pidfile}" ]; then
  310. # Find the basename of $program
  311. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  312. progname=`echo "${program}" | sed "s@${prefix}@@"`
  313. if [ -e "/var/run/${progname}.pid" ]; then
  314. rm -f "/var/run/${progname}.pid" 2> /dev/null
  315. fi
  316. else
  317. if [ -e "${pidfile}" ]; then rm -f "${pidfile}" 2> /dev/null; fi
  318. fi
  319. # For signals that do not expect a program to exit, simply
  320. # let kill do it's job, and evaluate kills return for value
  321. else # check_sig_type - signal is not used to terminate program
  322. for pid in ${pidlist}; do
  323. kill "${signal}" "${pid}"
  324. if [ "${?}" -ne "0" ]; then return 1; fi
  325. done
  326. fi
  327. }
  328. ################################################################################
  329. # pidofproc() #
  330. # Usage: pidofproc [-p pidfile] pathname #
  331. # #
  332. # Purpose: This function returns one or more pid(s) for a particular daemon #
  333. # #
  334. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  335. # pathname, path to the specified program #
  336. # #
  337. # Return values (as defined by LSB status codes): #
  338. # 0 - Success (PIDs to stdout) #
  339. # 1 - Program is dead, PID file still exists (remaining PIDs output) #
  340. # 3 - Program is not running (no output) #
  341. ################################################################################
  342. pidofproc()
  343. {
  344. local pidfile
  345. local program
  346. local prefix
  347. local progname
  348. local pidlist
  349. local lpids
  350. local exitstatus="0"
  351. # Process arguments
  352. while true; do
  353. case "${1}" in
  354. -p)
  355. pidfile="${2}"
  356. shift 2
  357. ;;
  358. *)
  359. program="${1}"
  360. if [ -n "${2}" ]; then
  361. # Too many arguments
  362. # Since this is status, return unknown
  363. return 4
  364. else
  365. break
  366. fi
  367. ;;
  368. esac
  369. done
  370. # If a PID file is not specified, try and find one.
  371. if [ -z "${pidfile}" ]; then
  372. # Get the program's basename
  373. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  374. if [ -z "${prefix}" ]; then
  375. progname="${program}"
  376. else
  377. progname=`echo "${program}" | sed "s@${prefix}@@"`
  378. fi
  379. # If a PID file exists with that name, assume that is it.
  380. if [ -e "/var/run/${progname}.pid" ]; then
  381. pidfile="/var/run/${progname}.pid"
  382. fi
  383. fi
  384. # If a PID file is set and exists, use it.
  385. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  386. # Use the value in the first line of the pidfile
  387. pidlist=`/bin/head -n1 "${pidfile}"`
  388. # This can optionally be written as 'sed 1q' to repalce 'head -n1'
  389. # should LFS move /bin/head to /usr/bin/head
  390. else
  391. # Use pidof
  392. pidlist=`pidof "${program}"`
  393. fi
  394. # Figure out if all listed PIDs are running.
  395. for pid in ${pidlist}; do
  396. kill -0 ${pid} 2> /dev/null
  397. if [ "${?}" -eq "0" ]; then
  398. lpids="${pids}${pid} "
  399. else
  400. exitstatus="1"
  401. fi
  402. done
  403. if [ -z "${lpids}" -a ! -f "${pidfile}" ]; then
  404. return 3
  405. else
  406. echo "${lpids}"
  407. return "${exitstatus}"
  408. fi
  409. }
  410. ################################################################################
  411. # statusproc() #
  412. # Usage: statusproc [-p pidfile] pathname #
  413. # #
  414. # Purpose: This function prints the status of a particular daemon to stdout #
  415. # #
  416. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  417. # pathname, path to the specified program #
  418. # #
  419. # Return values: #
  420. # 0 - Status printed #
  421. # 1 - Input error. The daemon to check was not specified. #
  422. ################################################################################
  423. statusproc()
  424. {
  425. local pidfile
  426. local pidlist
  427. if [ "${#}" = "0" ]; then
  428. echo "Usage: [-p pidfle] statusproc {program}"
  429. exit 1
  430. fi
  431. # Process arguments
  432. while true; do
  433. case "${1}" in
  434. -p)
  435. pidfile="${2}"
  436. shift 2
  437. ;;
  438. *)
  439. if [ -n "${2}" ]; then
  440. echo "Too many arguments"
  441. return 1
  442. else
  443. break
  444. fi
  445. ;;
  446. esac
  447. done
  448. if [ -z "${pidfile}" ]; then
  449. pidlist=`pidofproc -p "${pidfile}" $@`
  450. else
  451. pidlist=`pidofproc $@`
  452. fi
  453. # Trim trailing blanks
  454. pidlist=`echo "${pidlist}" | sed -r 's/ +$//'`
  455. base="${1##*/}"
  456. if [ -n "${pidlist}" ]; then
  457. echo -e "${INFO}${base} is running with Process" \
  458. "ID(s) ${pidlist}.${NORMAL}"
  459. else
  460. if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then
  461. echo -e "${WARNING}${1} is not running but" \
  462. "/var/run/${base}.pid exists.${NORMAL}"
  463. else
  464. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  465. echo -e "${WARNING}${1} is not running" \
  466. "but ${pidfile} exists.${NORMAL}"
  467. else
  468. echo -e "${INFO}${1} is not running.${NORMAL}"
  469. fi
  470. fi
  471. fi
  472. }
  473. ################################################################################
  474. # timespec() #
  475. # #
  476. # Purpose: An internal utility function to format a timestamp #
  477. # a boot log file. Sets the STAMP variable. #
  478. # #
  479. # Return value: Not used #
  480. ################################################################################
  481. timespec()
  482. {
  483. STAMP="$(echo `date +"%b %d %T %:z"` `hostname`) "
  484. return 0
  485. }
  486. ################################################################################
  487. # log_success_msg() #
  488. # Usage: log_success_msg ["message"] #
  489. # #
  490. # Purpose: Print a successful status message to the screen and #
  491. # a boot log file. #
  492. # #
  493. # Inputs: $@ - Message #
  494. # #
  495. # Return values: Not used #
  496. ################################################################################
  497. log_success_msg()
  498. {
  499. echo -n -e "${BMPREFIX}${@}"
  500. echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
  501. # Strip non-printable characters from log file
  502. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  503. timespec
  504. echo -e "${STAMP} ${logmessage} OK" >> ${BOOTLOG}
  505. return 0
  506. }
  507. log_success_msg2()
  508. {
  509. echo -n -e "${BMPREFIX}${@}"
  510. echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
  511. echo " OK" >> ${BOOTLOG}
  512. return 0
  513. }
  514. ################################################################################
  515. # log_failure_msg() #
  516. # Usage: log_failure_msg ["message"] #
  517. # #
  518. # Purpose: Print a failure status message to the screen and #
  519. # a boot log file. #
  520. # #
  521. # Inputs: $@ - Message #
  522. # #
  523. # Return values: Not used #
  524. ################################################################################
  525. log_failure_msg()
  526. {
  527. echo -n -e "${BMPREFIX}${@}"
  528. echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
  529. # Strip non-printable characters from log file
  530. timespec
  531. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  532. echo -e "${STAMP} ${logmessage} FAIL" >> ${BOOTLOG}
  533. return 0
  534. }
  535. log_failure_msg2()
  536. {
  537. echo -n -e "${BMPREFIX}${@}"
  538. echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
  539. echo "FAIL" >> ${BOOTLOG}
  540. return 0
  541. }
  542. ################################################################################
  543. # log_warning_msg() #
  544. # Usage: log_warning_msg ["message"] #
  545. # #
  546. # Purpose: Print a warning status message to the screen and #
  547. # a boot log file. #
  548. # #
  549. # Return values: Not used #
  550. ################################################################################
  551. log_warning_msg()
  552. {
  553. echo -n -e "${BMPREFIX}${@}"
  554. echo -e "${CURS_ZERO}${WARNING_PREFIX}${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
  555. # Strip non-printable characters from log file
  556. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  557. timespec
  558. echo -e "${STAMP} ${logmessage} WARN" >> ${BOOTLOG}
  559. return 0
  560. }
  561. ################################################################################
  562. # log_info_msg() #
  563. # Usage: log_info_msg message #
  564. # #
  565. # Purpose: Print an information message to the screen and #
  566. # a boot log file. Does not print a trailing newline character. #
  567. # #
  568. # Return values: Not used #
  569. ################################################################################
  570. log_info_msg()
  571. {
  572. echo -n -e "${BMPREFIX}${@}"
  573. # Strip non-printable characters from log file
  574. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  575. timespec
  576. echo -n -e "${STAMP} ${logmessage}" >> ${BOOTLOG}
  577. return 0
  578. }
  579. log_info_msg2()
  580. {
  581. echo -n -e "${@}"
  582. # Strip non-printable characters from log file
  583. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  584. echo -n -e "${logmessage}" >> ${BOOTLOG}
  585. return 0
  586. }
  587. ################################################################################
  588. # evaluate_retval() #
  589. # Usage: Evaluate a return value and print success or failyure as appropriate #
  590. # #
  591. # Purpose: Convenience function to terminate an info message #
  592. # #
  593. # Return values: Not used #
  594. ################################################################################
  595. evaluate_retval()
  596. {
  597. local error_value="${?}"
  598. if [ ${error_value} = 0 ]; then
  599. log_success_msg2
  600. else
  601. log_failure_msg2
  602. fi
  603. }
  604. ################################################################################
  605. # check_signal() #
  606. # Usage: check_signal [ -{signal} | {signal} ] #
  607. # #
  608. # Purpose: Check for a valid signal. This is not defined by any LSB draft, #
  609. # however, it is required to check the signals to determine if the #
  610. # signals chosen are invalid arguments to the other functions. #
  611. # #
  612. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  613. # #
  614. # Return values: #
  615. # 0 - Success (signal is valid #
  616. # 1 - Signal is not valid #
  617. ################################################################################
  618. check_signal()
  619. {
  620. local valsig
  621. # Add error handling for invalid signals
  622. valsig="-ALRM -HUP -INT -KILL -PIPE -POLL -PROF -TERM -USR1 -USR2"
  623. valsig="${valsig} -VTALRM -STKFLT -PWR -WINCH -CHLD -URG -TSTP -TTIN"
  624. valsig="${valsig} -TTOU -STOP -CONT -ABRT -FPE -ILL -QUIT -SEGV -TRAP"
  625. valsig="${valsig} -SYS -EMT -BUS -XCPU -XFSZ -0 -1 -2 -3 -4 -5 -6 -8 -9"
  626. valsig="${valsig} -11 -13 -14 -15"
  627. echo "${valsig}" | grep -- " ${1} " > /dev/null
  628. if [ "${?}" -eq "0" ]; then
  629. return 0
  630. else
  631. return 1
  632. fi
  633. }
  634. ################################################################################
  635. # check_sig_type() #
  636. # Usage: check_signal [ -{signal} | {signal} ] #
  637. # #
  638. # Purpose: Check if signal is a program termination signal or a control signal #
  639. # This is not defined by any LSB draft, however, it is required to #
  640. # check the signals to determine if they are intended to end a #
  641. # program or simply to control it. #
  642. # #
  643. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  644. # #
  645. # Return values: #
  646. # 0 - Signal is used for program termination #
  647. # 1 - Signal is used for program control #
  648. ################################################################################
  649. check_sig_type()
  650. {
  651. local valsig
  652. # The list of termination signals (limited to generally used items)
  653. valsig="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15"
  654. echo "${valsig}" | grep -- " ${1} " > /dev/null
  655. if [ "${?}" -eq "0" ]; then
  656. return 0
  657. else
  658. return 1
  659. fi
  660. }
  661. ################################################################################
  662. # wait_for_user() #
  663. # #
  664. # Purpose: Wait for the user to respond if not a headless system #
  665. # #
  666. ################################################################################
  667. wait_for_user()
  668. {
  669. # Wait for the user by default
  670. [ "${HEADLESS=0}" = "0" ] && read ENTER
  671. return 0
  672. }
  673. # End /lib/lsb/init-functions