diff options
-rw-r--r-- | getty.c | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -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; } |