ia64/xen-unstable

view tools/examples/xen-hotplug-common.sh @ 10098:48c0f5489d44

Remove Emacs variables settings from tail of our Linux files.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu May 18 11:39:03 2006 +0100 (2006-05-18)
parents 911f3ecd975e
children 3798ec84431d
line source
1 #
2 # Copyright (c) 2005 XenSource Ltd.
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of version 2.1 of the GNU Lesser General Public
6 # License as published by the Free Software Foundation.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
19 dir=$(dirname "$0")
20 . "$dir/logging.sh"
21 . "$dir/xen-script-common.sh"
22 . "$dir/locking.sh"
24 exec 2>>/var/log/xen-hotplug.log
26 export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
27 export LANG="POSIX"
28 unset $(set | grep ^LC_ | cut -d= -f1)
30 fatal() {
31 xenstore_write "$XENBUS_PATH"/hotplug-status error
32 log err "$@"
33 exit 1
34 }
36 success() {
37 # Tell DevController that backend is "connected"
38 xenstore_write "$XENBUS_PATH"/hotplug-status connected
39 }
41 do_or_die() {
42 "$@" || fatal "$@ failed"
43 }
45 do_without_error() {
46 "$@" 2>/dev/null || log debug "$@ failed"
47 }
49 sigerr() {
50 fatal "$0 failed; error detected."
51 }
53 trap sigerr ERR
56 ##
57 # xenstore_read <path>+
58 #
59 # Read each of the given paths, returning each result on a separate line, or
60 # exit this script if any of the paths is missing.
61 #
62 xenstore_read() {
63 local v=$(xenstore-read "$@" || true)
64 [ "$v" != "" ] || fatal "xenstore-read $@ failed."
65 echo "$v"
66 }
69 ##
70 # xenstore_read_default <path> <default>
71 #
72 # Read the given path, returning the value there or the given default if the
73 # path is not present.
74 #
75 xenstore_read_default() {
76 xenstore-read "$1" 2>/dev/null || echo "$2"
77 }
80 ##
81 # xenstore_write (<path> <value>)+
82 #
83 # Write each of the key/value pairs to the store, and exit this script if any
84 # such writing fails.
85 #
86 xenstore_write() {
87 log debug "Writing $@ to xenstore."
88 xenstore-write "$@" || fatal "Writing $@ to xenstore failed."
89 }
92 log debug "$@" "XENBUS_PATH=$XENBUS_PATH"