return false;
}
- int r = mutt_file_lock(fileno(ci->lockfp), excl, 1);
+ int r = mutt_file_lock(fileno(ci->lockfp), excl, true);
if (r == 0)
ci->locked = true;
else if (excl)
* @param e Message headers
* @param force override the $ask* vars (used for the ~h command)
*/
-static void be_edit_header(struct Envelope *e, int force)
+static void be_edit_header(struct Envelope *e, bool force)
{
char tmp[HUGE_STRING];
scrollok(stdscr, true);
- be_edit_header(msg->env, 0);
+ be_edit_header(msg->env, false);
addstr(_("(End message with a . on a line by itself)\n"));
msg->env->cc = mutt_expand_aliases(msg->env->cc);
break;
case 'h':
- be_edit_header(msg->env, 1);
+ be_edit_header(msg->env, true);
break;
case 'F':
case 'f':
return NULL;
}
- if (mutt_file_lock(ctx->fd, 1, 5))
+ if (mutt_file_lock(ctx->fd, true, true))
goto fail_close;
ret = db_env_create(&ctx->env, 0);
struct Maildir *p, *last = NULL;
char fn[PATH_MAX];
int count;
- int sort = 0;
+ bool sort = false;
#ifdef USE_HCACHE
const char *key = NULL;
size_t keylen;
*md = p;
else
last->next = p;
- sort = 1;
+ sort = true;
p = skip_duplicates(p, &last);
snprintf(fn, sizeof(fn), "%s/%s", mailbox->path, p->h->path);
}
/**
* mutt_file_lock - (try to) lock a file using fcntl()
* @param fd File descriptor to file
- * @param excl If set, try to lock exclusively
- * @param timeout Retry after this time
+ * @param excl If true, try to lock exclusively
+ * @param timeout If true, Retry #MAX_LOCK_ATTEMPTS times
* @retval 0 Success
* @retval -1 Failure
*
*
* Use mutt_file_unlock() to unlock the file.
*/
-int mutt_file_lock(int fd, int excl, int timeout)
+int mutt_file_lock(int fd, bool excl, bool timeout)
{
- int count;
- int attempt;
struct stat sb = { 0 }, prev_sb = { 0 };
+ int count = 0;
+ int attempt = 0;
struct flock lck;
-
memset(&lck, 0, sizeof(struct flock));
lck.l_type = excl ? F_WRLCK : F_RDLCK;
lck.l_whence = SEEK_SET;
- count = 0;
- attempt = 0;
while (fcntl(fd, F_SETLK, &lck) == -1)
{
mutt_debug(1, "fcntl errno %d.\n", errno);
/**
* mutt_file_lock - (try to) lock a file using flock()
* @param fd File descriptor to file
- * @param excl If set, try to lock exclusively
- * @param timeout Retry after this time
+ * @param excl If true, try to lock exclusively
+ * @param timeout If true, Retry #MAX_LOCK_ATTEMPTS times
* @retval 0 Success
* @retval -1 Failure
*
*
* Use mutt_file_unlock() to unlock the file.
*/
-int mutt_file_lock(int fd, int excl, int timeout)
+int mutt_file_lock(int fd, bool excl, bool timeout)
{
- int count;
- int attempt;
struct stat sb = { 0 }, prev_sb = { 0 };
- int r = 0;
+ int rc = 0;
+ int count = 0;
+ int attempt = 0;
- count = 0;
- attempt = 0;
while (flock(fd, (excl ? LOCK_EX : LOCK_SH) | LOCK_NB) == -1)
{
if (errno != EWOULDBLOCK)
{
mutt_perror("flock");
- r = -1;
+ rc = -1;
break;
}
{
if (timeout)
mutt_error(_("Timeout exceeded while attempting flock lock"));
- r = -1;
+ rc = -1;
break;
}
}
/* release any other locks obtained in this routine */
- if (r != 0)
+ if (rc != 0)
{
flock(fd, LOCK_UN);
}
- return r;
+ return rc;
}
/**
if (fd == -1)
return;
- if (mutt_file_lock(fd, 1, 1) == -1)
+ if (mutt_file_lock(fd, true, true) == -1)
{
close(fd);
return;
int mutt_file_fclose(FILE **f);
FILE * mutt_file_fopen(const char *path, const char *mode);
int mutt_file_fsync_close(FILE **f);
-int mutt_file_lock(int fd, int excl, int timeout);
+int mutt_file_lock(int fd, bool excl, bool timeout);
int mutt_file_mkdir(const char *path, mode_t mode);
FILE * mutt_file_mkstemp_full(const char *file, int line, const char *func);
#define mutt_file_mkstemp() mutt_file_mkstemp_full(__FILE__, __LINE__, __func__)
/* lock it */
mutt_debug(1, "Locking %s\n", nserv->newsrc_file);
- if (mutt_file_lock(fileno(nserv->newsrc_fp), 0, 1))
+ if (mutt_file_lock(fileno(nserv->newsrc_fp), false, true))
{
mutt_file_fclose(&nserv->newsrc_fp);
return -1;