OSDN Git Service

Update to lfsbook 7.2.ja
[linuxjf/JF.git] / docs / LFS-BOOK / scripts / apds02.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4   <head>
5     <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
6     <title>
7       D.2. /lib/lsb/init-functions
8     </title>
9     <link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
10     <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
11     <link rel="stylesheet" href="../stylesheets/lfs-print.css" type=
12     "text/css" media="print" />
13   </head>
14   <body class="lfs" id="lfs-7.2">
15     <div class="navheader">
16       <h4>
17         Linux From Scratch - Version 7.2
18       </h4>
19       <h3>
20         付録 D. ブートスクリプトと sysconfig スクリプト version-20120901
21       </h3>
22       <ul>
23         <li class="prev">
24           <a accesskey="p" href="apds01.html" title=
25           "/etc/rc.d/init.d/rc">前のページ</a>
26           <p>
27             /etc/rc.d/init.d/rc
28           </p>
29         </li>
30         <li class="next">
31           <a accesskey="n" href="apds03.html" title=
32           "/etc/rc.d/init.d/functions">次のページ</a>
33           <p>
34             /etc/rc.d/init.d/functions
35           </p>
36         </li>
37         <li class="up">
38           <a accesskey="u" href="scripts.html" title=
39           "付録 D. ブートスクリプトと sysconfig スクリプト version-20120901">上に戻る</a>
40         </li>
41         <li class="home">
42           <a accesskey="h" href="../index.html" title=
43           "Linux From Scratch - Version 7.2">ホーム</a>
44         </li>
45       </ul>
46     </div>
47     <div class="wrap" lang="ja" xml:lang="ja">
48       <h1 class="sect1">
49         <a id="init-functions" name="init-functions"></a>D.2.
50         /lib/lsb/init-functions
51       </h1>
52       <pre class="screen">
53 #!/bin/sh
54 ########################################################################
55
56 # Begin /lib/lsb/init-funtions
57 #
58 # Description : Run Level Control Functions
59 #
60 # Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
61 #             : DJ Lucas - dj@linuxfromscratch.org
62 # Update      : Bruce Dubbs - bdubbs@linuxfromscratch.org
63 #
64 # Version     : LFS 7.0
65 #
66 # Notes       : With code based on Matthias Benkmann's simpleinit-msb
67 #               http://winterdrache.de/linux/newboot/index.html
68 #
69 #               The file should be located in /lib/lsb
70 #
71 ########################################################################
72
73 ## Environmental setup
74 # Setup default values for environment
75 umask 022
76 export PATH="/bin:/usr/bin:/sbin:/usr/sbin"
77
78 ## Screen Dimensions
79 # Find current screen size
80 if [ -z "${COLUMNS}" ]; then
81    COLUMNS=$(stty size)
82    COLUMNS=${COLUMNS##* }
83 fi
84
85 # When using remote connections, such as a serial port, stty size returns 0
86 if [ "${COLUMNS}" = "0" ]; then
87    COLUMNS=80
88 fi
89
90 ## Measurements for positioning result messages
91 COL=$((${COLUMNS} - 8))
92 WCOL=$((${COL} - 2))
93
94 ## Set Cursor Position Commands, used via echo
95 SET_COL="\\033[${COL}G"      # at the $COL char
96 SET_WCOL="\\033[${WCOL}G"    # at the $WCOL char
97 CURS_UP="\\033[1A\\033[0G"   # Up one line, at the 0'th char
98 CURS_ZERO="\\033[0G"
99
100 ## Set color commands, used via echo
101 # Please consult `man console_codes for more information
102 # under the "ECMA-48 Set Graphics Rendition" section
103 #
104 # Warning: when switching from a 8bit to a 9bit font,
105 # the linux console will reinterpret the bold (1;) to
106 # the top 256 glyphs of the 9bit font.  This does
107 # not affect framebuffer consoles
108
109 NORMAL="\\033[0;39m"         # Standard console grey
110 SUCCESS="\\033[1;32m"        # Success is green
111 WARNING="\\033[1;33m"        # Warnings are yellow
112 FAILURE="\\033[1;31m"        # Failures are red
113 INFO="\\033[1;36m"           # Information is light cyan
114 BRACKET="\\033[1;34m"        # Brackets are blue
115
116 # Use a colored prefix
117 BMPREFIX="     "
118 SUCCESS_PREFIX="${SUCCESS}  *  ${NORMAL}"
119 FAILURE_PREFIX="${FAILURE}*****${NORMAL}"
120 WARNING_PREFIX="${WARNING} *** ${NORMAL}"
121
122 SUCCESS_SUFFIX="${BRACKET}[${SUCCESS}  OK  ${BRACKET}]${NORMAL}"
123 FAILURE_SUFFIX="${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
124 WARNING_SUFFIX="${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
125
126 BOOTLOG=/run/var/bootlog
127 KILLDELAY=3
128
129 # Set any user specified environment variables e.g. HEADLESS
130 [ -r /etc/sysconfig/rc.site ]  &amp;&amp; . /etc/sysconfig/rc.site
131
132 ################################################################################
133 # start_daemon()                                                               #
134 # Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...]      #
135 #                                                                              #
136 # Purpose: This runs the specified program as a daemon                         #
137 #                                                                              #
138 # Inputs: -f: (force) run the program even if it is already running.           #
139 #         -n nicelevel: specify a nice level. See 'man nice(1)'.               #
140 #         -p pidfile: use the specified file to determine PIDs.                #
141 #         pathname: the complete path to the specified program                 #
142 #         args: additional arguments passed to the program (pathname)          #
143 #                                                                              #
144 # Return values (as defined by LSB exit codes):                                #
145 #       0 - program is running or service is OK                                #
146 #       1 - generic or unspecified error                                       #
147 #       2 - invalid or excessive argument(s)                                   #
148 #       5 - program is not installed                                           #
149 ################################################################################
150 start_daemon()
151 {
152     local force=""
153     local nice="0"
154     local pidfile=""
155     local pidlist=""
156     local retval=""
157
158     # Process arguments
159     while true
160     do
161         case "${1}" in
162
163             -f)
164                 force="1"
165                 shift 1
166                 ;;
167
168             -n)
169                 nice="${2}"
170                 shift 2
171                 ;;
172
173             -p)
174                 pidfile="${2}"
175                 shift 2
176                 ;;
177
178             -*)
179                 return 2
180                 ;;
181
182             *)
183                 program="${1}"
184                 break
185                 ;;
186         esac
187     done
188
189     # Check for a valid program
190     if [ ! -e "${program}" ]; then return 5; fi
191
192     # Execute
193     if [ -z "${force}" ]; then
194         if [ -z "${pidfile}" ]; then
195             # Determine the pid by discovery
196             pidlist=`pidofproc "${1}"`
197             retval="${?}"
198         else
199             # The PID file contains the needed PIDs
200             # Note that by LSB requirement, the path must be given to pidofproc,
201             # however, it is not used by the current implementation or standard.
202             pidlist=`pidofproc -p "${pidfile}" "${1}"`
203             retval="${?}"
204         fi
205
206         # Return a value ONLY 
207         # It is the init script's (or distribution's functions) responsibilty
208         # to log messages!
209         case "${retval}" in
210
211             0)
212                 # Program is already running correctly, this is a 
213                 # successful start.
214                 return 0
215                 ;;
216
217             1)
218                 # Program is not running, but an invalid pid file exists
219                 # remove the pid file and continue
220                 rm -f "${pidfile}"
221                 ;;
222
223             3)
224                 # Program is not running and no pidfile exists
225                 # do nothing here, let start_deamon continue.
226                 ;;
227
228             *)
229                 # Others as returned by status values shall not be interpreted
230                 # and returned as an unspecified error.
231                 return 1
232                 ;;
233         esac
234     fi
235
236     # Do the start!
237     nice -n "${nice}" "${@}"
238 }
239
240 ################################################################################
241 # killproc()                                                                   #
242 # Usage: killproc [-p pidfile] pathname [signal]                               #
243 #                                                                              #
244 # Purpose: Send control signals to running processes                           #
245 #                                                                              #
246 # Inputs: -p pidfile, uses the specified pidfile                               #
247 #         pathname, pathname to the specified program                          #
248 #         signal, send this signal to pathname                                 #
249 #                                                                              #
250 # Return values (as defined by LSB exit codes):                                #
251 #       0 - program (pathname) has stopped/is already stopped or a             #
252 #           running program has been sent specified signal and stopped         #
253 #           successfully                                                       #
254 #       1 - generic or unspecified error                                       #
255 #       2 - invalid or excessive argument(s)                                   #
256 #       5 - program is not installed                                           #
257 #       7 - program is not running and a signal was supplied                   #
258 ################################################################################
259 killproc()
260 {
261     local pidfile
262     local program
263     local prefix
264     local progname
265     local signal="-TERM"
266     local fallback="-KILL"
267     local nosig
268     local pidlist
269     local retval
270     local pid
271     local delay="30"
272     local piddead
273     local dtime
274
275     # Process arguments
276     while true; do
277         case "${1}" in
278             -p)
279                 pidfile="${2}"
280                 shift 2
281                 ;;
282  
283              *)
284                  program="${1}"
285                  if [ -n "${2}" ]; then
286                      signal="${2}"
287                      fallback=""
288                  else
289                      nosig=1
290                  fi
291
292                  # Error on additional arguments
293                  if [ -n "${3}" ]; then
294                      return 2
295                  else 
296                      break
297                  fi                 
298                  ;;
299         esac
300     done
301
302     # Check for a valid program
303     if [ ! -e "${program}" ]; then return 5; fi
304
305     # Check for a valid signal
306     check_signal "${signal}"
307     if [ "${?}" -ne "0" ]; then return 2; fi
308
309     # Get a list of pids
310     if [ -z "${pidfile}" ]; then
311         # determine the pid by discovery
312         pidlist=`pidofproc "${1}"`
313         retval="${?}"
314     else
315         # The PID file contains the needed PIDs
316         # Note that by LSB requirement, the path must be given to pidofproc,
317         # however, it is not used by the current implementation or standard.
318         pidlist=`pidofproc -p "${pidfile}" "${1}"`
319         retval="${?}"
320     fi
321
322     # Return a value ONLY
323     # It is the init script's (or distribution's functions) responsibilty
324     # to log messages!
325     case "${retval}" in
326
327         0)
328             # Program is running correctly
329             # Do nothing here, let killproc continue.
330             ;;
331
332         1)
333             # Program is not running, but an invalid pid file exists
334             # Remove the pid file.
335             rm -f "${pidfile}"
336
337             # This is only a success if no signal was passed.
338             if [ -n "${nosig}" ]; then
339                 return 0
340             else
341                 return 7
342             fi
343             ;;
344
345         3)
346             # Program is not running and no pidfile exists
347             # This is only a success if no signal was passed.
348             if [ -n "${nosig}" ]; then
349                 return 0
350             else
351                 return 7
352             fi
353             ;;
354
355         *)
356             # Others as returned by status values shall not be interpreted
357             # and returned as an unspecified error.
358             return 1
359             ;;
360     esac
361
362     # Perform different actions for exit signals and control signals
363     check_sig_type "${signal}"
364
365     if [ "${?}" -eq "0" ]; then # Signal is used to terminate the program
366
367         # Account for empty pidlist (pid file still exists and no 
368         # signal was given)
369         if [ "${pidlist}" != "" ]; then
370
371             # Kill the list of pids
372             for pid in ${pidlist}; do
373
374                 kill -0 "${pid}" 2&gt; /dev/null
375
376                 if [ "${?}" -ne "0" ]; then
377                     # Process is dead, continue to next and assume all is well
378                     continue
379                 else
380                     kill "${signal}" "${pid}" 2&gt; /dev/null
381
382                     # Wait up to ${delay}/10 seconds to for "${pid}" to 
383                     # terminate in 10ths of a second
384
385                     while [ "${delay}" -ne "0" ]; do
386                         kill -0 "${pid}" 2&gt; /dev/null || piddead="1"
387                         if [ "${piddead}" = "1" ]; then break; fi
388                         sleep 0.1
389                         delay="$(( ${delay} - 1 ))"
390                     done
391
392                     # If a fallback is set, and program is still running, then
393                     # use the fallback
394                     if [ -n "${fallback}" -a "${piddead}" != "1" ]; then
395                         kill "${fallback}" "${pid}" 2&gt; /dev/null
396                         sleep 1
397                         # Check again, and fail if still running
398                         kill -0 "${pid}" 2&gt; /dev/null &amp;&amp; return 1
399                     else
400                         # just check one last time and if still alive, fail
401                         sleep 1
402                         kill -0 "${pid}" 2&gt; /dev/null &amp;&amp; return 1
403                     fi
404                 fi
405             done
406         fi
407
408         # Check for and remove stale PID files.
409         if [ -z "${pidfile}" ]; then
410             # Find the basename of $program
411             prefix=`echo "${program}" | sed 's/[^/]*$//'`
412             progname=`echo "${program}" | sed "s@${prefix}@@"`
413
414             if [ -e "/var/run/${progname}.pid" ]; then
415                 rm -f "/var/run/${progname}.pid" 2&gt; /dev/null
416             fi
417         else
418             if [ -e "${pidfile}" ]; then rm -f "${pidfile}" 2&gt; /dev/null; fi
419         fi
420
421     # For signals that do not expect a program to exit, simply
422     # let kill do it's job, and evaluate kills return for value
423
424     else # check_sig_type - signal is not used to terminate program
425         for pid in ${pidlist}; do
426             kill "${signal}" "${pid}"
427             if [ "${?}" -ne "0" ]; then return 1; fi
428         done
429     fi
430 }
431
432 ################################################################################
433 # pidofproc()                                                                  #
434 # Usage: pidofproc [-p pidfile] pathname                                       #
435 #                                                                              #
436 # Purpose: This function returns one or more pid(s) for a particular daemon    #
437 #                                                                              #
438 # Inputs: -p pidfile, use the specified pidfile instead of pidof               #
439 #         pathname, path to the specified program                              #
440 #                                                                              #
441 # Return values (as defined by LSB status codes):                              #
442 #       0 - Success (PIDs to stdout)                                           #
443 #       1 - Program is dead, PID file still exists (remaining PIDs output)     #
444 #       3 - Program is not running (no output)                                 #
445 ################################################################################
446 pidofproc()
447 {
448     local pidfile
449     local program
450     local prefix
451     local progname
452     local pidlist
453     local lpids
454     local exitstatus="0"
455
456     # Process arguments
457     while true; do
458         case "${1}" in
459
460             -p)
461                 pidfile="${2}"
462                 shift 2
463                 ;;
464
465             *)
466                 program="${1}"
467                 if [ -n "${2}" ]; then
468                     # Too many arguments
469                     # Since this is status, return unknown
470                     return 4
471                 else
472                     break
473                 fi
474                 ;;
475         esac
476     done
477
478     # If a PID file is not specified, try and find one.
479     if [ -z "${pidfile}" ]; then
480         # Get the program's basename
481         prefix=`echo "${program}" | sed 's/[^/]*$//'`
482
483         if [ -z "${prefix}" ]; then 
484            progname="${program}"
485         else
486            progname=`echo "${program}" | sed "s@${prefix}@@"`
487         fi
488
489         # If a PID file exists with that name, assume that is it.
490         if [ -e "/var/run/${progname}.pid" ]; then
491             pidfile="/var/run/${progname}.pid"
492         fi
493     fi
494
495     # If a PID file is set and exists, use it.
496     if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
497
498         # Use the value in the first line of the pidfile
499         pidlist=`/bin/head -n1 "${pidfile}"`
500         # This can optionally be written as 'sed 1q' to repalce 'head -n1'
501         # should LFS move /bin/head to /usr/bin/head
502     else
503         # Use pidof
504         pidlist=`pidof "${program}"`
505     fi
506
507     # Figure out if all listed PIDs are running.
508     for pid in ${pidlist}; do
509         kill -0 ${pid} 2&gt; /dev/null
510
511         if [ "${?}" -eq "0" ]; then
512             lpids="${lpids}${pid} "
513         else
514             exitstatus="1"
515         fi
516     done
517
518     if [ -z "${lpids}" -a ! -f "${pidfile}" ]; then
519         return 3
520     else
521         echo "${lpids}"
522         return "${exitstatus}"
523     fi
524 }
525
526 ################################################################################
527 # statusproc()                                                                 #
528 # Usage: statusproc [-p pidfile] pathname                                      #
529 #                                                                              #
530 # Purpose: This function prints the status of a particular daemon to stdout    #
531 #                                                                              #
532 # Inputs: -p pidfile, use the specified pidfile instead of pidof               #
533 #         pathname, path to the specified program                              #
534 #                                                                              #
535 # Return values:                                                               #
536 #       0 - Status printed                                                     #
537 #       1 - Input error. The daemon to check was not specified.                #
538 ################################################################################
539 statusproc()
540 {
541    local pidfile
542    local pidlist
543
544    if [ "${#}" = "0" ]; then
545       echo "Usage: statusproc [-p pidfle] {program}"
546       exit 1
547    fi
548
549    # Process arguments
550    while true; do
551        case "${1}" in
552
553            -p)
554                pidfile="${2}"
555                shift 2
556                ;;
557
558            *)
559                if [ -n "${2}" ]; then
560                    echo "Too many arguments"
561                    return 1
562                else
563                    break
564                fi
565                ;;
566        esac
567    done
568
569    if [ -n "${pidfile}" ]; then
570       pidlist=`pidofproc -p "${pidfile}" $@`
571    else
572       pidlist=`pidofproc $@`
573    fi
574
575    # Trim trailing blanks
576    pidlist=`echo "${pidlist}" | sed -r 's/ +$//'`
577
578    base="${1##*/}"
579
580    if [ -n "${pidlist}" ]; then
581       echo -e "${INFO}${base} is running with Process" \
582          "ID(s) ${pidlist}.${NORMAL}"
583    else
584       if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then
585          echo -e "${WARNING}${1} is not running but" \
586             "/var/run/${base}.pid exists.${NORMAL}"
587       else
588          if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
589             echo -e "${WARNING}${1} is not running" \
590                "but ${pidfile} exists.${NORMAL}"
591          else
592             echo -e "${INFO}${1} is not running.${NORMAL}"
593          fi
594       fi
595    fi
596 }
597
598 ################################################################################
599 # timespec()                                                                   #
600 #                                                                              #
601 # Purpose: An internal utility function to format a timestamp                  #
602 #          a boot log file.  Sets the STAMP variable.                          #
603 #                                                                              #
604 # Return value: Not used                                                       #
605 ################################################################################
606 timespec()
607 {
608    STAMP="$(echo `date +"%b %d %T %:z"` `hostname`) "
609    return 0
610 }
611
612 ################################################################################
613 # log_success_msg()                                                            #
614 # Usage: log_success_msg ["message"]                                           #
615 #                                                                              #
616 # Purpose: Print a successful status message to the screen and                 #
617 #          a boot log file.                                                    #
618 #                                                                              #
619 # Inputs: $@ - Message                                                         #
620 #                                                                              #
621 # Return values: Not used                                                      #
622 ################################################################################
623 log_success_msg()
624 {
625     echo -n -e "${BMPREFIX}${@}"
626     echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
627
628     # Strip non-printable characters from log file
629     local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
630
631     timespec
632     echo -e "${STAMP} ${logmessage} OK" &gt;&gt; ${BOOTLOG}
633     
634     return 0
635 }
636
637 log_success_msg2()
638 {
639     echo -n -e "${BMPREFIX}${@}"
640     echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
641
642     echo " OK" &gt;&gt; ${BOOTLOG}
643     
644     return 0
645 }
646
647 ################################################################################
648 # log_failure_msg()                                                            #
649 # Usage: log_failure_msg ["message"]                                           #
650 #                                                                              #
651 # Purpose: Print a failure status message to the screen and                    #
652 #          a boot log file.                                                    #
653 #                                                                              #
654 # Inputs: $@ - Message                                                         #
655 #                                                                              #
656 # Return values: Not used                                                      #
657 ################################################################################
658 log_failure_msg()
659 {
660     echo -n -e "${BMPREFIX}${@}"
661     echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
662
663     # Strip non-printable characters from log file
664
665     timespec
666     local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
667     echo -e "${STAMP} ${logmessage} FAIL" &gt;&gt; ${BOOTLOG}
668     
669     return 0
670 }
671
672 log_failure_msg2()
673 {
674     echo -n -e "${BMPREFIX}${@}"
675     echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
676
677     echo "FAIL" &gt;&gt; ${BOOTLOG}
678     
679     return 0
680 }
681
682 ################################################################################
683 # log_warning_msg()                                                            #
684 # Usage: log_warning_msg ["message"]                                           #
685 #                                                                              #
686 # Purpose: Print a warning status message to the screen and                    #
687 #          a boot log file.                                                    #
688 #                                                                              #
689 # Return values: Not used                                                      #
690 ################################################################################
691 log_warning_msg()
692 {
693     echo -n -e "${BMPREFIX}${@}"
694     echo -e "${CURS_ZERO}${WARNING_PREFIX}${SET_COL}${WARNING_SUFFIX}"
695
696     # Strip non-printable characters from log file
697     local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
698     timespec
699     echo -e "${STAMP} ${logmessage} WARN" &gt;&gt; ${BOOTLOG}
700     
701     return 0
702 }
703
704 ################################################################################
705 # log_info_msg()                                                               #
706 # Usage: log_info_msg message                                                  #
707 #                                                                              #
708 # Purpose: Print an information message to the screen and                      #
709 #          a boot log file.  Does not print a trailing newline character.      #
710 #                                                                              #
711 # Return values: Not used                                                      #
712 ################################################################################
713 log_info_msg()
714 {
715     echo -n -e "${BMPREFIX}${@}"
716
717     # Strip non-printable characters from log file
718     local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
719     timespec
720     echo -n -e "${STAMP} ${logmessage}" &gt;&gt; ${BOOTLOG}
721     
722     return 0
723 }
724
725 log_info_msg2()
726 {
727     echo -n -e "${@}"
728
729     # Strip non-printable characters from log file
730     local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
731     echo -n -e "${logmessage}" &gt;&gt; ${BOOTLOG}
732     
733     return 0
734 }
735
736 ################################################################################
737 # evaluate_retval()                                                            #
738 # Usage: Evaluate a return value and print success or failyure as appropriate  #
739 #                                                                              #
740 # Purpose: Convenience function to terminate an info message                   #
741 #                                                                              #
742 # Return values: Not used                                                      #
743 ################################################################################
744 evaluate_retval()
745 {
746    local error_value="${?}"
747
748    if [ ${error_value} = 0 ]; then
749       log_success_msg2
750    else
751       log_failure_msg2
752    fi
753 }
754
755 ################################################################################
756 # check_signal()                                                               #
757 # Usage: check_signal [ -{signal} | {signal} ]                                 #
758 #                                                                              #
759 # Purpose: Check for a valid signal.  This is not defined by any LSB draft,    #
760 #          however, it is required to check the signals to determine if the    #
761 #          signals chosen are invalid arguments to the other functions.        #
762 #                                                                              #
763 # Inputs: Accepts a single string value in the form or -{signal} or {signal}   #
764 #                                                                              #
765 # Return values:                                                               #
766 #       0 - Success (signal is valid                                           #
767 #       1 - Signal is not valid                                                #
768 ################################################################################
769 check_signal()
770 {
771     local valsig
772
773     # Add error handling for invalid signals
774     valsig="-ALRM -HUP -INT -KILL -PIPE -POLL -PROF -TERM -USR1 -USR2"
775     valsig="${valsig} -VTALRM -STKFLT -PWR -WINCH -CHLD -URG -TSTP -TTIN"
776     valsig="${valsig} -TTOU -STOP -CONT -ABRT -FPE -ILL -QUIT -SEGV -TRAP"
777     valsig="${valsig} -SYS -EMT -BUS -XCPU -XFSZ -0 -1 -2 -3 -4 -5 -6 -8 -9"
778     valsig="${valsig} -11 -13 -14 -15"
779
780     echo "${valsig}" | grep -- " ${1} " &gt; /dev/null
781
782     if [ "${?}" -eq "0" ]; then
783         return 0
784     else
785         return 1
786     fi
787 }
788
789 ################################################################################
790 # check_sig_type()                                                             #
791 # Usage: check_signal [ -{signal} | {signal} ]                                 #
792 #                                                                              #
793 # Purpose: Check if signal is a program termination signal or a control signal #
794 #          This is not defined by any LSB draft, however, it is required to    #
795 #          check the signals to determine if they are intended to end a        #
796 #          program or simply to control it.                                    #
797 #                                                                              #
798 # Inputs: Accepts a single string value in the form or -{signal} or {signal}   #
799 #                                                                              #
800 # Return values:                                                               #
801 #       0 - Signal is used for program termination                             #
802 #       1 - Signal is used for program control                                 #
803 ################################################################################
804 check_sig_type()
805 {
806     local valsig
807
808     # The list of termination signals (limited to generally used items)
809     valsig="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15"
810
811     echo "${valsig}" | grep -- " ${1} " &gt; /dev/null
812
813     if [ "${?}" -eq "0" ]; then
814         return 0
815     else
816         return 1
817     fi
818 }
819
820 ################################################################################
821 # wait_for_user()                                                              #
822 #                                                                              #
823 # Purpose: Wait for the user to respond if not a headless system               #
824 #                                                                              #
825 ################################################################################
826 wait_for_user()
827 {
828    # Wait for the user by default
829    [ "${HEADLESS=0}" = "0" ] &amp;&amp; read ENTER
830    return 0
831 }
832
833 ################################################################################
834 # is_true()                                                                    #
835 #                                                                              #
836 # Purpose: Utility to test if a variable is true | yes | 1                     #
837 #                                                                              #
838 ################################################################################
839 is_true()
840 {
841    [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] ||  [ "$1" = "y" ] ||
842    [ "$1" = "t" ]
843 }
844
845 # End /lib/lsb/init-functions
846 </pre>
847     </div>
848     <div class="navfooter">
849       <ul>
850         <li class="prev">
851           <a accesskey="p" href="apds01.html" title=
852           "/etc/rc.d/init.d/rc">前のページ</a>
853           <p>
854             /etc/rc.d/init.d/rc
855           </p>
856         </li>
857         <li class="next">
858           <a accesskey="n" href="apds03.html" title=
859           "/etc/rc.d/init.d/functions">次のページ</a>
860           <p>
861             /etc/rc.d/init.d/functions
862           </p>
863         </li>
864         <li class="up">
865           <a accesskey="u" href="scripts.html" title=
866           "付録 D. ブートスクリプトと sysconfig スクリプト version-20120901">上に戻る</a>
867         </li>
868         <li class="home">
869           <a accesskey="h" href="../index.html" title=
870           "Linux From Scratch - Version 7.2">ホーム</a>
871         </li>
872       </ul>
873     </div>
874   </body>
875 </html>