mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:07:35 +00:00
Misc: Add a simple init process
This doesn't do much right now, just fork off a bunch of stuff and set priorities.
This commit is contained in:
parent
9cd0f6ffac
commit
d31ce9eccd
6 changed files with 95 additions and 52 deletions
|
@ -26,15 +26,6 @@
|
||||||
#include <Kernel/Net/NetworkTask.h>
|
#include <Kernel/Net/NetworkTask.h>
|
||||||
#include <Kernel/Devices/DebugLogDevice.h>
|
#include <Kernel/Devices/DebugLogDevice.h>
|
||||||
|
|
||||||
#define SPAWN_TERMINAL
|
|
||||||
#define SPAWN_LAUNCHER
|
|
||||||
//#define SPAWN_GUITEST2
|
|
||||||
//#define SPAWN_FILE_MANAGER
|
|
||||||
//#define SPAWN_PROCESS_MANAGER
|
|
||||||
//#define SPAWN_TEXT_EDITOR
|
|
||||||
//#define SPAWN_FONTEDITOR
|
|
||||||
//#define SPAWN_VISUAL_BUILDER
|
|
||||||
//#define SPAWN_MULTIPLE_SHELLS
|
|
||||||
//#define STRESS_TEST_SPAWNING
|
//#define STRESS_TEST_SPAWNING
|
||||||
|
|
||||||
VirtualConsole* tty0;
|
VirtualConsole* tty0;
|
||||||
|
@ -88,52 +79,12 @@ VFS* vfs;
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
auto* dns_lookup_server_process = Process::create_user_process("/bin/LookupServer", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
auto* system_server_process = Process::create_user_process("/bin/SystemServer", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
dbgprintf("error spawning LookupServer: %d\n", error);
|
dbgprintf("error spawning SystemServer: %d\n", error);
|
||||||
hang();
|
hang();
|
||||||
}
|
}
|
||||||
|
system_server_process->set_priority(Process::HighPriority);
|
||||||
auto* window_server_process = Process::create_user_process("/bin/WindowServer", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
||||||
if (error != 0) {
|
|
||||||
dbgprintf("error spawning WindowServer: %d\n", error);
|
|
||||||
hang();
|
|
||||||
}
|
|
||||||
window_server_process->set_priority(Process::HighPriority);
|
|
||||||
Process::create_user_process("/bin/Taskbar", (uid_t)100, (gid_t)100, (pid_t)0, error);
|
|
||||||
//Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
|
||||||
#ifdef SPAWN_TERMINAL
|
|
||||||
Process::create_user_process("/bin/Terminal", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_GUITEST2
|
|
||||||
Process::create_user_process("/bin/guitest2", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_LAUNCHER
|
|
||||||
Process::create_user_process("/bin/Launcher", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_VISUAL_BUILDER
|
|
||||||
Process::create_user_process("/bin/VisualBuilder", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_FILE_MANAGER
|
|
||||||
Process::create_user_process("/bin/FileManager", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_PROCESS_MANAGER
|
|
||||||
Process::create_user_process("/bin/ProcessManager", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_TEXT_EDITOR
|
|
||||||
Vector<String> text_editor_arguments;
|
|
||||||
text_editor_arguments.append("/bin/TextEditor");
|
|
||||||
text_editor_arguments.append("/home/anon/ReadMe.md");
|
|
||||||
Process::create_user_process("/bin/TextEditor", (uid_t)100, (gid_t)100, (pid_t)0, error, move(text_editor_arguments), { }, tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_FONTEDITOR
|
|
||||||
Process::create_user_process("/bin/FontEditor", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
|
||||||
#endif
|
|
||||||
#ifdef SPAWN_MULTIPLE_SHELLS
|
|
||||||
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty1);
|
|
||||||
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty2);
|
|
||||||
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty3);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STRESS_TEST_SPAWNING
|
#ifdef STRESS_TEST_SPAWNING
|
||||||
Process::create_kernel_process("spawn_stress", spawn_stress);
|
Process::create_kernel_process("spawn_stress", spawn_stress);
|
||||||
|
|
|
@ -13,6 +13,7 @@ build_targets=""
|
||||||
build_targets="$build_targets ../LibC"
|
build_targets="$build_targets ../LibC"
|
||||||
build_targets="$build_targets ../LibM"
|
build_targets="$build_targets ../LibM"
|
||||||
build_targets="$build_targets ../LibCore"
|
build_targets="$build_targets ../LibCore"
|
||||||
|
build_targets="$build_targets ../Servers/SystemServer"
|
||||||
build_targets="$build_targets ../Servers/LookupServer"
|
build_targets="$build_targets ../Servers/LookupServer"
|
||||||
build_targets="$build_targets ../Servers/WindowServer"
|
build_targets="$build_targets ../Servers/WindowServer"
|
||||||
build_targets="$build_targets ../LibGUI"
|
build_targets="$build_targets ../LibGUI"
|
||||||
|
|
|
@ -63,6 +63,7 @@ cp -v ../Applications/TextEditor/TextEditor mnt/bin/TextEditor
|
||||||
cp -v ../Applications/IRCClient/IRCClient mnt/bin/IRCClient
|
cp -v ../Applications/IRCClient/IRCClient mnt/bin/IRCClient
|
||||||
ln -s IRCClient mnt/bin/irc
|
ln -s IRCClient mnt/bin/irc
|
||||||
ln -s FileManager mnt/bin/fm
|
ln -s FileManager mnt/bin/fm
|
||||||
|
cp -v ../Servers/SystemServer/SystemServer mnt/bin/SystemServer
|
||||||
cp -v ../Servers/LookupServer/LookupServer mnt/bin/LookupServer
|
cp -v ../Servers/LookupServer/LookupServer mnt/bin/LookupServer
|
||||||
cp -v ../Servers/WindowServer/WindowServer mnt/bin/WindowServer
|
cp -v ../Servers/WindowServer/WindowServer mnt/bin/WindowServer
|
||||||
cp -v ../Applications/Taskbar/Taskbar mnt/bin/Taskbar
|
cp -v ../Applications/Taskbar/Taskbar mnt/bin/Taskbar
|
||||||
|
|
23
Servers/SystemServer/Makefile
Normal file
23
Servers/SystemServer/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
include ../../Makefile.common
|
||||||
|
|
||||||
|
SYSTEMSERVER_OBJS = \
|
||||||
|
main.o
|
||||||
|
|
||||||
|
APP = SystemServer
|
||||||
|
OBJS = $(SYSTEMSERVER_OBJS)
|
||||||
|
|
||||||
|
DEFINES += -DUSERLAND
|
||||||
|
|
||||||
|
all: $(APP)
|
||||||
|
|
||||||
|
$(APP): $(OBJS)
|
||||||
|
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lc -lcore
|
||||||
|
|
||||||
|
.cpp.o:
|
||||||
|
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
-include $(OBJS:%.o=%.d)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo "CLEAN"; rm -f $(APP) $(OBJS) *.d
|
||||||
|
|
4
Servers/SystemServer/install.sh
Executable file
4
Servers/SystemServer/install.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#mkdir -p ../../Root/usr/include/SystemServer/
|
||||||
|
#cp *.h ../../Root/usr/include/SystemServer/
|
63
Servers/SystemServer/main.cpp
Normal file
63
Servers/SystemServer/main.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <AK/Assertions.h>
|
||||||
|
|
||||||
|
void start_process(const char *prog, int prio)
|
||||||
|
{
|
||||||
|
pid_t pid = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
dbgprintf("Forking for %s...\n", prog);
|
||||||
|
int pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
dbgprintf("Fork %s failed! %s\n", prog, strerror(errno));
|
||||||
|
continue;
|
||||||
|
} else if (pid > 0) {
|
||||||
|
// parent...
|
||||||
|
dbgprintf("Process %s hopefully started with priority %d...\n", prog, prio);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (pid == 0) {
|
||||||
|
dbgprintf("Executing for %s... at prio %d\n", prog, prio);
|
||||||
|
struct sched_param p;
|
||||||
|
p.sched_priority = prio;
|
||||||
|
int ret = sched_setparam(pid, &p);
|
||||||
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
|
char* progv[256];
|
||||||
|
progv[0] = (char*)prog;
|
||||||
|
progv[1] = nullptr;
|
||||||
|
ret = execv(prog, progv);
|
||||||
|
if (ret < 0) {
|
||||||
|
dbgprintf("Exec %s failed! %s", prog, strerror(errno));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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/Taskbar", highest_prio);
|
||||||
|
start_process("/bin/Terminal", highest_prio-1);
|
||||||
|
start_process("/bin/Launcher", highest_prio);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue