int decode_rfc2047(char *, char *, size_t);
void discard(FILE *);
int default_done(int);
+int execprog(char *, char **);
+int execprogl(char *, char *, ...);
char *expandfol(char *);
char *expanddir(char *);
int ext_hook(char *, char *, char *);
context_replace.c context_save.c \
cpydata.c cpydgst.c crawl_folders.c \
discard.c done.c dtime.c dtimep.c \
- error.c ext_hook.c folder_addmsg.c folder_delmsgs.c \
+ error.c execprog.c ext_hook.c folder_addmsg.c folder_delmsgs.c \
folder_free.c folder_read.c \
folder_realloc.c gans.c getans.c getanswer.c \
getarguments.c getcpy.c \
--- /dev/null
+/*
+** execprog.c -- invoke an external command synchronously
+** This is a safer alternative to system(3)
+*/
+
+#include <h/mh.h>
+
+
+int
+execprog(char *cmd, char **arg)
+{
+ pid_t pid;
+
+ context_save();
+ fflush(stdout);
+
+ switch (pid = fork()) {
+ case -1:
+ /* fork error */
+ advise("fork", "unable to");
+ return 1;
+
+ case 0:
+ /* child */
+ execvp(cmd, arg);
+ fprintf(stderr, "unable to exec ");
+ perror(cmd);
+ _exit(-1);
+
+ default:
+ /* parent */
+ return (pidwait(pid, -1) & 0377 ? 1 : 0);
+ }
+
+ return 1; /* NOT REACHED */
+}
+
+
+int
+execprogl(char *cmd, char *arg, ...)
+{
+ va_list ap;
+ int argc = 0;
+ char *argv[MAXARGS];
+ char *cp;
+ int ret;
+
+ argv[argc++] = mhbasename(arg);
+ va_start(ap, arg);
+ while ((cp = va_arg(ap, char *))) {
+ argv[argc++] = cp;
+ }
+ argv[argc] = NULL;
+ ret = execprog(cmd, argv);
+ va_end(ap);
+
+ return ret;
+}