diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-01-28 13:47:35 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-01-28 13:47:35 +0100 |
commit | 2d5bdf5bc0e4714d42e5999a4e37553a6bf83575 (patch) | |
tree | ea5e964d2761f1dcd29ba9bb53b869569a6292bf /src/shared | |
parent | 7736202ce9149942e96e525c08d508daa448aff5 (diff) |
always use the same code for creating temporary files
Let's unify our code here, and also always specifiy O_CLOEXEC.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/ask-password-api.c | 5 | ||||
-rw-r--r-- | src/shared/util.c | 8 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index c9c82b2520..a328f145e9 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -325,10 +325,7 @@ int ask_password_agent( mkdir_p_label("/run/systemd/ask-password", 0755); - RUN_WITH_UMASK(0022) { - fd = mkostemp(temp, O_CLOEXEC|O_CREAT|O_WRONLY); - } - + fd = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC); if (fd < 0) { log_error("Failed to create password file: %m"); r = -errno; diff --git a/src/shared/util.c b/src/shared/util.c index f9cbb2073c..2b91ef8a8f 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3893,7 +3893,7 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) { t[k] = '.'; stpcpy(stpcpy(t+k+1, fn), "XXXXXX"); - fd = mkostemp(t, O_WRONLY|O_CLOEXEC); + fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC); if (fd < 0) { free(t); return -errno; @@ -6115,11 +6115,15 @@ int mkostemp_safe(char *pattern, int flags) { unsigned long tries = TMP_MAX; char *s; int r; + _cleanup_umask_ mode_t u; assert(pattern); + u = umask(077); + /* This is much like like mkostemp() but avoids using any - * static variables, thus is async signal safe */ + * static variables, thus is async signal safe. Also, it's not + * subject to umask(). */ s = endswith(pattern, "XXXXXX"); if (!s) |