From 0dce26778ef8abd4fc40de689d7ec9b720d26430 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Tue, 3 Jan 2012 17:08:01 +0100 Subject: Fix compiler warnings. * common/dotlock.c (use_hardlinks_p, dotlock_take_unix): Check return value of link(). * g13/g13.c: Make sure err is initialized. * scd/scdaemon.c (main) [!USE_GCRY_THREAD_CBS]: Do not define ERR. --- common/dotlock.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'common/dotlock.c') diff --git a/common/dotlock.c b/common/dotlock.c index b4734b99f..58a3d0f2a 100644 --- a/common/dotlock.c +++ b/common/dotlock.c @@ -583,16 +583,21 @@ use_hardlinks_p (const char *tname) strcpy (lname, tname); strcat (lname, "x"); - link (tname, lname); - - if (stat (tname, &sb)) - res = -1; /* Ooops. */ - else if (sb.st_nlink == nlink + 1) - res = 0; /* Yeah, hardlinks are supported. */ + res = link (tname, lname); + if (res < 0) + res = -1; else - res = 1; /* No hardlink support. */ + { + if (stat (tname, &sb)) + res = -1; /* Ooops. */ + else if (sb.st_nlink == nlink + 1) + res = 0; /* Yeah, hardlinks are supported. */ + else + res = 1; /* No hardlink support. */ + + unlink (lname); + } - unlink (lname); jnlib_free (lname); return res; } @@ -948,6 +953,7 @@ dotlock_destroy (dotlock_t h) static int dotlock_take_unix (dotlock_t h, long timeout) { + int res; int wtime = 0; int sumtime = 0; int pid; @@ -1004,7 +1010,13 @@ dotlock_take_unix (dotlock_t h, long timeout) { struct stat sb; - link (h->tname, h->lockname); + res = link (h->tname, h->lockname); + if (res < 0) + { + my_error_1 ("lock not made: Oops: link of tmp file failed: %s\n", + strerror (errno)); + return -1; + } if (stat (h->tname, &sb)) { -- cgit v1.2.3 From ff2095ad7b4be7eaf9468b6ef39fd979527ecc4f Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Tue, 3 Jan 2012 17:32:41 +0100 Subject: Revert last change, add comment about link() return values. * common/dotlock.c (use_hardlinks_p, dotlock_take_unix): Do not check return value of link(). --- common/dotlock.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'common/dotlock.c') diff --git a/common/dotlock.c b/common/dotlock.c index 58a3d0f2a..5e17e64c6 100644 --- a/common/dotlock.c +++ b/common/dotlock.c @@ -583,21 +583,17 @@ use_hardlinks_p (const char *tname) strcpy (lname, tname); strcat (lname, "x"); - res = link (tname, lname); - if (res < 0) - res = -1; - else - { - if (stat (tname, &sb)) - res = -1; /* Ooops. */ - else if (sb.st_nlink == nlink + 1) - res = 0; /* Yeah, hardlinks are supported. */ - else - res = 1; /* No hardlink support. */ + /* We ignore the return value of link() because it is unreliable. */ + (void) link (tname, lname); - unlink (lname); - } + if (stat (tname, &sb)) + res = -1; /* Ooops. */ + else if (sb.st_nlink == nlink + 1) + res = 0; /* Yeah, hardlinks are supported. */ + else + res = 1; /* No hardlink support. */ + unlink (lname); jnlib_free (lname); return res; } @@ -953,7 +949,6 @@ dotlock_destroy (dotlock_t h) static int dotlock_take_unix (dotlock_t h, long timeout) { - int res; int wtime = 0; int sumtime = 0; int pid; @@ -1010,13 +1005,8 @@ dotlock_take_unix (dotlock_t h, long timeout) { struct stat sb; - res = link (h->tname, h->lockname); - if (res < 0) - { - my_error_1 ("lock not made: Oops: link of tmp file failed: %s\n", - strerror (errno)); - return -1; - } + /* We ignore the return value of link() because it is unreliable. */ + (void) link (h->tname, h->lockname); if (stat (h->tname, &sb)) { -- cgit v1.2.3