mirror of
git://sourceware.org/git/lvm2.git
synced 2025-08-05 16:22:02 +03:00
liblvm: Save off and restore umask values
lvm has a default umask value in the config file that defaults to 0077 which lvm changes to during normal operation. This causes a problem when the code is used as a library with liblvm as it is changing the umask for the process. This patch saves off the current umask, sets to what is specified in the config file and restores it what it was on library function call exit. The user is now free to change the umask in their application at anytime including between library calls. This fix address BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1012113 Tested by setting umask to 0777 and running the python unit test and verifying that umask is still same value as expected at the test completion and with a successful run. Signed-off-by: Tony Asleson <tasleson@redhat.com>
This commit is contained in:
@ -140,3 +140,28 @@ int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Store anything that may need to be restored back to the user on library
|
||||
* call exit. Currently the only thing we are preserving is the users umask.
|
||||
*/
|
||||
struct saved_env store_user_env(struct cmd_context *cmd)
|
||||
{
|
||||
struct saved_env env = {0};
|
||||
|
||||
if (cmd) {
|
||||
env.user_umask = umask(cmd->default_settings.umask);
|
||||
} else {
|
||||
env.user_umask = umask(0);
|
||||
umask(env.user_umask);
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
void restore_user_env(const struct saved_env *env)
|
||||
{
|
||||
if (env) {
|
||||
umask(env->user_umask);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user