From a4f7db8d70e4a1f285fb8345d3c9173b4a0cbe17 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 6 Apr 2014 11:12:14 -0500 Subject: [PATCH] Don't ignore return value of lkfopendata(), most notably of seq_read() in folder_read(). Increased LOCK_RETRIES from 5 to 60. --- h/prototypes.h | 6 +++++- sbr/folder_read.c | 10 +++++++++- sbr/lock_file.c | 2 +- sbr/seq_read.c | 23 ++++++++++++++++------- uip/new.c | 8 +++++++- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/h/prototypes.h b/h/prototypes.h index f8adbac5..4f1d3295 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -280,8 +280,12 @@ void seq_printall (struct msgs *); * and a pointer to the filehandle will be stored in * folder structure, where it will later be used by * seq_save(). + * + * Return values: + * OK - successfully read the sequence files, or they don't exist + * NOTOK - failed to lock sequence file */ -void seq_read (struct msgs * mp, int lockflag); +int seq_read (struct msgs * mp, int lockflag); void seq_save (struct msgs *); void seq_setcur (struct msgs *, int); void seq_setprev (struct msgs *); diff --git a/sbr/folder_read.c b/sbr/folder_read.c index 5c52abde..73ffe431 100644 --- a/sbr/folder_read.c +++ b/sbr/folder_read.c @@ -165,7 +165,15 @@ folder_read (char *name, int lockflag) /* * Read and initialize the sequence information. */ - seq_read (mp, lockflag); + if (seq_read (mp, lockflag) == NOTOK) { + char seqfile[PATH_MAX]; + + /* Failed to lock sequence file. */ + snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq); + advise (seqfile, "failed to lock"); + + return NULL; + } return mp; } diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 1a562f9b..3e322ba5 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -48,7 +48,7 @@ struct lockinfo { /* * Number of tries to retry locking */ -#define LOCK_RETRIES 5 +#define LOCK_RETRIES 60 /* * Amount of time to wait before diff --git a/sbr/seq_read.c b/sbr/seq_read.c index aeb76fc1..44e25799 100644 --- a/sbr/seq_read.c +++ b/sbr/seq_read.c @@ -15,7 +15,7 @@ * static prototypes */ static int seq_init (struct msgs *, char *, char *); -static void seq_public (struct msgs *, int); +static int seq_public (struct msgs *, int); static void seq_private (struct msgs *); @@ -25,7 +25,7 @@ static void seq_private (struct msgs *); * or context file (for private sequences). */ -void +int seq_read (struct msgs *mp, int lockflag) { /* @@ -37,13 +37,20 @@ seq_read (struct msgs *mp, int lockflag) /* If folder is empty, don't scan for sequence information */ if (mp->nummsg == 0) - return; + return OK; /* Initialize the public sequences */ - seq_public (mp, lockflag); + if (seq_public (mp, lockflag) == NOTOK) { + if (errno == EACCES || errno == EAGAIN || errno == EWOULDBLOCK) { + /* Failed to lock sequence file. */ + return NOTOK; + } + } /* Initialize the private sequences */ seq_private (mp); + + return OK; } @@ -51,7 +58,7 @@ seq_read (struct msgs *mp, int lockflag) * read folder's sequences file for public sequences */ -static void +static int seq_public (struct msgs *mp, int lockflag) { int state; @@ -66,13 +73,13 @@ seq_public (struct msgs *mp, int lockflag) * then just return, and do not initialize any public sequences. */ if (mh_seq == NULL || *mh_seq == '\0') - return; + return OK; /* get filename of sequence file */ snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq); if ((fp = lkfopendata (seqfile, lockflag ? "r+" : "r")) == NULL) - return; + return NOTOK; /* Use m_getfld to scan sequence file */ for (;;) { @@ -116,6 +123,8 @@ seq_public (struct msgs *mp, int lockflag) } else { lkfclosedata (fp, seqfile); } + + return OK; } diff --git a/uip/new.c b/uip/new.c index 6f998252..a0683dd2 100644 --- a/uip/new.c +++ b/uip/new.c @@ -114,7 +114,13 @@ get_msgnums(char *folder, char *sequences[]) if ((fp = lkfopendata (seqfile, "r")) == NULL) { free(seqfile); - return NULL; + + if (errno == EACCES || errno == EAGAIN || errno == EWOULDBLOCK) { + /* Failed to lock sequence file. */ + adios (seqfile, "failed to lock"); + } else { + return NULL; + } } /* Use m_getfld to scan sequence file */ -- 2.56.0