]> Trent Huber's Code - thus.git/commitdiff
Fix pipes
authorTrent Huber <trentmhuber@gmail.com>
Thu, 4 Sep 2025 23:05:41 +0000 (19:05 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Thu, 4 Sep 2025 23:05:41 +0000 (19:05 -0400)
src/parse.c
src/run.c

index b81a33e9c3411c8a13206e70bd46c326d06a21c1..bda7ae19b5ee26fed8a1bfbef736935a5b58b906 100644 (file)
@@ -20,14 +20,15 @@ int parse(struct context *c) {
        if (!c->input(c)) return 0;
        c->b = c->buffer;
    }
-   if (globs.gl_pathc) {
-       globfree(&globs);
-       globs.gl_pathc = 0;
-   }
    c->t = c->tokens;
    c->r = c->redirects;
    c->r->mode = NONE;
    c->prev = c->current;
+
+   if (globs.gl_pathc) {
+       globfree(&globs);
+       globs.gl_pathc = 0;
+   }
    prevsublen = globbing = 0;
 
    for (*c->t = c->b; *c->b; ++c->b) switch (*c->b) {
index 105c0f81f6cf0a98deb028c0ea4f441541b7996f..375bf1f9db9fe0bd7fee0e46f6c7293f3c765853 100644 (file)
--- a/src/run.c
+++ b/src/run.c
@@ -74,6 +74,7 @@ int run(struct context *c) {
    setsigchld(&actbg);
    if (!parse(c)) return 0;
    setsigchld(&actdefault);
+
    islist = c->prev.term > BG || c->current.term > BG;
    if (c->t) {
        if (c->current.term == BG && fullbg()) {
@@ -82,9 +83,7 @@ int run(struct context *c) {
        }
        if (!(path = getpath(c->current.name))) {
            note("Couldn't find `%s' command", c->current.name);
-           if (c->prev.term == PIPE) {
-               killpg(pipeid, SIGKILL);
-           }
+           if (c->prev.term == PIPE) killpg(pipeid, SIGKILL);
            return quit(c);
        }
 
@@ -114,7 +113,7 @@ int run(struct context *c) {
                }
                exec(path, c);
            }
-           if (ispipestart) pipeid = cpid;
+           if (ispipestart) pipeid = cpid; else closepipe(c->prev);
            jobid = pipeid;
        } else if (!c->r && isbuiltin(c->tokens)) cpid = 0;
        else if ((jobid = cpid = fork()) == -1) {