tree-wide: fix use of flink_tmpfile()
Let's always make sure the temporary file returned by fopen_tmpfile() and friends is removed on failure (via _cleanup_). Conversely, make sure that once the file is renamed into its final place, we no longer try to remove the temporary file (since it's not going to exist anymore).
This commit is contained in:
committed by
Daan De Meyer
parent
b9df3d6447
commit
22b5ddb90f
@@ -1789,6 +1789,8 @@ static int action_list_or_mtree_or_copy_or_make_archive(DissectedImage *m, LoopD
|
||||
r = flink_tmpfile(f, tar, arg_target, LINK_TMPFILE_REPLACE);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to move archive file into place: %m");
|
||||
|
||||
tar = mfree(tar);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "build.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "memstream-util.h"
|
||||
@@ -383,7 +384,7 @@ static int verb_pkcs7(int argc, char *argv[], void *userdata) {
|
||||
ASN1_STRING_set0(signer_info->enc_digest, TAKE_PTR(pkcs1), pkcs1_len);
|
||||
|
||||
_cleanup_fclose_ FILE *output = NULL;
|
||||
_cleanup_free_ char *tmp = NULL;
|
||||
_cleanup_(unlink_and_freep) char *tmp = NULL;
|
||||
r = fopen_tmpfile_linkable(arg_output, O_WRONLY|O_CLOEXEC, &tmp, &output);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to open temporary file: %m");
|
||||
@@ -396,6 +397,8 @@ static int verb_pkcs7(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to link temporary file to %s: %m", arg_output);
|
||||
|
||||
tmp = mfree(tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -7556,6 +7556,8 @@ static int context_fstab(Context *context) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to link temporary file to %s: %m", path);
|
||||
|
||||
t = mfree(t);
|
||||
|
||||
log_info("%s written.", path);
|
||||
|
||||
return 0;
|
||||
@@ -7633,6 +7635,8 @@ static int context_crypttab(Context *context) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to link temporary file to %s: %m", path);
|
||||
|
||||
t = mfree(t);
|
||||
|
||||
log_info("%s written.", path);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -409,6 +409,8 @@ static int trie_store(struct trie *trie, const char *filename, bool compat) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
filename_tmp = mfree(filename_tmp);
|
||||
|
||||
/* write succeeded */
|
||||
|
||||
log_debug("=== trie on-disk ===");
|
||||
|
||||
@@ -385,6 +385,8 @@ static int run(int argc, char *argv[]) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to move SRK public key file to '%s': %m", tpm2b_public_path);
|
||||
|
||||
t = mfree(t);
|
||||
|
||||
log_info("SRK public key saved to '%s' in TPM2B_PUBLIC format.", tpm2b_public_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user