X-Git-Url: https://vcs.fsf.org/?p=exim.git;a=blobdiff_plain;f=src%2Fsrc%2Fexim_lock.c;h=158ec6836aafd8a79149449d6261bfacd791bd7b;hp=027a55831d1e106d09ad336ed51e5fe7b395e6e5;hb=5fb822fc4839e253d2f839ba7966bc25a5329ac1;hpb=3634fc257bd0667daef14d72005cd87c735bbb24 diff --git a/src/src/exim_lock.c b/src/src/exim_lock.c index 027a55831..158ec6836 100644 --- a/src/src/exim_lock.c +++ b/src/src/exim_lock.c @@ -9,6 +9,8 @@ Options: -fcntl use fcntl() lock Default is -fcntl -lockfile. Argument: the name of the lock file + +Copyright (c) The Exim Maintainers 2016 */ #include "os.h" @@ -70,6 +72,10 @@ the other stuff in os.c, so force the other macros to omit it. */ #define FIND_RUNNING_INTERFACES #endif +#ifndef OS_GET_DNS_RESOLVER_RES + #define OS_GET_DNS_RESOLVER_RES +#endif + #include "../src/os.c" @@ -171,7 +177,7 @@ int fd = -1; int hd = -1; int md = -1; int yield = 0; -int now = time(NULL); +time_t now = time(NULL); BOOL use_lockfile = FALSE; BOOL use_fcntl = FALSE; BOOL use_flock = FALSE; @@ -212,7 +218,7 @@ for (i = 1; i < argc; i++) else usage(); } -if (quiet) verbose = 0; +if (quiet) verbose = FALSE; /* Can't use flock() if the OS doesn't provide it */ @@ -296,8 +302,10 @@ if (use_lockfile) lockname = malloc(len + 8); sprintf(lockname, "%s.lock", filename); hitchname = malloc(len + 32 + (int)strlen(primary_hostname)); + + /* Presumably, this must match appendfile.c */ sprintf(hitchname, "%s.%s.%08x.%08x", lockname, primary_hostname, - now, (int)getpid()); + (unsigned int)now, (unsigned int)getpid()); if (verbose) printf("exim_lock: lockname = %s\n hitchname = %s\n", lockname, @@ -316,7 +324,7 @@ for (j = 0; j < lock_retries; j++) if (use_lockfile) { - int rc; + int rc, rc2; if (verbose) printf("exim_lock: creating lock file\n"); hd = open(hitchname, O_WRONLY | O_CREAT | O_EXCL, 0440); if (hd < 0) @@ -328,11 +336,12 @@ for (j = 0; j < lock_retries; j++) /* Apply hitching post algorithm. */ - if ((rc = link(hitchname, lockname)) != 0) fstat(hd, &statbuf); + if ((rc = link(hitchname, lockname)) != 0) + rc2 = fstat(hd, &statbuf); (void)close(hd); unlink(hitchname); - if (rc != 0 && statbuf.st_nlink != 2) + if (rc != 0 && (rc2 != 0 || statbuf.st_nlink != 2)) { printf("exim_lock: failed to link hitching post to lock file\n"); hd = -1; @@ -579,12 +588,14 @@ if (restore_times) struct stat strestore; struct utimbuf ut; stat(filename, &strestore); - (void)system(command); + i = system(command); ut.actime = strestore.st_atime; ut.modtime = strestore.st_mtime; utime(filename, &ut); } -else (void)system(command); +else i = system(command); + +if(i && !quiet) printf("warning: nonzero status %d\n", i); /* Remove the locks and exit. Unlink the /tmp file if we can get an exclusive lock on the mailbox. This should be a non-blocking lock call, as there is no