Use execprog() instead of system() ... partly transition
authormarkus schnalke <meillo@marmaro.de>
Wed, 14 Jan 2015 06:31:49 +0000 (07:31 +0100)
committermarkus schnalke <meillo@marmaro.de>
Wed, 14 Jan 2015 06:31:49 +0000 (07:31 +0100)
There are several more places where system() should be replaced.

As execprog() does not split strings into multiple arguments,
`listproc' could no longer contain ``show -file''. We need to
rework the concept of these `...proc' entries.

This commit fixes tests/whatnow/test-attach-detach.

config/config.c
man/mh-profile.man5
uip/new.c
uip/repl.c
uip/send.c
uip/spost.c
uip/whatnow.c

index 52ef436..2bf7325 100644 (file)
@@ -112,10 +112,9 @@ char *mimetypequeryproc = "file -b --mime";
 /*
 ** This is the default program invoked by a "list" or "display" response
 ** at the "What now?" prompt. It will be given the absolute pathname of
 /*
 ** This is the default program invoked by a "list" or "display" response
 ** at the "What now?" prompt. It will be given the absolute pathname of
-** the message to show. The string ``show -file'' is most likely what you
-** want to be you listproc.
+** the message to show.
 */
 */
-char *listproc = "show -file";
+char *listproc = "show";
 
 /*
 ** This is used by mhl as a front-end.  It is also used
 
 /*
 ** This is used by mhl as a front-end.  It is also used
index 109d3c4..5e02d9f 100644 (file)
@@ -392,7 +392,7 @@ user wishes.  The default values are given in the examples.
 .RE
 .PP
 .BR listproc :
 .RE
 .PP
 .BR listproc :
-show \-file
+show
 .RS 5
 This program is used to list the contents of a message in response
 to the
 .RS 5
 This program is used to list the contents of a message in response
 to the
index a79845c..a43a710 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -311,7 +311,11 @@ doit(char *cur, char *folders, char *sequences[])
        struct node *first, *cur_node, *node, *last = NULL, *prev;
        size_t folder_len;
        int count, total = 0;
        struct node *first, *cur_node, *node, *last = NULL, *prev;
        size_t folder_len;
        int count, total = 0;
-       char *command = NULL, *sequences_s = NULL;
+       char *sequences_s = NULL;
+       int argc = 0;
+       char *argv[MAXARGS];
+       char *cp;
+       char buf[BUFSIZ];
 
        if (cur == NULL || cur[0] == '\0') {
                cur = "inbox";
 
        if (cur == NULL || cur[0] == '\0') {
                cur = "inbox";
@@ -383,14 +387,15 @@ doit(char *cur, char *folders, char *sequences[])
                        }
                        fflush(stdout);
 
                        }
                        fflush(stdout);
 
-                       /*
-                       ** TODO: Split enough of scan.c out so that we can
-                       ** call it here.
-                       */
-                       command = concat("scan +", node->n_name, " ",
-                                       sequences_s, (void *)NULL);
-                       system(command);
-                       free(command);
+                       argc = 0;
+                       argv[argc++] = "scan";
+                       snprintf(buf, sizeof buf, "+%s", node->n_name);
+                       argv[argc++] = buf;
+                       for (cp=*sequences; *cp; cp++) {
+                               argv[argc++] = cp;
+                       }
+                       argv[argc] = (char *)NULL;
+                       execprog(*argv, argv);
                } else {
                        if (node->n_field == NULL) {
                                continue;
                } else {
                        if (node->n_field == NULL) {
                                continue;
index 9c9e5ce..e5fbc0f 100644 (file)
@@ -573,11 +573,11 @@ finished:
                /* add an attachment header */
                char buffer[BUFSIZ];
 
                /* add an attachment header */
                char buffer[BUFSIZ];
 
-               snprintf(buffer, sizeof buffer, "anno -append -nodate '%s' "
-                               "-comp '%s' -text '+%s %s'",
-                               drft,
-                               attach_hdr, mp->foldpath, m_name(mp->lowsel));
-               if (system(buffer) != 0) {
+               snprintf(buffer, sizeof buffer, "+%s %s",
+                               mp->foldpath, m_name(mp->lowsel));
+               if (execprogl("anno", "anno", "-append", "-nodate",
+                               drft, "-comp", attach_hdr, "-text", buffer,
+                               (char *)NULL) != 0) {
                        advise(NULL, "unable to add attachment header");
                }
        }
                        advise(NULL, "unable to add attachment header");
                }
        }
index adb2039..3ca6772 100644 (file)
@@ -448,8 +448,8 @@ attach(char *draft_file_name)
        fclose(composition_file);
 
        /* We're ready to roll! */
        fclose(composition_file);
 
        /* We're ready to roll! */
-       sprintf(buf, "mhbuild %s", composition_file_name);
-       if (system(buf) != 0) {
+       if (execprogl("mhbuild", "mhbuild", composition_file_name,
+                       (char *)NULL) != 0) {
                /* some problem */
                clean_up_temporary_files();
                return (NOTOK);
                /* some problem */
                clean_up_temporary_files();
                return (NOTOK);
@@ -469,6 +469,7 @@ signandenc(char *draft_file_name)
        char buf[BUFSIZ];
        int dosign = 0;
        int doenc = 0;
        char buf[BUFSIZ];
        int dosign = 0;
        int doenc = 0;
+       int ret;
 
        if (!(draft_file = fopen(draft_file_name, "r"))) {
                adios(NULL, "can't open draft file `%s'.", draft_file_name);
 
        if (!(draft_file = fopen(draft_file_name, "r"))) {
                adios(NULL, "can't open draft file `%s'.", draft_file_name);
@@ -495,9 +496,14 @@ signandenc(char *draft_file_name)
        strcpy(composition_file_name, draft_file_name);
 
        /* We're ready to roll! */
        strcpy(composition_file_name, draft_file_name);
 
        /* We're ready to roll! */
-       sprintf(buf, "mhsign -m%s '%s'", doenc ? " -e" : "",
-                       draft_file_name);
-       if (system(buf) != 0) {
+       if (doenc) {
+               ret = execprogl("mhsign", "mhsign", "-m", "-e",
+                               draft_file_name, (char *)NULL);
+       } else {
+               ret = execprogl("mhsign", "mhsign", "-m",
+                               draft_file_name, (char *)NULL);
+       }
+       if (ret != 0) {
                /* some problem */
                return (NOTOK);
        }
                /* some problem */
                return (NOTOK);
        }
index 7a59d59..b65e4c4 100644 (file)
@@ -628,7 +628,6 @@ static void
 process_bccs(char *origmsg)
 {
        char *bccdraft = NULL;
 process_bccs(char *origmsg)
 {
        char *bccdraft = NULL;
-       char buf[BUFSIZ];
        struct mailname *mp = NULL;
        FILE *out = NULL;
 
        struct mailname *mp = NULL;
        FILE *out = NULL;
 
@@ -640,8 +639,7 @@ process_bccs(char *origmsg)
                fprintf(out, "------------\n");
                fclose(out);
 
                fprintf(out, "------------\n");
                fclose(out);
 
-               snprintf(buf, sizeof buf, "send %s", bccdraft);
-               if (system(buf) != 0) {
+               if (execprogl("send", "send", bccdraft, (char *)NULL) != 0) {
                        admonish(invo_name, "Problems to send Bcc to %s",
                                        mp->m_text);
                        unlink(bccdraft);
                        admonish(invo_name, "Problems to send Bcc to %s",
                                        mp->m_text);
                        unlink(bccdraft);
index c60a11c..ff9d84c 100644 (file)
@@ -174,9 +174,8 @@ main(int argc, char **argv)
                case DISPSW:
                        /* display the msg being replied to or distributed */
                        if ((cp = getenv("mhaltmsg")) && *cp) {
                case DISPSW:
                        /* display the msg being replied to or distributed */
                        if ((cp = getenv("mhaltmsg")) && *cp) {
-                               snprintf(buf, sizeof buf, "%s '%s'",
-                                               listproc, cp);
-                               system(buf);
+                               execprogl(listproc, listproc, "-file", cp,
+                                               (char *)NULL);
                        } else {
                                advise(NULL, "no alternate message to display");
                        }
                        } else {
                                advise(NULL, "no alternate message to display");
                        }
@@ -191,8 +190,8 @@ main(int argc, char **argv)
 
                case LISTSW:
                        /* display the draft file */
 
                case LISTSW:
                        /* display the draft file */
-                       snprintf(buf, sizeof buf, "%s '%s'", listproc, drft);
-                       system(buf);
+                       execprogl(listproc, listproc, "-file", drft,
+                                       (char *)NULL);
                        break;
 
                case QUITSW:
                        break;
 
                case QUITSW:
@@ -269,9 +268,9 @@ main(int argc, char **argv)
                        /*
                        ** List attachments on current draft.
                        */
                        /*
                        ** List attachments on current draft.
                        */
-                       snprintf(buf, sizeof buf, "anno -list -comp '%s' "
-                                       "-number '%s'", attach_hdr, drft);
-                       if (system(buf) != 0) {
+                       if (execprogl("anno", "anno", "-list", "-comp",
+                                       attach_hdr, "-number", drft,
+                                       (char *)NULL) != 0) {
                                advise(NULL, "Could not list attachment headers.");
                        }
                        break;
                                advise(NULL, "Could not list attachment headers.");
                        }
                        break;
@@ -304,8 +303,6 @@ main(int argc, char **argv)
                        ** Add the attachment annotation to the draft.
                        */
                        if ((f = popen_in_dir(cwd, buf, "r"))) {
                        ** Add the attachment annotation to the draft.
                        */
                        if ((f = popen_in_dir(cwd, buf, "r"))) {
-                               char buf[BUFSIZ];
-
                                while (fgets(shell, sizeof(shell), f)) {
                                        *(strchr(shell, '\n')) = '\0';
 
                                while (fgets(shell, sizeof(shell), f)) {
                                        *(strchr(shell, '\n')) = '\0';
 
@@ -315,13 +312,13 @@ main(int argc, char **argv)
                                                sprintf(file, "%s/%s", cwd,
                                                                shell);
                                        }
                                                sprintf(file, "%s/%s", cwd,
                                                                shell);
                                        }
-                                       snprintf(buf, sizeof buf,
-                                                       "anno -nodate -append "
-                                                       "-comp '%s' -text '%s'"
-                                                       " '%s'",
-                                                       attach_hdr, file,
-                                                       drft);
-                                       if (system(buf) != 0) {
+                                       if (execprogl("anno", "anno",
+                                                       "-nodate",
+                                                       "-append", "-comp",
+                                                       attach_hdr, "-text",
+                                                       file, drft,
+                                                       (char *)NULL)
+                                                       != 0) {
                                                advise(NULL, "Could not add attachment header.");
                                        }
                                }
                                                advise(NULL, "Could not add attachment header.");
                                        }
                                }
@@ -344,22 +341,20 @@ main(int argc, char **argv)
                        ** that the numbering stays correct.
                        */
                        for (arguments=argp+1; *arguments; arguments++) {
                        ** that the numbering stays correct.
                        */
                        for (arguments=argp+1; *arguments; arguments++) {
-                               char buf[BUFSIZ];
                                int n;
 
                                if (**arguments == '\0') {
                                        continue;
                                }
 
                                int n;
 
                                if (**arguments == '\0') {
                                        continue;
                                }
 
-                               n = atoi(*arguments);
-                               snprintf(buf, sizeof buf, "anno -delete "
-                                               "-comp '%s' -number '%d' "
-                                               "'%s'",
-                                               attach_hdr, n, drft);
-                               if (system(buf) != 0) {
+                               if (execprogl("anno", "anno", "-delete",
+                                               "-comp", attach_hdr,
+                                               "-number", *arguments, drft,
+                                               (char *)NULL) != 0) {
                                        advise(NULL, "Could not delete attachment header.");
                                }
 
                                        advise(NULL, "Could not delete attachment header.");
                                }
 
+                               n = atoi(*arguments);
                                for (argp=arguments+1; *argp; argp++) {
                                        if (atoi(*argp) > n) {
                                                if (atoi(*argp) == 1) {
                                for (argp=arguments+1; *argp; argp++) {
                                        if (atoi(*argp) > n) {
                                                if (atoi(*argp) == 1) {
@@ -374,8 +369,7 @@ main(int argc, char **argv)
 
                case WHOMSW:
                        /* list recipients */
 
                case WHOMSW:
                        /* list recipients */
-                       snprintf(buf, sizeof buf, "%s '%s'", "whom", drft);
-                       system(buf);
+                       execprogl("whom", "whom", drft, (char *)NULL);
                        break;
 
                default:
                        break;
 
                default: