gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: util: Attempt to fix issue #9306


From: gnunet
Subject: [gnunet] branch master updated: util: Attempt to fix issue #9306
Date: Thu, 07 Nov 2024 12:38:07 +0100

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new bf84274b7 util: Attempt to fix issue #9306
bf84274b7 is described below

commit bf84274b70903f9ab65238c4615e291980270cc0
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Thu Nov 7 12:37:40 2024 +0100

    util: Attempt to fix issue #9306
---
 configure.ac                  |  2 +-
 meson.build                   |  2 +-
 src/include/gnunet_disk_lib.h |  3 ++-
 src/lib/util/disk.c           | 27 ++++++++++++++++++++++++---
 src/lib/util/test_bio.c       |  6 ++++++
 5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index 605b0a6c4..6e4d71d73 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1058,7 +1058,7 @@ AC_TYPE_UID_T
 # check for library functions
 AC_FUNC_FORK
 AC_FUNC_CHOWN
-AC_CHECK_FUNCS([atoll stat64 strnlen mremap getrlimit setrlimit sysconf 
initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid getifaddrs 
freeifaddrs getresgid mallinfo2 malloc_size malloc_usable_size getrusage random 
srandom stat statfs statvfs wait4 timegm pipe2])
+AC_CHECK_FUNCS([atoll stat64 strnlen mremap getrlimit setrlimit sysconf 
initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid getifaddrs 
freeifaddrs getresgid mallinfo2 malloc_size malloc_usable_size getrusage random 
srandom stat statfs statvfs wait4 timegm pipe2 renameat2])
 
 GN_INTLINCL=""
 GN_LIBINTL="$LTLIBINTL"
diff --git a/meson.build b/meson.build
index f92ff946f..9e1461d9e 100644
--- a/meson.build
+++ b/meson.build
@@ -440,7 +440,7 @@ syscalls = [
   'getpeerucred', 'getpeereid', 'setresuid', 'getifaddrs', 'freeifaddrs',
   'getresgid', 'mallinfo2', 'malloc_size', 'malloc_usable_size', 'getrusage',
   'random', 'srandom', 'stat', 'statfs', 'statvfs', 'wait4', 'timegm',
-  'getaddrinfo', 'initgroups', 'gethostbyname', 'pipe2'
+  'getaddrinfo', 'initgroups', 'gethostbyname', 'pipe2', 'renameat2'
 ]
 
 str_syscalls = [
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index 5e06e32eb..7718a44a7 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -292,8 +292,9 @@ GNUNET_DISK_file_test_read (const char *fil);
  * where NUM is the smallest number that is not used yet.
  *
  * @param fil name of the file to back up
+ * @return the backup file name (must be freed by caller)
  */
-void
+char*
 GNUNET_DISK_file_backup (const char *fil);
 
 
diff --git a/src/lib/util/disk.c b/src/lib/util/disk.c
index 7fed3fda6..936466ac5 100644
--- a/src/lib/util/disk.c
+++ b/src/lib/util/disk.c
@@ -356,7 +356,7 @@ GNUNET_DISK_mkdtemp (const char *t)
 }
 
 
-void
+char *
 GNUNET_DISK_file_backup (const char *fil)
 {
   size_t slen;
@@ -366,17 +366,38 @@ GNUNET_DISK_file_backup (const char *fil)
   slen = strlen (fil) + 20;
   target = GNUNET_malloc (slen);
   num = 0;
+
+#if HAVE_RENAMEAT2
+  {
+    int fd;
+    do
+    {
+      GNUNET_snprintf (target, slen, "%s.%u~", fil, num++);
+      fd = open (target, O_CREAT | O_EXCL);
+    } while (-1 == fd);
+    if (0 != renameat2 (AT_FDCWD, fil, AT_FDCWD, target, RENAME_EXCHANGE))
+    {
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "renameat2", fil);
+      close (fd);
+      return NULL;
+    }
+    close (fd);
+  }
+#else
   do
   {
     GNUNET_snprintf (target, slen, "%s.%u~", fil, num++);
   }
   while (0 == access (target, F_OK));
   if (0 != rename (fil, target))
+  {
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "rename", fil);
-  GNUNET_free (target);
+    return NULL;
+  }
+#endif
+  return target;
 }
 
-
 char *
 GNUNET_DISK_mktemp (const char *t)
 {
diff --git a/src/lib/util/test_bio.c b/src/lib/util/test_bio.c
index 821ce7a4d..04fe27652 100644
--- a/src/lib/util/test_bio.c
+++ b/src/lib/util/test_bio.c
@@ -75,6 +75,12 @@ test_normal_rw (void)
                               rString));
   GNUNET_assert (wNum == rNum);
   GNUNET_free (rString);
+  {
+    char *newname = GNUNET_DISK_file_backup (filename);
+    GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_test (newname));
+    GNUNET_assert (GNUNET_OK ==
+                   GNUNET_DISK_directory_remove (newname));
+  }
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_DISK_directory_remove (filename));
   GNUNET_free (filename);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]