summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-05-18 20:14:54 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commitc9182982285c084db03437583705a63d24acd599 (patch)
treea06dccd670a72700c3c71d388219cad440194c55 /src/basic/fs-util.c
parent43810cf7ec7e3b0b9dd0637334befb70072ce10b (diff)
fs-util: don't alter errno in unlink_tempfilep()
Functions whose only purpose is to be used with _cleanup_() should not touch errno, so that failing removals do not alter errno at unexpected places. This is already done in unlink_and_freep(), rmdir_and_freep(), rm_rf_physical_and_freep(), hence do so for unlink_tempfilep(), too. Follow-up for #9013
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r--src/basic/fs-util.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 5fb8b88fd..b7d5c5271 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -1081,6 +1081,15 @@ int access_fd(int fd, int mode) {
return r;
}
+void unlink_tempfilep(char (*p)[]) {
+ /* If the file is created with mkstemp(), it will (almost always)
+ * change the suffix. Treat this as a sign that the file was
+ * successfully created. We ignore both the rare case where the
+ * original suffix is used and unlink failures. */
+ if (!endswith(*p, ".XXXXXX"))
+ (void) unlink_noerrno(*p);
+}
+
int unlinkat_deallocate(int fd, const char *name, int flags) {
_cleanup_close_ int truncate_fd = -1;
struct stat st;