X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/fe86b6d55ac470e6e832c53ea2c71e680efe5274..36672e5977cdfee454f5ccb1946a19cd43ec5ba0:/uip/rcvdist.c diff --git a/uip/rcvdist.c b/uip/rcvdist.c index b255afa9..bf301cc2 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -1,6 +1,4 @@ - -/* - * rcvdist.c -- asynchronously redistribute messages +/* rcvdist.c -- asynchronously redistribute messages * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -12,7 +10,9 @@ #include #include #include +#include "h/done.h" #include +#include "sbr/m_mktemp.h" #define RCVDIST_SWITCHES \ X("form formfile", 4, FORMSW) \ @@ -42,7 +42,7 @@ int main (int argc, char **argv) { pid_t child_id; - int i, vecp; + int vecp; char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ], *program; char **argp, **arguments, **vec; FILE *fp; @@ -50,7 +50,7 @@ main (int argc, char **argv) if (nmh_init(argv[0], 2)) { return 1; } - done=unlink_done; + set_done(unlink_done); /* * Configure this now, since any unknown switches to rcvdist get @@ -125,12 +125,11 @@ main (int argc, char **argv) vec[vecp++] = drft; vec[vecp] = NULL; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: - inform("unable to fork, continuing..."); - /* FALLTHRU */ + adios("fork", "failed:"); + case OK: execvp (program, vec); fprintf (stderr, "unable to exec "); @@ -146,8 +145,6 @@ main (int argc, char **argv) /* very similar to routine in replsbr.c */ -#define SBUFSIZ 256 - static int outputlinelen = OUTPUTLINELEN; static struct format *fmt; @@ -176,11 +173,11 @@ rcvdistout (FILE *inb, char *form, char *addrs) { int char_read = 0, format_len, i, state; char **ap; - char *cp, name[NAMESZ], tmpbuf[SBUFSIZ]; + char *cp, name[NAMESZ], tmpbuf[NMH_BUFSIZ]; charstring_t scanl; struct comp *cptr; FILE *out; - m_getfld_state_t gstate = 0; + m_getfld_state_t gstate; if (!(out = fopen (drft, "w"))) adios (drft, "unable to create"); @@ -200,25 +197,26 @@ rcvdistout (FILE *inb, char *form, char *addrs) if (cptr) cptr->c_text = addrs; + gstate = m_getfld_state_init(inb); for (;;) { - int msg_count = SBUFSIZ; - switch (state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb)) { + int msg_count = sizeof tmpbuf; + switch (state = m_getfld2(&gstate, name, tmpbuf, &msg_count)) { case FLD: case FLDPLUS: i = fmt_addcomptext(name, tmpbuf); if (i != -1) { char_read += msg_count; while (state == FLDPLUS) { - msg_count = SBUFSIZ; - state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb); + msg_count = sizeof tmpbuf; + state = m_getfld2(&gstate, name, tmpbuf, &msg_count); fmt_appendcomp(i, name, tmpbuf); char_read += msg_count; } } while (state == FLDPLUS) { - msg_count = SBUFSIZ; - state = m_getfld (&gstate, name, tmpbuf, &msg_count, inb); + msg_count = sizeof tmpbuf; + state = m_getfld2(&gstate, name, tmpbuf, &msg_count); } break; @@ -229,7 +227,7 @@ rcvdistout (FILE *inb, char *form, char *addrs) goto finished; default: - adios (NULL, "m_getfld() returned %d", state); + adios (NULL, "m_getfld2() returned %d", state); } } finished: ; @@ -251,7 +249,7 @@ finished: ; } -static void +static void NORETURN unlink_done (int status) { if (backup[0])