From 7b10faf47aa46e3bbcff87acafed7ac4710c2139 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Thu, 5 Jul 2018 09:18:41 +0200 Subject: [PATCH 1/2] scripts: enable linker debugging when running in debug mode --- scripts/container-manager.sh | 8 +++++--- scripts/snap-wrapper.sh | 3 ++- snap/hooks/configure | 8 +++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/container-manager.sh b/scripts/container-manager.sh index b67d614..7eda23e 100755 --- a/scripts/container-manager.sh +++ b/scripts/container-manager.sh @@ -61,8 +61,10 @@ start() { $SNAP/sbin/apparmor_parser -r $SNAP/apparmor/anbox-container.aa fi - if [ -e "$SNAP_COMMON"/.enable_debug ]; then + enable_debug="$(snapctl get debug.enable)" + if [ "$enable_debug" = true ]; then export ANBOX_LOG_LEVEL=debug + export LD_DEBUG=libs fi EXTRA_ARGS= @@ -71,8 +73,8 @@ start() { EXTRA_ARGS="$EXTRA_ARGS --use-rootfs-overlay" fi - privileged_container="$(snapctl get container.privileged)" - if [ "$privileged_container" = true ]; then + enable_privileged_container="$(snapctl get container.privileged)" + if [ "$enable_privileged_container" = true ]; then EXTRA_ARGS="$EXTRA_ARGS --privileged" fi diff --git a/scripts/snap-wrapper.sh b/scripts/snap-wrapper.sh index 60877db..e0e2e80 100755 --- a/scripts/snap-wrapper.sh +++ b/scripts/snap-wrapper.sh @@ -29,7 +29,8 @@ export XDG_DATA_HOME="$SNAP_USER_COMMON/app-data" # configured but the actual EGL implementation is missing. export __EGL_VENDOR_LIBRARY_DIRS="$SNAP/glvnd" -if [ -e "$SNAP_COMMON"/.enable_debug ]; then +enable_debug="$(snapctl get debug.enable)" +if [ "$enable_debug" = true ]; then export ANBOX_LOG_LEVEL=debug fi diff --git a/snap/hooks/configure b/snap/hooks/configure index 89dea03..0677cf6 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -1,9 +1,7 @@ #!/bin/sh -if [ "$(snapctl get debug.enable)" = true ]; then - touch "$SNAP_COMMON"/.enable_debug -else - rm -f "$SNAP_COMMON"/.enable_debug -fi +# We need to have something for snapd in place in order to +# allow configuration options for our snap even if the items +# are read via snapctl elsewhere in the code. exit 0 From bfd0619d969f94fc8b202495f3db19b2657c8baa Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Thu, 5 Jul 2018 09:21:34 +0200 Subject: [PATCH 2/2] scripts: make shellcheck happy --- scripts/container-manager.sh | 27 +++++++++++++-------------- scripts/snap-wrapper.sh | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/container-manager.sh b/scripts/container-manager.sh index 7eda23e..ce693af 100755 --- a/scripts/container-manager.sh +++ b/scripts/container-manager.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -x # We need to put the rootfs somewhere where we can modify some @@ -7,7 +7,6 @@ set -x # rootfs. DATA_PATH=$SNAP_COMMON/ -ROOTFS_PATH=$DATA_PATH/rootfs ANDROID_IMG=$SNAP/android.img if [ "$(id -u)" != 0 ]; then @@ -15,14 +14,14 @@ if [ "$(id -u)" != 0 ]; then exit 1 fi -if [ ! -e $ANDROID_IMG ]; then +if [ ! -e "$ANDROID_IMG" ]; then echo "ERROR: android image does not exist" exit 1 fi -if [ "$SNAP_ARCH" == "amd64" ]; then +if [ "$SNAP_ARCH" = "amd64" ]; then ARCH="x86_64-linux-gnu" -elif [ "$SNAP_ARCH" == "armhf" ]; then +elif [ "$SNAP_ARCH" = "armhf" ]; then ARCH="arm-linux-gnueabihf" else ARCH="$SNAP_ARCH-linux-gnu" @@ -32,11 +31,11 @@ start() { # Make sure our setup path for the container rootfs # is present as lxc is statically configured for # this path. - mkdir -p $SNAP_COMMON/lxc + mkdir -p "$SNAP_COMMON/lxc" # We start the bridge here as long as a oneshot service unit is not # possible. See snapcraft.yaml for further details. - $SNAP/bin/anbox-bridge.sh start + "$SNAP"/bin/anbox-bridge.sh start # Ensure FUSE support for user namespaces is enabled echo Y | tee /sys/module/fuse/parameters/userns_mounts || echo "WARNING: kernel doesn't support fuse in user namespaces" @@ -49,16 +48,16 @@ start() { fi # liblxc.so.1 is in $SNAP/lib - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/liblxc + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/liblxc" # For unknown reason we got bug reports that the container manager failed to start # because it cannot find libboost_log.so.1.58.0 To mitigate this we're adding the # lib directory as explicit search target here. - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH" if [ -d /sys/kernel/security/apparmor ] ; then # Load the profile for our Android container - $SNAP/sbin/apparmor_parser -r $SNAP/apparmor/anbox-container.aa + "$SNAP"/sbin/apparmor_parser -r "$SNAP"/apparmor/anbox-container.aa fi enable_debug="$(snapctl get debug.enable)" @@ -78,15 +77,15 @@ start() { EXTRA_ARGS="$EXTRA_ARGS --privileged" fi - exec $AA_EXEC $SNAP/bin/anbox-wrapper.sh container-manager \ + exec "$AA_EXEC" "$SNAP"/bin/anbox-wrapper.sh container-manager \ "$EXTRA_ARGS" \ - --data-path=$DATA_PATH \ - --android-image=$ANDROID_IMG \ + --data-path="$DATA_PATH" \ + --android-image="$ANDROID_IMG" \ --daemon } stop() { - $SNAP/bin/anbox-bridge.sh stop + "$SNAP"/bin/anbox-bridge.sh stop } case "$1" in diff --git a/scripts/snap-wrapper.sh b/scripts/snap-wrapper.sh index e0e2e80..061c165 100755 --- a/scripts/snap-wrapper.sh +++ b/scripts/snap-wrapper.sh @@ -38,4 +38,4 @@ if [ "$(snapctl get software-rendering.enable)" = true ]; then export ANBOX_FORCE_SOFTWARE_RENDERING=true fi -exec $SNAP/usr/bin/anbox $@ +exec "$SNAP"/usr/bin/anbox "$@"