Paul Sutor
2019-Jul-17 22:05 UTC
[Pkg-xen-devel] Bug#932336: xen-utils-common: vif-nat exits with code 1 even if successful
Package: xen-utils-common Version: 4.11.1+92-g6c33308a8d-2 Severity: normal Dear Maintainer, This happened after upgrading from Debian 9 to Debian 10, and also after commenting out line 88 of /etc/xen/scripts/vif-nat. After I worked around another bug (which hasn't been assigned a number yet - "vif-nat fails to find backend/vif/x/x/domain") in vif-nat on Debian 10, vif-nat still said it was returning code 1 and was thus still preventing domUs from being created. As I attempted to add "echo"s to the script to find out where it was erroring out, to my surprise I found that just adding the echos made the script work! I narrowed it down to one strategic place to add an "echo" to let the script work normally: before the "handle_iptable" on line 182. I don't know why this makes it work - perhaps an exit code is being carried through where it shouldn't. Thanks, Paul Sutor -- System Information: Debian Release: 10.0 APT prefers stable APT policy: (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 4.19.0-5-amd64 (SMP w/32 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages xen-utils-common depends on: ii libc6 2.28-10 ii libxenstore3.0 4.11.1+92-g6c33308a8d-2 ii lsb-base 10.2019051400 ii python 2.7.16-1 ii ucf 3.0038+nmu1 ii udev 241-5 ii xenstore-utils 4.11.1+92-g6c33308a8d-2 xen-utils-common recommends no packages. Versions of packages xen-utils-common suggests: pn xen-doc <none> -- Configuration Files: /etc/default/xendomains changed: XENDOMAINS_RESTORE=false XENDOMAINS_AUTO=/etc/xen/auto XENDOMAINS_STOP_MAXWAIT=300 /etc/xen/scripts/vif-nat changed: dir=$(dirname "$0") . "$dir/vif-common.sh" if [ -f /etc/dhcpd.conf ] then dhcp=${dhcp:-yes} else dhcp=${dhcp:-no} fi if [ "$dhcp" != 'no' ] then dhcpd_conf_file=$(find_dhcpd_conf_file) dhcpd_init_file=$(find_dhcpd_init_file) dhcpd_arg_file=$(find_dhcpd_arg_file) if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ] || [ -z "$dhcpd_arg_file" ] then echo 'Failed to find dhcpd configuration or init or args file.' >&2 exit 1 fi fi domid=$(xenstore_read "$XENBUS_PATH/frontend-id") vifid=$(xenstore_read "$XENBUS_PATH/handle") vifid=$(( $vifid + 1 )) ip_from_dom() { local domid1=$(( $domid / 256 )) local domid2=$(( $domid % 256 )) echo "10.$domid1.$domid2.$vifid/16" } routing_ip() { echo $(echo $1 | awk -F. '{print $1"."$2"."$3"."$4 + 127}') } dotted_quad() { echo\ $(( ($1 & 0xFF000000) >> 24))\ .$(( ($1 & 0x00FF0000) >> 16))\ .$(( ($1 & 0x0000FF00) >> 8 ))\ .$(( $1 & 0x000000FF )) } if [ "$ip" = "" ] then ip=$(ip_from_dom) fi router_ip=$(routing_ip "$ip") vif_ip=`echo ${ip} | awk -F/ '{print $1}'` if [ "$vifid" != "1" ] then hostname="$hostname-$vifid" fi dhcparg_remove_entry() { local tmpfile=$(mktemp) sed -e "s/${dev} //" "$dhcpd_arg_file" >"$tmpfile" if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null then rm "$tmpfile" else mv "$tmpfile" "$dhcpd_arg_file" fi } dhcparg_add_entry() { dhcparg_remove_entry local tmpfile=$(mktemp) # handle Red Hat, SUSE, and Debian styles, with or without quotes sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \ "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \ "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \ "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" rm -f "$tmpfile" } dhcp_remove_entry() { local tmpfile=$(mktemp) grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile" if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null then rm "$tmpfile" else mv "$tmpfile" "$dhcpd_conf_file" fi dhcparg_remove_entry } dhcp_up() { claim_lock "vif-nat-dhcp" dhcp_remove_entry mac=$(xenstore_read "$XENBUS_PATH/mac") echo >>"$dhcpd_conf_file" \ "host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; option host-name \"$hostname\"; }" dhcparg_add_entry release_lock "vif-nat-dhcp" "$dhcpd_init_file" restart || true } dhcp_down() { claim_lock "vif-nat-dhcp" dhcp_remove_entry release_lock "vif-nat-dhcp" "$dhcpd_init_file" restart || true # We need to ignore failure because # ISC dhcpd 3 borks if there is nothing # for it to do, which is the case if # the outgoing interface is not # configured to offer leases and there # are no vifs. } case "$command" in online) if ip route | grep -q "dev ${dev}" then log debug "${dev} already up" exit 0 fi do_or_die ip link set dev "${dev}" up arp on do_or_die ip addr add "$router_ip" dev "${dev}" do_or_die ip route add "$vif_ip" dev "${dev}" src "$router_ip" echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp [ "$dhcp" != 'no' ] && dhcp_up ;; offline) [ "$dhcp" != 'no' ] && dhcp_down do_without_error ifconfig "${dev}" down ;; esac echo hi handle_iptable call_hooks vif post log debug "Successful vif-nat $command for ${dev}." if [ "$command" = "online" ] then success fi /etc/xen/xend-config.sxp changed: (dom0-min-mem 640) (enable-dom0-ballooning yes) (total_available_memory 0) (dom0-cpus 0) (vncpasswd '') /etc/xen/xl.conf changed: vif.default.script="vif-nat" -- no debconf information
Stephan Beyer
2019-Sep-17 23:21 UTC
[Pkg-xen-devel] Bug#932336: xen-utils-common: vif-nat exits with code 1 even if successful
I stumbled over exactly the same issue today, tried to narrow it down by adding debug messages to the script, and suddenly it worked. I think the bad guy is [ "$dhcp" != 'no' ] && dhcp_up which returns 1 in case no dhcp is used. Maybe using "if" here is better... Also handle_iptable (in vif-common.sh) only does a "return" which again returns 1. Maybe using "return 0" here is better... The question (for me) is why this leads to an exit. Even if "set -e" is used in some scripts, why does it exit at handle_iptable() and not already after the false [ "$dhcp" != 'no' ]? Stephan