libos: Add a Process class
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-04-18 18:16:24 +02:00
parent fbb7de7156
commit 6ce125d286
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 27 additions and 6 deletions

View File

@ -3,6 +3,7 @@
#include <os/ArgumentParser.h>
#include <os/File.h>
#include <os/FileSystem.h>
#include <os/Process.h>
#include <errno.h>
#include <stddef.h>
@ -113,12 +114,7 @@ Result<int> luna_main(int argc, char** argv)
continue;
}
pid_t child = fork();
if (child < 0)
{
perror("fork");
return 1;
}
pid_t child = TRY(os::Process::fork());
if (child == 0) { execute_command(cmd.view()); }

View File

@ -7,6 +7,7 @@ set(SOURCES
src/ArgumentParser.cpp
src/File.cpp
src/FileSystem.cpp
src/Process.cpp
src/Main.cpp
)

View File

@ -0,0 +1,12 @@
#pragma once
#include <luna/Result.h>
#include <sys/types.h>
namespace os
{
class Process
{
public:
static Result<pid_t> fork();
};
}

12
libos/src/Process.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <os/Process.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace os
{
Result<pid_t> Process::fork()
{
long rc = syscall(SYS_fork);
return Result<pid_t>::from_syscall(rc);
}
}