X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/80fea873648ca2ab2e592999a336c59cf054ab55..a85c067ba6c6940512cf57ec213277a370d87e70:/src/src/exim_lock.c diff --git a/src/src/exim_lock.c b/src/src/exim_lock.c index 158ec6836..1a54a92ad 100644 --- a/src/src/exim_lock.c +++ b/src/src/exim_lock.c @@ -10,7 +10,8 @@ Default is -fcntl -lockfile. Argument: the name of the lock file -Copyright (c) The Exim Maintainers 2016 +Copyright (c) The Exim Maintainers 2016 - 2021 +SPDX-License-Identifier: GPL-2.0-only */ #include "os.h" @@ -38,7 +39,7 @@ in sys/file.h. */ #endif -typedef int BOOL; +typedef unsigned BOOL; #define FALSE 0 #define TRUE 1 @@ -87,7 +88,6 @@ the other stuff in os.c, so force the other macros to omit it. */ static void sigalrm_handler(int sig) { -sig = sig; /* Keep picky compilers happy */ sigalrm_seen = TRUE; } @@ -357,8 +357,7 @@ for (j = 0; j < lock_retries; j++) /* 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)); @@ -377,7 +376,6 @@ for (j = 0; j < lock_retries; j++) 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) { @@ -388,8 +386,8 @@ for (j = 0; j < lock_retries; j++) } 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 @@ -586,12 +584,37 @@ else 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; + stat(filename, &strestore); i = system(command); ut.actime = strestore.st_atime; ut.modtime = strestore.st_mtime; utime(filename, &ut); +#endif } else i = system(command);