From: Ken Hornstein Date: Wed, 6 Feb 2013 20:51:04 +0000 (-0500) Subject: More work to convert programs over to the use of argsplit(). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/49c748c77f3c9b9ea024c4eb5d1d83855d7e7201?ds=sidebyside More work to convert programs over to the use of argsplit(). --- diff --git a/sbr/arglist.c b/sbr/arglist.c index 8749a4b9..aa143eee 100644 --- a/sbr/arglist.c +++ b/sbr/arglist.c @@ -52,7 +52,7 @@ argsplit(char *command, char **file, int *argp) } } - argvarray = (char **) mh_xmalloc((sizeof(char **) * MAXARGS)); + argvarray = (char **) mh_xmalloc((sizeof(char **) * (MAXARGS + 5))); /* * The simple case - no spaces or shell metacharacters diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index c31b93ed..6babf510 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1860,18 +1860,17 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp, */ switch (filterpid = fork()) { - char **args; + char **args, *program; struct arglist *a; - int i, dat[5], s; + int i, dat[5], s, argp; case 0: /* - * Allocate an argument array for us + * Configure an argument array for us */ - args = (char **) mh_xmalloc((filter_nargs + 2) * sizeof(char *)); - args[0] = formatproc; - args[filter_nargs + 1] = NULL; + args = argsplit(formatproc, &program, &argp); + args[argp + filter_nargs] = NULL; dat[0] = 0; dat[1] = 0; dat[2] = 0; @@ -1882,7 +1881,7 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp, * Pull out each argument and scan them. */ - for (a = arglist_head, i = 1; a != NULL; a = a->a_next, i++) { + for (a = arglist_head, i = argp; a != NULL; a = a->a_next, i++) { args[i] = mh_xmalloc(BUFSIZ); fmt_scan(a->a_fmt, args[i], BUFSIZ - 1, BUFSIZ, dat); /* diff --git a/uip/post.c b/uip/post.c index 716f70e3..9b8bcbef 100644 --- a/uip/post.c +++ b/uip/post.c @@ -1506,7 +1506,8 @@ post (char *file, int bccque, int talk, char *envelope) sigon (); if (sm_mts == MTS_SENDMAIL_PIPE) { - char *sargv[16], **argp; + char **argp, *program; + int argc; for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) sleep (5); @@ -1519,17 +1520,16 @@ post (char *file, int bccque, int talk, char *envelope) adios (file, "can't reopen for sendmail"); } - argp = sargv; - *argp++ = "sendmail"; - *argp++ = "-t"; /* read msg for recipients */ - *argp++ = "-i"; /* don't stop on "." */ + argp = argsplit(sendmail, &program, &argc); + argp[argc++] = "-t"; /* read msg for recipients */ + argp[argc++] = "-i"; /* don't stop on "." */ if (whomsw) - *argp++ = "-bv"; + argp[argc++] = "-bv"; if (snoop) - *argp++ = "-v"; - *argp = NULL; + argp[argc++] = "-v"; + argp[argc] = NULL; - execv (sendmail, sargv); + execv (program, argp); adios (sendmail, "can't exec"); default: diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 33890d5f..3c017c4a 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -42,9 +42,9 @@ int main (int argc, char **argv) { pid_t child_id; - int i, vecp = 1; - char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ]; - char **argp, **arguments, *vec[MAXARGS]; + int i, vecp; + char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ], *program; + char **argp, **arguments, **vec; FILE *fp; char *tfile = NULL; @@ -58,6 +58,13 @@ main (int argc, char **argv) /* read user profile/context */ context_read(); + /* + * Configure this now, since any unknown switches to rcvdist get + * sent to postproc + */ + + vec = argsplit(postproc, &program, &vecp); + mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -114,7 +121,6 @@ main (int argc, char **argv) if (distout (drft, tmpfil, backup) == NOTOK) done (1); - vec[0] = r1bindex (postproc, '/'); vec[vecp++] = "-dist"; vec[vecp++] = drft; if ((cp = context_find ("mhlproc"))) { @@ -129,7 +135,7 @@ main (int argc, char **argv) case NOTOK: admonish (NULL, "unable to fork");/* fall */ case OK: - execvp (postproc, vec); + execvp (program, vec); fprintf (stderr, "unable to exec "); perror (postproc); _exit (1); diff --git a/uip/refile.c b/uip/refile.c index ae71de23..54b6e5f8 100644 --- a/uip/refile.c +++ b/uip/refile.c @@ -321,17 +321,19 @@ clsfolds (struct st_fold *folders, int nfolders) static void remove_files (int filep, char **files) { - int i; - char **vec; + int i, vecp; + char **vec, *program; /* If rmmproc is defined, we use that */ if (rmmproc) { - vec = files++; /* vec[0] = filevec[0] */ - files[filep] = NULL; /* NULL terminate list */ + vec = argsplit(rmmproc, &program, &vecp); + files++; /* Yes, we need to do this */ + for (i = 0; i < filep; i++) + vec[vecp++] = files[i]; + vec[vecp] = NULL; /* NULL terminate list */ fflush (stdout); - vec[0] = r1bindex (rmmproc, '/'); - execvp (rmmproc, vec); + execvp (program, vec); adios (rmmproc, "unable to exec"); }