X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/5dd6771b28c257af405d7248639ed0e3bcdce38b..cf57870921b26703aad420c6741c524b33736ff1:/sbr/folder_delmsgs.c diff --git a/sbr/folder_delmsgs.c b/sbr/folder_delmsgs.c index 6bde76f9..94aa29ce 100644 --- a/sbr/folder_delmsgs.c +++ b/sbr/folder_delmsgs.c @@ -8,6 +8,7 @@ */ #include +#include /* * 1) If we are using an external rmmproc, then exec it. @@ -24,7 +25,7 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) { pid_t pid; int msgnum, vecp, retval = 0; - char buf[100], *dp, **vec; + char buf[100], *dp, **vec, *prog; char msgpath[BUFSIZ]; /* @@ -40,13 +41,23 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) /* Mark that the sequence information has changed */ mp->msgflags |= SEQMOD; - if (mp->numsel > MAXARGS - 2) - adios (NULL, "more than %d messages for %s exec", MAXARGS - 2, - rmmproc); - vec = (char **) calloc ((size_t) (mp->numsel + 2), sizeof(*vec)); - if (vec == NULL) - adios (NULL, "unable to allocate exec vector"); - vecp = 1; + /* + * Write out the sequence and context files; this will release + * any locks before the rmmproc is called. + */ + + seq_save (mp); + context_save (); + + vec = argsplit(rmmproc, &prog, &vecp); + + /* + * argsplit allocates a MAXARGS vector by default, If we need + * something bigger, allocate it ourselves + */ + + if (mp->numsel + vecp + 1 > MAXARGS) + vec = mh_xrealloc(vec, (mp->numsel + vecp + 1) * sizeof *vec); for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (is_selected (mp, msgnum) && !(vec[vecp++] = strdup (m_name (msgnum)))) @@ -55,20 +66,20 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) vec[vecp] = NULL; fflush (stdout); - vec[0] = r1bindex (rmmproc, '/'); - switch (pid = vfork()) { + switch (pid = fork()) { case -1: advise ("fork", "unable to"); return -1; case 0: - execvp (rmmproc, vec); + execvp (prog, vec); fprintf (stderr, "unable to exec "); perror (rmmproc); _exit (-1); default: + arglist_free(prog, vec); return (pidwait (pid, -1)); } } @@ -92,14 +103,14 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) if (!nohook) { (void)snprintf(msgpath, sizeof (msgpath), "%s/%d", mp->foldpath, msgnum); - (void)ext_hook("del-hook", msgpath, (char *)0); + (void)ext_hook("del-hook", msgpath, NULL); } dp = m_name (msgnum); if (unlink_msgs) { /* just unlink the messages */ - if (unlink (dp) == -1) { + if (m_unlink (dp) == -1) { admonish (dp, "unable to unlink"); retval = -1; continue; @@ -127,5 +138,12 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) /* Mark that the sequence information has changed */ mp->msgflags |= SEQMOD; + /* + * Write out sequence and context files + */ + + seq_save (mp); + context_save (); + return retval; }