#!/bin/bash

if test "$#" -ne 2; then
    exit 1
fi

channel_path="$1"
channel_num="$2"

name="`xenstore-read \"$channel_path\"/name`"
test -z "$name" && exit 1

if test $name != "org.qemu.guest_agent.0"; then
    exit 1
fi

mkdir -p /dev/xenchannel
devname=/dev/xenchannel/$name
# Xen's console devices are used for channels. See xen-pv-channel(7)
# for more details
ln -sfn /dev/hvc$channel_num $devname

echo "XEN_CHANNEL_NAME=$name"
