From 6778abb99950efaea21bdd220a18129f575598c3 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sat, 17 Aug 2019 12:33:39 +0300 Subject: [PATCH] Kernel+SystemServer: Mount filesystems and start TTYServer in userspace --- Base/etc/fstab | 4 ++++ Kernel/init.cpp | 37 +-------------------------------- Servers/SystemServer/main.cpp | 39 ++++++++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 44 deletions(-) create mode 100644 Base/etc/fstab diff --git a/Base/etc/fstab b/Base/etc/fstab new file mode 100644 index 0000000000..cd18feb762 --- /dev/null +++ b/Base/etc/fstab @@ -0,0 +1,4 @@ +/dev/hda / ext2 +proc /proc proc +devpts /dev/pts devpts +tmp /tmp tmp diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 650cbb8992..1cfa0157fd 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -118,20 +118,6 @@ VFS* vfs; load_ksyms(); dbgprintf("Loaded ksyms\n"); - // TODO: we should mount these from SystemServer - auto procfs = ProcFS::create(); - procfs->initialize(); - vfs->mount(procfs, "/proc"); - - auto devptsfs = DevPtsFS::create(); - devptsfs->initialize(); - vfs->mount(devptsfs, "/dev/pts"); - - auto tmpfs = TmpFS::create(); - if (!tmpfs->initialize()) - ASSERT_NOT_REACHED(); - vfs->mount(move(tmpfs), "/tmp"); - // Now, detect whether or not there are actually any floppy disks attached to the system u8 detect = CMOS::read(0x10); RefPtr fd0; @@ -152,34 +138,13 @@ VFS* vfs; int error; - auto* system_server_process = Process::create_user_process("/bin/SystemServer", (uid_t)100, (gid_t)100, (pid_t)0, error, {}, {}, tty0); + auto* system_server_process = Process::create_user_process("/bin/SystemServer", (uid_t)0, (gid_t)0, (pid_t)0, error, {}, {}, tty0); if (error != 0) { kprintf("init_stage2: error spawning SystemServer: %d\n", error); hang(); } system_server_process->set_priority(Process::HighPriority); - auto* tty1_process = Process::create_user_process("/bin/TTYServer", (uid_t)0, (gid_t)0, (pid_t)0, error, { "/bin/TTYServer", "tty1" }, {}, tty1); - if (error != 0) { - kprintf("init_stage2: error spawning TTYServer for tty1: %d\n", error); - hang(); - } - tty1_process->set_priority(Process::HighPriority); - - auto* tty2_process = Process::create_user_process("/bin/TTYServer", (uid_t)0, (gid_t)0, (pid_t)0, error, { "/bin/TTYServer", "tty2" }, {}, tty2); - if (error != 0) { - kprintf("init_stage2: error spawning TTYServer for tty2: %d\n", error); - hang(); - } - tty2_process->set_priority(Process::HighPriority); - - auto* tty3_process = Process::create_user_process("/bin/TTYServer", (uid_t)0, (gid_t)0, (pid_t)0, error, { "/bin/TTYServer", "tty3" }, {}, tty3); - if (error != 0) { - kprintf("init_stage2: error spawning TTYServer for tty3: %d\n", error); - hang(); - } - tty3_process->set_priority(Process::HighPriority); - current->process().sys$exit(0); ASSERT_NOT_REACHED(); } diff --git a/Servers/SystemServer/main.cpp b/Servers/SystemServer/main.cpp index 57cda02920..43a688e392 100644 --- a/Servers/SystemServer/main.cpp +++ b/Servers/SystemServer/main.cpp @@ -1,13 +1,14 @@ #include #include #include +#include #include #include #include #include #include -void start_process(const char* prog, int prio) +void start_process(const char* prog, const char* arg, int prio, const char* tty = nullptr) { pid_t pid = 0; @@ -32,9 +33,17 @@ void start_process(const char* prog, int prio) int ret = sched_setparam(pid, &p); ASSERT(ret == 0); + if (tty != nullptr) { + close(0); + ASSERT(open(tty, O_RDWR) == 0); + dup2(0, 1); + dup2(0, 2); + } + char* progv[256]; progv[0] = const_cast(prog); - progv[1] = nullptr; + progv[1] = const_cast(arg); + progv[2] = nullptr; ret = execv(prog, progv); if (ret < 0) { dbgprintf("Exec %s failed! %s", prog, strerror(errno)); @@ -72,12 +81,26 @@ int main(int, char**) { int lowest_prio = sched_get_priority_min(SCHED_OTHER); int highest_prio = sched_get_priority_max(SCHED_OTHER); - start_process("/bin/LookupServer", lowest_prio); - start_process("/bin/WindowServer", highest_prio); - start_process("/bin/AudioServer", highest_prio); - start_process("/bin/Taskbar", highest_prio); - start_process("/bin/Terminal", highest_prio - 1); - start_process("/bin/Launcher", highest_prio); + + // Mount the filesystems. + start_process("/bin/mount", "-a", highest_prio); + wait(nullptr); + + start_process("/bin/TTYServer", "tty0", highest_prio, "/dev/tty0"); + start_process("/bin/TTYServer", "tty1", highest_prio, "/dev/tty1"); + start_process("/bin/TTYServer", "tty2", highest_prio, "/dev/tty2"); + start_process("/bin/TTYServer", "tty3", highest_prio, "/dev/tty3"); + + // Drop privileges. + setuid(100); + setgid(100); + + start_process("/bin/LookupServer", nullptr, lowest_prio); + start_process("/bin/WindowServer", nullptr, highest_prio); + start_process("/bin/AudioServer", nullptr, highest_prio); + start_process("/bin/Taskbar", nullptr, highest_prio); + start_process("/bin/Terminal", nullptr, highest_prio - 1); + start_process("/bin/Launcher", nullptr, highest_prio); // This won't return if we're in test mode. check_for_test_mode();