summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-07-29 00:35:43 +0200
committerLouis Burda <quent.burda@gmail.com>2023-07-29 00:35:43 +0200
commit8afeed1a607f70606a81ab39cac8d684964fdab1 (patch)
tree7459af60da66569d7500acc77d8b1c53840a1a33
parent29f6aee4d9c8df7375b369ddba9121f1cb4498bf (diff)
downloadpipeln-8afeed1a607f70606a81ab39cac8d684964fdab1.tar.gz
pipeln-8afeed1a607f70606a81ab39cac8d684964fdab1.zip
Rename main.c to pipeln.c and properly close fds
-rw-r--r--Makefile6
-rw-r--r--build.jst.tmpl3
-rw-r--r--pipeln.c (renamed from main.c)7
3 files changed, 10 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index e7f1f9b..62e95b5 100644
--- a/Makefile
+++ b/Makefile
@@ -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
+
diff --git a/main.c b/pipeln.c
index 9a4d77d..f0578ea 100644
--- a/main.c
+++ b/pipeln.c
@@ -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]);
}