void admonish (char *, char *, ...);
void advertise (char *, char *, char *, va_list);
void advise (char *, char *, ...);
+char **argsplit (char *, char **, int *);
+void arglist_free (char *, char **);
void ambigsw (char *, struct swit *);
int atooi(char *);
char **brkstring (char *, char *, char *);
*
* - If there are no spaces or shell metacharacters in "command", then
* take it as-is.
- * - If there are spaces in command, space-split command string and
- * append an argument list to it.
+ * - If there are spaces in command, space-split command string.
* - If we have shell metacharacters, run the command using
- * /bin/sh -c 'command "${@}"'.
+ * /bin/sh -c 'command "$@"'. In this case, any additional arguments
+ * appended to the arglist will be expanded by "$@".
*
* In all cases additional arguments can be added to the argv[] array.
*/
return argvarray;
}
+
+/*
+ * Free our argument array
+ */
+
+void
+arglist_free(char *command, char **argvarray)
+{
+ int i;
+
+ if (command != NULL)
+ free(command);
+
+ if (argvarray != NULL) {
+ for (i = 0; argvarray[i] != NULL; i++)
+ free(argvarray[i]);
+ free(argvarray);
+ }
+}
m_popen (char *name)
{
int pd[2];
+ char *file;
+ char **arglist;
if (mhl_action && (sd = dup (fileno (stdout))) == NOTOK)
adios ("standard output", "unable to dup()");
dup2 (pd[0], fileno (stdin));
close (pd[0]);
}
- execlp (name, r1bindex (name, '/'), NULL);
+ arglist = argsplit(name, &file, NULL);
+ execvp (file, arglist);
fprintf (stderr, "unable to exec ");
perror (name);
_exit (-1);
{
pid_t child_id;
int i, vecp;
- char *vec[8];
+ char **vec;
+ char *file;
- vecp = 0;
- vec[vecp++] = r1bindex (mhlproc, '/');
- vec[vecp++] = "-form";
- vec[vecp++] = form;
- vec[vecp++] = "-nobody";
- vec[vecp++] = ct->c_file;
+ vec = argsplit(mhlproc, &file, &vecp);
+ vec[vecp++] = getcpy("-form");
+ vec[vecp++] = getcpy(form);
+ vec[vecp++] = getcpy("-nobody");
+ vec[vecp++] = getcpy(ct->c_file);
/*
* If we've specified -(no)moreproc,
* then just pass that along.
*/
if (nomore) {
- vec[vecp++] = "-nomoreproc";
+ vec[vecp++] = getcpy("-nomoreproc");
} else if (progsw) {
- vec[vecp++] = "-moreproc";
- vec[vecp++] = progsw;
+ vec[vecp++] = getcpy("-moreproc");
+ vec[vecp++] = getcpy(progsw);
}
vec[vecp] = NULL;
/* NOTREACHED */
case OK:
- execvp (mhlproc, vec);
+ execvp (file, vec);
fprintf (stderr, "unable to exec ");
perror (mhlproc);
_exit (-1);
xpid = -child_id;
break;
}
+
+ arglist_free(file, vec);
}
int pid;
char *mhl;
char *errstr;
- char *arglist[7];
+ char **arglist;
+ int argnum;
if (filter == NULL)
return;
if (access (filter, R_OK) == NOTOK)
adios (filter, "unable to read");
- mhl = r1bindex (mhlproc, '/');
-
rewind (in);
lseek (fileno(in), (off_t) 0, SEEK_SET);
dup2 (fileno (out), fileno (stdout));
closefds (3);
- arglist[0] = mhl;
- arglist[1] = "-form";
- arglist[2] = filter;
- arglist[3] = "-noclear";
+ /*
+ * We're not allocating the memory for the extra arguments,
+ * because we never call arglist_free(). But if we ever change
+ * that be sure to use getcpy() for the extra arguments.
+ */
+ arglist = argsplit(mhlproc, &mhl, &argnum);
+ arglist[argnum++] = "-form";
+ arglist[argnum++] = filter;
+ arglist[argnum++] = "-noclear";
switch (fmtproc) {
case 1:
- arglist[4] = "-fmtproc";
- arglist[5] = formatproc;
- arglist[6] = NULL;
+ arglist[argnum++] = "-fmtproc";
+ arglist[argnum++] = formatproc;
break;
case 0:
- arglist[4] = "-nofmtproc";
- arglist[5] = NULL;
+ arglist[argnum++] = "-nofmtproc";
break;
- default:
- arglist[4] = NULL;
}
- execvp (mhlproc, arglist);
+ arglist[argnum++] = NULL;
+
+ execvp (mhl, arglist);
errstr = strerror(errno);
write(2, "unable to exec ", 15);
write(2, mhlproc, strlen(mhlproc));