lib/commonio: make lock failures more detailed
This tweaks the database locking logic so that failures in the link-checking paths are more detailed. The rationale for this is that I've experienced a non-deterministic bug which seems to be coming from this logic, and I'd like to get more details about the actual failing condition.
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
static int lrename (const char *, const char *);
|
static int lrename (const char *, const char *);
|
||||||
static int check_link_count (const char *file);
|
static int check_link_count (const char *file, bool log);
|
||||||
static int do_lock_file (const char *file, const char *lock, bool log);
|
static int do_lock_file (const char *file, const char *lock, bool log);
|
||||||
static /*@null@*/ /*@dependent@*/FILE *fopen_set_perms (
|
static /*@null@*/ /*@dependent@*/FILE *fopen_set_perms (
|
||||||
const char *name,
|
const char *name,
|
||||||
@@ -93,15 +93,25 @@ int lrename (const char *old, const char *new)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_link_count (const char *file)
|
static int check_link_count (const char *file, bool log)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (stat (file, &sb) != 0) {
|
if (stat (file, &sb) != 0) {
|
||||||
|
if (log) {
|
||||||
|
(void) fprintf (shadow_logfd,
|
||||||
|
"%s: %s file stat error: %s\n",
|
||||||
|
shadow_progname, file, strerror (errno));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sb.st_nlink != 2) {
|
if (sb.st_nlink != 2) {
|
||||||
|
if (log) {
|
||||||
|
(void) fprintf (shadow_logfd,
|
||||||
|
"%s: %s: lock file already used (nlink: %u)\n",
|
||||||
|
shadow_progname, file, sb.st_nlink);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +163,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
|
|||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
if (link (file, lock) == 0) {
|
if (link (file, lock) == 0) {
|
||||||
retval = check_link_count (file);
|
retval = check_link_count (file, log);
|
||||||
if ((0==retval) && log) {
|
|
||||||
(void) fprintf (shadow_logfd,
|
|
||||||
"%s: %s: lock file already used\n",
|
|
||||||
shadow_progname, file);
|
|
||||||
}
|
|
||||||
unlink (file);
|
unlink (file);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -219,12 +224,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
|
|||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
if (link (file, lock) == 0) {
|
if (link (file, lock) == 0) {
|
||||||
retval = check_link_count (file);
|
retval = check_link_count (file, log);
|
||||||
if ((0==retval) && log) {
|
|
||||||
(void) fprintf (shadow_logfd,
|
|
||||||
"%s: %s: lock file already used\n",
|
|
||||||
shadow_progname, file);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (log) {
|
if (log) {
|
||||||
(void) fprintf (shadow_logfd,
|
(void) fprintf (shadow_logfd,
|
||||||
|
Reference in New Issue
Block a user