source: trunk/packages/xen-3.1/xen-3.1/tools/examples/xen-hotplug-common.sh @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 2.2 KB
Line 
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#
17
18
19dir=$(dirname "$0")
20. "$dir/logging.sh"
21. "$dir/xen-script-common.sh"
22. "$dir/locking.sh"
23
24exec 2>>/var/log/xen/xen-hotplug.log
25
26export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
27export LANG="POSIX"
28unset $(set | grep ^LC_ | cut -d= -f1)
29
30fatal() {
31  xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
32                 "$XENBUS_PATH/hotplug-status" error
33  log err "$@"
34  exit 1
35}
36
37success() {
38  # Tell DevController that backend is "connected"
39  xenstore_write "$XENBUS_PATH/hotplug-status" connected
40}
41
42do_or_die() {
43  "$@" || fatal "$@ failed"
44}
45
46do_without_error() {
47  "$@" 2>/dev/null || log debug "$@ failed"
48}
49
50sigerr() {
51  fatal "$0 failed; error detected."
52}
53
54trap sigerr ERR
55
56
57##
58# xenstore_read <path>+
59#
60# Read each of the given paths, returning each result on a separate line, or
61# exit this script if any of the paths is missing.
62#
63xenstore_read() {
64  local v=$(xenstore-read "$@" || true)
65  [ "$v" != "" ] || fatal "xenstore-read $@ failed."
66  echo "$v"
67}
68
69
70##
71# xenstore_read_default <path> <default>
72#
73# Read the given path, returning the value there or the given default if the
74# path is not present.
75#
76xenstore_read_default() {
77  xenstore-read "$1" 2>/dev/null || echo "$2"
78}
79
80
81##
82# xenstore_write (<path> <value>)+
83#
84# Write each of the key/value pairs to the store, and exit this script if any
85# such writing fails.
86#
87xenstore_write() {
88  log debug "Writing $@ to xenstore."
89  xenstore-write "$@" || fatal "Writing $@ to xenstore failed."
90}
91
92
93log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
Note: See TracBrowser for help on using the repository browser.