summary refs log tree commit diff
path: root/sbin/fdmaker/fdmaker.c
blob: 95ef98c524367b197806da691ff14dfb6aef0fc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <string.h>

int main() {
    // make process be sigma (why did i think of this)
    if (setsid() < 0) {
        perror("setsid");
        exit(1);
    }

    // >open /dev/tty1
    // >look inside
    // >Failed to open /dev/tty1
    int fd = open("/dev/tty1", O_RDWR);
    if (fd == -1) {
        write(2, "Failed to open /dev/tty1\n", 26);
        exit(1);
    }
    // make tty1 be the displayed tty
    if (ioctl(fd, TIOCSCTTY, 0) < 0) {
        write(2, "ioctl TIOCSCTTY", 16);
        exit(1);
    }
    char path[128] = {0};
    int len = write(fd, "\nEnter path to shell (nothing for /bin/shel): ", 47);
    path[len - 1] = '\0';
    read(0, path, sizeof(path));
    if (len == 47) {
        strcpy(path, "/bin/shel");
    }
    // write(1, path, strlen(path));
    write(fd, "\e[2J\e[0;0Hwelcome to nyaOS - a distro made by an idiot with no C experience that still somehow works\n\n", 103);
    
    execve(path, 0, 0);
}