summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ungol.org>2020-03-31 18:36:21 -0400
committerJakob Kaivo <jkk@ungol.org>2020-03-31 18:36:21 -0400
commit2cccc6ea7ff16cb4166582168edeebefd406ff85 (patch)
treeb4331945c024091605245f6a26399212f8ecee23
parent55cd5da33c56ba4e8bbeb84d535a73dd724fdde5 (diff)
add (sadly) Linux-specific ioctl() to set controlling terminal
-rw-r--r--getty.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/getty.c b/getty.c
index 45ff830..e44f299 100644
--- a/getty.c
+++ b/getty.c
@@ -30,6 +30,12 @@
#include <string.h>
#include <unistd.h>
+#ifdef __linux__
+#include <sys/ioctl.h>
+#define DEFAULT_GETTY_COMMAND "/bin/login"
+#define DEFAULT_GETTY_TYPE "vt100"
+#endif
+
#ifndef DEFAULT_GETTY_COMMAND
#define DEFAULT_GETTY_COMMAND "/sys/bin/login"
#endif
@@ -74,7 +80,9 @@ int main(int argc, char *argv[])
return 1;
}
- int fd = open(device, O_RDWR, 0600);
+ setsid();
+
+ int fd = open(device, O_RDWR | O_CLOEXEC | O_TTY_INIT, 0600);
if (fd == -1) {
fprintf(stderr, "getty: %s: %s\n", device, strerror(errno));
return 1;
@@ -85,16 +93,20 @@ int main(int argc, char *argv[])
return 1;
}
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
+
+ #ifdef __linux__
+ if (ioctl (fd, TIOCSCTTY, (void *) 1) == -1) {
+ perror("ioctl");
+ }
+ #endif
+
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
- close(fd);
setenv("TERM", type, 1);
- /* TODO: wordexp() + execv() */
- execl("/bin/sh", "/bin/sh", "-c", command, (char*)NULL);
+ /* TODO: wordexp() */
+ char *args[] = { command, NULL };
+ execv(args[0], args);
return 1;
}