ctxpath = getcpy (m_maildir (cp));
- if ((ib = fopen (ctxpath, "r"))) {
+ if ((ib = lkfopen (ctxpath, "r"))) {
readconfig ((struct node **) 0, ib, cp, 1);
- fclose (ib);
+ lkfclose (ib);
}
return;
sigaddset (&set, SIGTERM);
SIGPROCMASK (SIG_BLOCK, &set, &oset);
- if (!(out = fopen (ctxpath, "w")))
+ if (!(out = lkfopen (ctxpath, "w")))
adios (ctxpath, "unable to write");
for (np = m_defs; np; np = np->n_next)
if (np->n_context)
fprintf (out, "%s: %s\n", np->n_name, np->n_field);
- fclose (out);
+ lkfclose (out, ctxpath);
SIGPROCMASK (SIG_SETMASK, &oset, &set); /* reset the signal mask */
if (strcmp (mode, "r") == 0)
access = O_RDONLY;
- else
+ else if (strcmp (mode, "r+") == 0)
access = O_RDWR;
+ else if (strcmp (mode, "w") == 0)
+ access = O_WRONLY | O_CREAT | O_TRUNC;
+ else if (strcmp (mode, "w+") == 0)
+ access = O_RDWR | O_CREAT | O_TRUNC;
+ else if (strcmp (mode, "a") == 0)
+ access = O_WRONLY | O_CREAT | O_APPEND;
+ else if (strcmp (mode, "a+") == 0)
+ access = O_RDWR | O_CREAT | O_APPEND;
+ else {
+ errno = EINVAL;
+ return NULL;
+ }
- if ((fd = lkopen (file, access, 0)) == -1)
+ if ((fd = lkopen (file, access, 0666)) == -1)
return NULL;
if ((fp = fdopen (fd, mode)) == NULL) {
# endif
# ifdef FLOCK_LOCKING
- if (flock (fd, LOCK_EX | LOCK_NB) != -1)
+ if (flock (fd, (((access & 03) == O_RDONLY) ? LOCK_SH : LOCK_EX)
+ | LOCK_NB) != -1)
return fd;
# endif
j = errno;
close (fd);
+ admonish (file, "lock did not succeed, waiting");
sleep (5);
}
/*
* Get the sequence information for this folder from
- * .mh_sequence (or equivalent specified in .mh_profile)
+ * .mh_sequences (or equivalent specified in .mh_profile)
* or context file (for private sequences).
*/
/* get filename of sequence file */
snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);
- if ((fp = fopen (seqfile, "r")) == NULL)
+ if ((fp = lkfopen (seqfile, "r")) == NULL)
return;
/* Use m_getfld to scan sequence file */
break; /* break from for loop */
}
- fclose (fp);
+ lkfclose (fp, seqfile);
}
* If that fails (probably because folder is
* readonly), then make sequence private.
*/
- if ((fp = fopen (seqfile, "w")) == NULL
+ if ((fp = lkfopen (seqfile, "w")) == NULL
&& (unlink (seqfile) == -1 ||
- (fp = fopen (seqfile, "w")) == NULL)) {
+ (fp = lkfopen (seqfile, "w")) == NULL)) {
admonish (attr, "unable to write");
goto priv;
}
}
if (fp) {
- fclose (fp);
+ lkfclose (fp, seqfile);
SIGPROCMASK (SIG_SETMASK, &oset, &set); /* reset signal mask */
} else {
/*