[libglnx] fdio: Generate tmpname for RENAME_EXCHANGE fallback



commit b72906dbe067aeee0edab627c9c8ada0a7d8e808
Author: Colin Walters <walters verbum org>
Date:   Mon Oct 2 10:07:50 2017 -0400

    fdio: Generate tmpname for RENAME_EXCHANGE fallback
    
    I was using this in rpm-ostree and glanced at the code. This was clearly the
    intent, but isn't a full fix. See code comments for more details.

 glnx-fdio.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/glnx-fdio.c b/glnx-fdio.c
index 53f82e2..7dfa509 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -143,6 +143,13 @@ glnx_renameat2_exchange (int olddirfd, const char *oldpath,
   /* Fallback */
   { const char *old_tmp_name = glnx_strjoina (oldpath, ".XXXXXX");
 
+    /* This obviously isn't race-free, but doing better gets tricky, since if
+     * we're here the kernel isn't likely to support RENAME_NOREPLACE either.
+     * Anyways, upgrade the kernel. Failing that, avoid use of this function in
+     * shared subdirectories like /tmp.
+     */
+    glnx_gen_temp_name (old_tmp_name);
+
     /* Move old out of the way */
     if (renameat (olddirfd, oldpath, olddirfd, old_tmp_name) < 0)
       return -1;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]