build: use pkg-config for i18n
[exim.git] / src / src / exim_lock.c
index 541e80f3f2a25bf4d6a2fdbcae5ef1f4a99124ea..070dfd780710f4d80f32b9ae79ae693dfacf8b29 100644 (file)
@@ -10,7 +10,8 @@ Default is -fcntl -lockfile.
 
 Argument: the name of the lock file
 
 
 Argument: the name of the lock file
 
-Copyright (c) The Exim Maintainers 2016
+Copyright (c) The Exim Maintainers 2016 - 2024
+SPDX-License-Identifier: GPL-2.0-or-later
 */
 
 #include "os.h"
 */
 
 #include "os.h"
@@ -87,7 +88,6 @@ the other stuff in os.c, so force the other macros to omit it. */
 static void
 sigalrm_handler(int sig)
 {
 static void
 sigalrm_handler(int sig)
 {
-sig = sig;      /* Keep picky compilers happy */
 sigalrm_seen = TRUE;
 }
 
 sigalrm_seen = TRUE;
 }
 
@@ -103,7 +103,7 @@ usage(void)
 printf("usage: exim_lock [-v] [-q] [-lockfile] [-fcntl] [-flock] [-mbx]\n"
        "       [-retries <n>] [-interval <n>] [-timeout <n>] [-restore-times]\n"
        "       <file name> [command]\n");
 printf("usage: exim_lock [-v] [-q] [-lockfile] [-fcntl] [-flock] [-mbx]\n"
        "       [-retries <n>] [-interval <n>] [-timeout <n>] [-restore-times]\n"
        "       <file name> [command]\n");
-exit(1);
+exit(EXIT_FAILURE);
 }
 
 
 }
 
 
@@ -227,7 +227,7 @@ if (use_flock)
   {
   printf("exim_lock: can't use flock() because it was not available in the\n"
          "           operating system when exim_lock was compiled\n");
   {
   printf("exim_lock: can't use flock() because it was not available in the\n"
          "           operating system when exim_lock was compiled\n");
-  exit(1);
+  exit(EXIT_FAILURE);
   }
 #endif
 
   }
 #endif
 
@@ -271,14 +271,14 @@ if (*filename == '~')
   if (pw == NULL)
     {
     printf("exim_lock: unable to expand file name %s\n", argv[i-1]);
   if (pw == NULL)
     {
     printf("exim_lock: unable to expand file name %s\n", argv[i-1]);
-    exit(1);
+    exit(EXIT_FAILURE);
     }
 
   if ((int)strlen(pw->pw_dir) + (int)strlen(filename) + 1 > sizeof(buffer))
     {
     printf("exim_lock: expanded file name %s%s is too long", pw->pw_dir,
       filename);
     }
 
   if ((int)strlen(pw->pw_dir) + (int)strlen(filename) + 1 > sizeof(buffer))
     {
     printf("exim_lock: expanded file name %s%s is too long", pw->pw_dir,
       filename);
-    exit(1);
+    exit(EXIT_FAILURE);
     }
 
   strcpy(buffer, pw->pw_dir);
     }
 
   strcpy(buffer, pw->pw_dir);
@@ -294,7 +294,7 @@ if (use_lockfile)
   if (uname(&s) < 0)
     {
     printf("exim_lock: failed to find host name using uname()\n");
   if (uname(&s) < 0)
     {
     printf("exim_lock: failed to find host name using uname()\n");
-    exit(1);
+    exit(EXIT_FAILURE);
     }
   primary_hostname = s.nodename;
 
     }
   primary_hostname = s.nodename;
 
@@ -331,7 +331,7 @@ for (j = 0; j < lock_retries; j++)
       {
       printf("exim_lock: failed to create hitching post %s: %s\n", hitchname,
         strerror(errno));
       {
       printf("exim_lock: failed to create hitching post %s: %s\n", hitchname,
         strerror(errno));
-      exit(1);
+      exit(EXIT_FAILURE);
       }
 
     /* Apply hitching post algorithm. */
       }
 
     /* Apply hitching post algorithm. */
@@ -357,8 +357,7 @@ for (j = 0; j < lock_retries; j++)
 
   /* Open the file for writing. */
 
 
   /* Open the file for writing. */
 
-  fd = open(filename, O_RDWR + O_APPEND);
-  if (fd < 0)
+  if ((fd = open(filename, O_RDWR + O_APPEND)) < 0)
     {
     printf("exim_lock: failed to open %s for writing: %s\n", filename,
       strerror(errno));
     {
     printf("exim_lock: failed to open %s for writing: %s\n", filename,
       strerror(errno));
@@ -377,7 +376,6 @@ for (j = 0; j < lock_retries; j++)
   a timeout changes it to blocking. */
 
   if (!use_mbx && (use_fcntl || use_flock))
   a timeout changes it to blocking. */
 
   if (!use_mbx && (use_fcntl || use_flock))
-    {
     if (apply_lock(fd, F_WRLCK, use_fcntl, lock_fcntl_timeout, use_flock,
         lock_flock_timeout) >= 0)
       {
     if (apply_lock(fd, F_WRLCK, use_fcntl, lock_fcntl_timeout, use_flock,
         lock_flock_timeout) >= 0)
       {
@@ -388,8 +386,8 @@ for (j = 0; j < lock_retries; j++)
         }
       break;
       }
         }
       break;
       }
-    else goto RETRY;   /* Message already output */
-    }
+    else
+      goto RETRY;   /* Message already output */
 
   /* Lock using MBX rules. This is complicated and is documented with the
   source of the c-client library that goes with Pine and IMAP. What has to
 
   /* Lock using MBX rules. This is complicated and is documented with the
   source of the c-client library that goes with Pine and IMAP. What has to
@@ -586,12 +584,37 @@ else
 if (restore_times)
   {
   struct stat strestore;
 if (restore_times)
   {
   struct stat strestore;
+#ifdef EXIM_HAVE_FUTIMENS
+  int fd = open(filename, O_RDWR); /* use fd for both get & restore */
+  struct timespec tt[2];
+
+  if (fd < 0)
+    {
+    printf("open '%s': %s\n", filename, strerror(errno));
+    yield = 1;
+    goto CLEAN_UP;
+    }
+  if (fstat(fd, &strestore) != 0)
+    {
+    printf("fstat '%s': %s\n", filename, strerror(errno));
+    yield = 1;
+    close(fd);
+    goto CLEAN_UP;
+    }
+  i = system(command);
+  tt[0] = strestore.st_atim;
+  tt[1] = strestore.st_mtim;
+  (void) futimens(fd, tt);
+  (void) close(fd);
+#else
   struct utimbuf ut;
   struct utimbuf ut;
+
   stat(filename, &strestore);
   i = system(command);
   ut.actime = strestore.st_atime;
   ut.modtime = strestore.st_mtime;
   utime(filename, &ut);
   stat(filename, &strestore);
   i = system(command);
   ut.actime = strestore.st_atime;
   ut.modtime = strestore.st_mtime;
   utime(filename, &ut);
+#endif
   }
 else i = system(command);
 
   }
 else i = system(command);