diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-29 00:35:43 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-29 00:35:43 +0200 |
| commit | 8afeed1a607f70606a81ab39cac8d684964fdab1 (patch) | |
| tree | 7459af60da66569d7500acc77d8b1c53840a1a33 | |
| parent | 29f6aee4d9c8df7375b369ddba9121f1cb4498bf (diff) | |
| download | pipeln-8afeed1a607f70606a81ab39cac8d684964fdab1.tar.gz pipeln-8afeed1a607f70606a81ab39cac8d684964fdab1.zip | |
Rename main.c to pipeln.c and properly close fds
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | build.jst.tmpl | 3 | ||||
| -rw-r--r-- | pipeln.c (renamed from main.c) | 7 |
3 files changed, 10 insertions, 6 deletions
@@ -3,11 +3,9 @@ BINDIR ?= /bin CFLAGS = -std=c99 -Wunused-variable -Wunused-function -Wconversion -O2 - all: pipeln -pipeln: main.c - $(CC) -o $@ $^ $(CFLAGS) +pipeln: pipeln.c clean: rm -f pipeln @@ -17,3 +15,5 @@ install: uninstall: rm -f "$(DESTDIR)$(PREFIX)$(BINDIR)/pipeln" + +.PHONY: all clean install uninstall diff --git a/build.jst.tmpl b/build.jst.tmpl index c895481..044f750 100644 --- a/build.jst.tmpl +++ b/build.jst.tmpl @@ -19,7 +19,7 @@ rule cc #{CC} -o $out $in $cflags target pipeln - cc main.c + cc pipeln.c command install install -m755 pipeln -t "#{DESTDIR}#{PREFIX}#{BINDIR}" @@ -32,3 +32,4 @@ command clean command all just pipeln + @@ -83,18 +83,21 @@ run(int *in, int *out, const char **argv) if (!child) { if (in) { - close(0); if (dup2(in[0], 0) < 0) die("dup2:"); + close(in[0]); + close(in[1]); } if (out) { - close(1); if (dup2(out[1], 1) < 0) die("dup2:"); + close(out[0]); + close(out[1]); } execv(argv[0], (char *const *) argv); die("execv %s:", argv[0]); } + if (in) close(in[0]); if (out) close(out[1]); } |
