summaryrefslogtreecommitdiff
path: root/src/cryptsetup/cryptsetup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-19 00:08:39 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-20 12:38:06 +0900
commite99ca1474145f7fad38bb0255d344f4ad7717ef5 (patch)
tree4c8662608ea96da642bc293d4838deeac860ed18 /src/cryptsetup/cryptsetup.c
parent5cf84d2545fc314d970e0eded0258d1650bed3cd (diff)
downloadsystemd-e99ca1474145f7fad38bb0255d344f4ad7717ef5.tar.gz
env-util: replace unsetenv_erase() by new getenv_steal_erase() helper
The new helper combines a bunch of steps every invocation of unsetenv_erase() did so far: getenv() + strdup() + unsetenv_erase(). Let's unify this into one helper that is harder to use incorrectly. It's in inspired by TAKE_PTR() in a way: get the env var out and invalidate where it was before.
Diffstat (limited to 'src/cryptsetup/cryptsetup.c')
-rw-r--r--src/cryptsetup/cryptsetup.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 746d428a9b..56a3eedacc 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -818,20 +818,19 @@ static bool libcryptsetup_plugins_support(void) {
#if HAVE_LIBCRYPTSETUP_PLUGINS
static int acquire_pins_from_env_variable(char ***ret_pins) {
- char *e;
+ _cleanup_(erase_and_freep) char *envpin = NULL;
_cleanup_strv_free_erase_ char **pins = NULL;
+ int r;
assert(ret_pins);
- e = getenv("PIN");
- if (e) {
- pins = strv_new(e);
+ r = getenv_steal_erase("PIN", &envpin);
+ if (r < 0)
+ return log_error_errno(r, "Failed to acquire PIN from environment: %m");
+ if (r > 0) {
+ pins = strv_new(envpin);
if (!pins)
return log_oom();
-
- string_erase(e);
- if (unsetenv("PIN") < 0)
- return log_error_errno(errno, "Failed to unset $PIN: %m");
}
*ret_pins = TAKE_PTR(pins);