From b26399ad055aae9ef4b01694967515235568cd85 Mon Sep 17 00:00:00 2001
From: dzwdz
Date: Sat, 30 Jul 2022 14:52:22 +0200
Subject: user: stderr

---
 src/user/app/init/init.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

(limited to 'src/user/app/init')

diff --git a/src/user/app/init/init.c b/src/user/app/init/init.c
index d7dc34d..bb92cce 100644
--- a/src/user/app/init/init.c
+++ b/src/user/app/init/init.c
@@ -6,20 +6,21 @@
 #include <unistd.h>
 #include <user/lib/fs/misc.h>
 
+#define die(fmt, ...) do { fprintf(stderr, "init: " fmt, __VA_ARGS__); exit(1); } while (0)
+
 void redirect(const char *exe, const char *out, const char *in) {
 	if (!fork()) {
-		if (!freopen(out, "a+", stdout)) {
-			printf("init: couldn't open %s\n", out); // TODO borked
-			exit(1);
-		}
-		if (!freopen(in, "r", stdin)) {
-			printf("init: couldn't open %s\n", in);
+		if (!freopen(out, "a+", stderr)) {
+			fprintf(stdout, "couldn't open %s\n", out);
 			exit(1);
 		}
+		if (!freopen(out, "a+", stdout))
+			die("couldn't open %s\n", out);
+		if (!freopen(in, "r", stdin))
+			die(" couldn't open %s\n", in);
 		termcook();
 		execv(exe, NULL);
-		printf("couldn't start %s\n", exe);
-		exit(1);
+		die("couldn't start %s\n", exe);
 	}
 }
 
-- 
cgit v1.2.3