summary: mount namespace is shared among processes
details: |
    The mount namespace is automatically shared amongst processes belonging to
    a given snap. The namespace is preserved until the machine reboots or until
    it is discarded with snap-discard-ns.
prepare: |
    # NOTE: devmode is required because otherwise we cannot read /proc/self/ns/mnt
    snap install --devmode snapd-hacker-toolbelt
execute: |
    export PATH=/snap/bin:$PATH
    echo "The mount namespace inside a snap is different"
    outer_mnt_ns=$(readlink /proc/self/ns/mnt)
    inner_mnt_ns=$(snapd-hacker-toolbelt.busybox readlink /proc/self/ns/mnt)
    [ "$outer_mnt_ns" != "$inner_mnt_ns" ]
    echo "The mount namespace is stable across invocations"
    for i in $(seq 100); do
        [ "$inner_mnt_ns" = "$(snapd-hacker-toolbelt.busybox readlink /proc/self/ns/mnt)" ]
    done
restore: |
    snap remove --purge snapd-hacker-toolbelt
