Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Try to preserve current working directory #48
Merged
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a39fb3f
Try to preserve current working directory
zyga 93c9ff2
Add spread regression test for LP:1595444
zyga 6f58c38
Chdir to / explicitly, reword error message
zyga 42c7bad
Exit when we cannot remain in the current working directory
zyga 912a5a0
Tweak error message to display errno
zyga 0e690b3
Switch to get_current_dir_name()
zyga
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,21 @@ | ||
| +summary: Regression check for https://bugs.launchpad.net/snap-confine/+bug/1595444 | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| +execute: | | ||
| + echo "Having installed the snapd-hacker-toolbelt snap" | ||
| + snap list | grep -q snapd-hacker-toolbelt || snap install snapd-hacker-toolbelt | ||
| + | ||
| + echo "We can go to a location that is available in all snaps (/tmp)" | ||
| + echo "We can run the 'cwd' tool from busybox and it reports /tmp" | ||
| + [ "$(cd /tmp && /snap/bin/snapd-hacker-toolbelt.busybox pwd)" = "/tmp" ] | ||
| + | ||
| + echo "But if we go to a location that is not available to snaps (e.g. $HOME/.cache)" | ||
| + echo "Then the same 'cwd' tool refuses to run the snap" | ||
| + mkdir -p "$HOME/.cache/" | ||
| + cd "$HOME/.cache" || exit 1 | ||
| + # pwd doesn't run | ||
| + [ "$(/snap/bin/snapd-hacker-toolbelt.busybox pwd)" = "" ] | ||
| + # there's an accurate error message | ||
| + [ "$(/snap/bin/snapd-hacker-toolbelt.busybox pwd 2>&1)" = "cannot remain in $HOME/.cache, please run this snap from another location. errmsg: No such file or directory" ] | ||
| + # snap-confine returns an error code on exit | ||
| + ! /snap/bin/snapd-hacker-toolbelt.busybox pwd |
11
spread.yaml
| @@ -0,0 +1,23 @@ | ||
| +/* | ||
| + * Copyright (C) 2015 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| + | ||
| +#include <stdlib.h> | ||
| + | ||
| +void sc_cleanup_string(char **ptr) | ||
| +{ | ||
| + free(*ptr); | ||
| +} |
| @@ -0,0 +1,29 @@ | ||
| +/* | ||
| + * Copyright (C) 2015 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| + | ||
| +#ifndef SNAP_CONFINE_CLEANUP_FUNCS_H | ||
| +#define SNAP_CONFINE_CLEANUP_FUNCS_H | ||
| + | ||
| +/** | ||
| + * Free a dynamically allocated string. | ||
| + * | ||
| + * This function is designed to be used with | ||
| + * __attribute__((cleanup(sc_cleanup_string))). | ||
| + **/ | ||
| +void sc_cleanup_string(char **ptr); | ||
| + | ||
| +#endif |
15
src/main.c
Since we are die()ing, LGTM with the get_current_dir_name() change.