awk: ignore SIGPIPE

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

awk: ignore SIGPIPE

Matthias Kilian
Hi,

IMHO, awk(1) should ignore SIGPIPE. Currently, if awk(1) get's a
SIGPIPE when writing to a pipe, it just dies. With the patch below,
it dies, too, but at least you get a reasonable error message.

diff -x CVS -rNu ../awk.orig/main.c ./main.c
--- ../awk.orig/main.c Thu Dec 30 14:06:17 2004
+++ ./main.c Wed Mar 29 15:05:20 2006
@@ -69,6 +69,7 @@
  exit(1);
  }
  signal(SIGFPE, fpecatch);
+ signal(SIGPIPE, SIG_IGN);
  yyin = NULL;
  symtab = makesymtab(NSYMTAB);
  while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {


Sample awk script:

#!/usr/bin/awk -f
BEGIN {
        for (i = 0; i < 32768; i++)
                print "" | "./foo"
        x = close("./foo")
        print x
}


Matching "foo":

#!/bin/sh
echo foo


Any Comments?


Ciao,
        Kili

ps: I've some more diffs to awk(1) around, but I first have to sort
out what's usable and what is junk or still incomplete.