tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/usr.bin/mail



christos%zoulas.com@localhost (Christos Zoulas) wrote:
 |On Mar 7,  7:15pm, sdaoden%gmail.com@localhost (Steffen "Daode" Nurpmeso) 
wrote:
 |-- Subject: Re: CVS commit: src/usr.bin/mail
 |
 || Not at all;  so it's a plain improvement of the codebase.
 || How about caching the result, just as S-nail does; i think with
 || your change you fork a shell subprocess for each and every
 || getfold() now?
 |
 |Yes, that sucks. But how did it work before? I guess I will have to
 |revert the patch and figure it out.

The attached patch should work.

We still go through the _expand() cycle even if the value hasn't
changed in the meanwhile (and no shell characters have been
found) -- i thought about adding caching, but left it off since it
doesn't seem to be a benefit compared to what there will be.

--steffen
diff -Napru mail.orig/fio.c mail/fio.c
--- mail.orig/fio.c     2013-03-06 11:43:31.000000000 +0100
+++ mail/fio.c  2013-03-06 11:57:01.000000000 +0100
@@ -386,6 +386,8 @@ fsize(FILE *iob)
        return sbuf.st_size;
 }
 
+static char const *    _expand(char const *, int);
+
 /*
  * Determine the current folder directory name.
  */
@@ -398,7 +400,7 @@ getfold(char *name, size_t namesize)
 
        if ((folder = value(ENAME_FOLDER)) == NULL)
                return -1;
-       if ((f = expand(folder)) == NULL)
+       if ((f = _expand(folder, 1)) == NULL)
                return -1;
        if (*f != '/') {
                (void)snprintf(unres, sizeof(unres), "%s/%s", homedir, f);
@@ -423,8 +425,8 @@ getfold(char *name, size_t namesize)
  *     any shell meta character
  * Return the file name as a dynamic string.
  */
-PUBLIC const char *
-expand(const char *name)
+static char const *
+_expand(char const *name, int shell_only)
 {
        char xname[PATHSIZE];
        char cmdbuf[PATHSIZE];          /* also used for file names */
@@ -435,6 +437,9 @@ expand(const char *name)
        int pivec[2];
        struct stat sbuf;
 
+       if (shell_only)
+               goto jshell;
+
        /*
         * The order of evaluation is "%" and "#" expand into constants.
         * "&" can expand into "+".  "+" can expand into shell meta characters.
@@ -462,7 +467,9 @@ expand(const char *name)
                (void)snprintf(xname, sizeof(xname), "%s/%s", cmdbuf, name + 1);
                name = savestr(xname);
        }
+
        /* catch the most common shell meta character */
+jshell:
        if (name[0] == '~' && (name[1] == '/' || name[1] == '\0')) {
                (void)snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1);
                name = savestr(xname);
@@ -513,6 +520,16 @@ expand(const char *name)
 }
 
 /*
+ * Evaluate the string given.
+ * Return the file name as a dynamic string.
+ */
+PUBLIC const char *
+expand(const char *name)
+{
+       return _expand(name, 0);
+}
+
+/*
  * Return the name of the dead.letter file.
  */
 PUBLIC const char *
@@ -520,12 +537,12 @@ getdeadletter(void)
 {
        const char *cp;
 
-       if ((cp = value(ENAME_DEAD)) == NULL || (cp = expand(cp)) == NULL)
-               cp = expand("~/dead.letter");
+       if ((cp = value(ENAME_DEAD)) == NULL || (cp = _expand(cp, 0)) == NULL)
+               cp = _expand("~/dead.letter", 1);
        else if (*cp != '/') {
                char buf[PATHSIZE];
                (void)snprintf(buf, sizeof(buf), "~/%s", cp);
-               cp = expand(buf);
+               cp = _expand(buf, 1);
        }
        return cp;
 }


Home | Main Index | Thread Index | Old Index