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.
Viewing a subset of changes. View all
Switch to get_current_dir_name()
This patch changes getcwd to get_current_dir_name and does a tiny refactor to move cleanup functions to a dedicated module so that they can be shared. Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
- Loading branch information...
commit 0e690b310d1ce4fb772fab3085015897d62bf7d0
zyga
committed
Jun 24, 2016
| @@ -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 |
I suggest using get_current_dir_name() instead of getcwd(), like we do in mount-support.c. This has the advantage of not having to pick an arbitrary size for vanilla_cwd but does mean you need to free() the result.