]> git.pond.sub.org Git - empserver/commitdiff
(dopipe): Check whether argument starts with '|'. Simplify convoluted
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 17 Nov 2007 09:10:29 +0000 (09:10 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 17 Nov 2007 09:10:29 +0000 (09:10 +0000)
logic.  Improve error messages.

src/client/servcmd.c

index 40f28be6bb46107a567f2c249a45f7ebfc42751e..c6fe0542112446d0db003269bac8b03cbb172dcf 100644 (file)
@@ -236,25 +236,27 @@ dopipe(char *p)
 {
     char *tag;
 
-    if (*p == '|')
-       p++;
+    if (*p++ != '|') {
+       fprintf(stderr, "WARNING!  Weird pipe %s", p);
+       return;
+    }
+
     tag = gettag(p);
-    while (*p && isspace(*p))
-       p++;
     if (tag == NULL) {
        fprintf(stderr, "WARNING!  Server attempted to run: %s\n", p);
        return;
     }
+    free(tag);
+
+    for (; *p && isspace(*p); p++) ;
     if (*p == 0) {
-       fprintf(stderr, "Null program name after redirect\n");
-       free(tag);
+       fprintf(stderr, "Redirection lacks a command\n");
        return;
     }
     if ((pipe_fp = popen(p, "w")) == NULL) {
-       fprintf(stderr, "Pipe open failed\n");
-       perror(p);
+       fprintf(stderr, "Can't redirect to pipe %s: %s\n",
+               p, strerror(errno));
     }
-    free(tag);
 }
 
 static void