summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2014-11-01 14:11:57 +0100
committerSteven Barth <steven@midlink.org>2014-11-01 14:52:29 +0100
commit174777181850705df7c6dbe234bd7e93d352666a (patch)
tree6f079c559397477163d91a7ad3a64c0bcd31a95b /utils
parentf83a9e2f677df368ff3a6deea5aaeca7f28cd46e (diff)
downloadunitd-174777181850705df7c6dbe234bd7e93d352666a.tar
unitd-174777181850705df7c6dbe234bd7e93d352666a.zip
Revert "Honour tty field in /etc/inittab"
This reverts commit e63051d9843ddbafb1fabfd97d60e853bdeac129. This unbreaks the initial console on UML and possibly other platforms. Signed-off-by: Steven Barth <cyrus@openwrt.org>
Diffstat (limited to 'utils')
-rw-r--r--utils/askfirst.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/utils/askfirst.c b/utils/askfirst.c
index e1f757a..6ad77aa 100644
--- a/utils/askfirst.c
+++ b/utils/askfirst.c
@@ -19,10 +19,34 @@
#include <unistd.h>
#include <fcntl.h>
+static int redirect_output(const char *dev)
+{
+ pid_t p = setsid();
+ int fd;
+
+ chdir("/dev");
+ fd = open(dev, O_RDWR);
+ chdir("/");
+
+ if (fd < 0)
+ return -1;
+
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ tcsetpgrp(fd, p);
+ close(fd);
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
int c;
+ if (redirect_output(argv[1]))
+ fprintf(stderr, "%s: Failed to open %s\n", argv[0], argv[1]);
+
printf("Please press Enter to activate this console.\n");
do {
c = getchar();
@@ -31,8 +55,8 @@ int main(int argc, char **argv)
}
while (c != 0xA);
- execvp(argv[1], &argv[1]);
- printf("%s: Failed to execute %s\n", argv[0], argv[1]);
+ execvp(argv[2], &argv[2]);
+ printf("%s: Failed to execute %s\n", argv[0], argv[2]);
return -1;
}