chiark / gitweb /
util: when creating temporary file names, allow including extra id string in it
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Jun 2015 17:09:02 +0000 (19:09 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:03:00 +0000 (10:03 +0100)
This adds a "char *extra" parameter to tempfn_xxxxxx(), tempfn_random(),
tempfn_ranomd_child(). If non-NULL this string is included in the middle
of the newly created file name. This is useful for being able to
distuingish the kind of temporary file when we see one.

This also adds tests for the three call.

For now, we don't make use of this at all, but port all users over.

src/shared/copy.c
src/shared/machine-pool.c
src/shared/util.h

index 1282cb88be7f076b3e390a3131a301da6c7304c0..230e7e4d3fc3a793431fc5165a5c3631dbbf0d3b 100644 (file)
@@ -396,7 +396,7 @@ int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace
         assert(from);
         assert(to);
 
         assert(from);
         assert(to);
 
-        r = tempfn_random(to, &t);
+        r = tempfn_random(to, NULL, &t);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
index 8c64908b1a327a137dbbc0bd700a761a82ee746a..8af78f47d5e3775de87065a6a3cb7e86dbd1ea08 100644 (file)
@@ -75,7 +75,7 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
         if (errno != ENOENT)
                 return sd_bus_error_set_errnof(error, errno, "Failed to open /var/lib/machines.raw: %m");
 
         if (errno != ENOENT)
                 return sd_bus_error_set_errnof(error, errno, "Failed to open /var/lib/machines.raw: %m");
 
-        r = tempfn_xxxxxx("/var/lib/machines.raw", &tmp);
+        r = tempfn_xxxxxx("/var/lib/machines.raw", NULL, &tmp);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
index 93fe000a26b55d88bd8eb1fbc8a84c3bbea9f748..11ab9f6c0b2bce65ea39f272a34086ba999d499d 100644 (file)
@@ -990,9 +990,9 @@ int bind_remount_recursive(const char *prefix, bool ro);
 
 int fflush_and_check(FILE *f);
 
 
 int fflush_and_check(FILE *f);
 
-int tempfn_xxxxxx(const char *p, char **ret);
-int tempfn_random(const char *p, char **ret);
-int tempfn_random_child(const char *p, char **ret);
+int tempfn_xxxxxx(const char *p, const char *extra, char **ret);
+int tempfn_random(const char *p, const char *extra, char **ret);
+int tempfn_random_child(const char *p, const char *extra, char **ret);
 
 bool is_localhost(const char *hostname);
 
 
 bool is_localhost(const char *hostname);