File: xen-utils-wrapper

package info (click to toggle)
xen 4.14.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 36,700 kB
  • sloc: ansic: 492,012; asm: 8,191; python: 6,969; makefile: 6,926; sh: 6,593; ml: 5,122; perl: 4,420; cpp: 1,885; lex: 813; yacc: 644; pascal: 489; sed: 4
file content (41 lines) | stat: -rwxr-xr-x 1,033 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh

# This portion is fast-path, avoid external programs, NOTE: NOT -e HERE!

COMMAND="${0##*/}"

DIR=/sys/hypervisor/version
# these return non-zero if hypervisor is absent, this is detected below
read major 2> /dev/null < $DIR/major
read minor 2> /dev/null < $DIR/minor
VERSION="$major.$minor"

DIR="/usr/lib/xen-$VERSION/bin"

[ -x "$DIR/$COMMAND" ] && exec "$DIR/$COMMAND" "$@"


# Certainly didn't work, now report failures, slower-path
set -e

error() {
	err="$1"
	shift
	echo "ERROR: " "$@" >&2
	exit $err
}

[ -e "/sys/hypervisor/type" ] || error 1 "Can't find hypervisor information in sysfs!"

read type < /sys/hypervisor/type
if [ "$type" != xen ]; then
	[ -n "$type" ] || error 1 "Can't read hypervisor type from sysfs!"
	error 1 "Hypervisor is not xen but '$type'!"
fi

if [ ! -d "/usr/lib/xen-$VERSION" ]; then
	error 127 "Can't find version $VERSION of xen utils (maybe xen-utils-$VERSION was already removed before rebooting out of Xen $VERSION), bailing out!"
fi

error 127 "Unable to execute $DIR/$COMMAND"