mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-13 22:47:15 -04:00
Work on logging
This commit is contained in:
parent
3938ab866c
commit
1cb20b40d0
@ -19,6 +19,7 @@ void finalize();
|
||||
void to_file();
|
||||
|
||||
void log(const char* s);
|
||||
void logf(const char* s, ...);
|
||||
void log(const std::string& s);
|
||||
|
||||
} //end of namespace logging
|
||||
|
@ -7,6 +7,10 @@
|
||||
|
||||
#include "logging.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "vfs/vfs.hpp"
|
||||
|
||||
#include <flags.hpp>
|
||||
#include <string.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
@ -18,6 +22,24 @@ constexpr const size_t MAX_EARLY = 128;
|
||||
size_t current_early = 0;
|
||||
const char* early_logs[MAX_EARLY];
|
||||
|
||||
const char* new_line = "\n";
|
||||
|
||||
void append_to_file(const char* s, size_t length){
|
||||
auto fd = vfs::open("/messages", std::OPEN_CREATE);
|
||||
|
||||
if(fd >= 0){
|
||||
stat_info info;
|
||||
if(vfs::stat(fd, info) == 0){
|
||||
if(vfs::truncate(fd, info.size + length + 1) == 0){
|
||||
vfs::write(fd, s, length, info.size);
|
||||
vfs::write(fd, new_line, 1, info.size + length);
|
||||
}
|
||||
}
|
||||
|
||||
vfs::close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
bool logging::is_early(){
|
||||
@ -29,37 +51,38 @@ bool logging::is_file(){
|
||||
}
|
||||
|
||||
void logging::finalize(){
|
||||
//Starting from there, the messages will be displayed on
|
||||
//the screen
|
||||
//Starting from there, the messages will be sent to the terminal
|
||||
early = false;
|
||||
}
|
||||
|
||||
void logging::to_file(){
|
||||
//Starting from there, the messages will be sent to the log file
|
||||
file = true;
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
||||
void logging::log(const char* s){
|
||||
if(is_early()){
|
||||
if(!is_early()){
|
||||
//TODO Display the string in the kernel terminal
|
||||
}
|
||||
|
||||
if(is_file()){
|
||||
append_to_file(s, std::str_len(s));
|
||||
} else {
|
||||
thor_assert(current_early < MAX_EARLY, "early log buffer is full");
|
||||
|
||||
early_logs[current_early++] = s;
|
||||
} else {
|
||||
if(is_file()){
|
||||
//TODO
|
||||
} else {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void logging::logf(const char* s, ...){
|
||||
//TODO
|
||||
}
|
||||
|
||||
void logging::log(const std::string& s){
|
||||
thor_assert(!is_early(), "log(string) in only valid in normal mode");
|
||||
thor_assert(is_file(), "log(string) in only valid file mode");
|
||||
|
||||
if(is_file()){
|
||||
//TODO
|
||||
} else {
|
||||
//TODO
|
||||
}
|
||||
//TODO Display the string in the kernel terminal
|
||||
|
||||
append_to_file(s.c_str(), s.size());
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "physical_pointer.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include "kernel_utils.hpp"
|
||||
#include "logging.hpp"
|
||||
|
||||
constexpr const bool DEBUG_SCHEDULER = false;
|
||||
|
||||
@ -594,6 +595,8 @@ void scheduler::init(){ //Create the idle task
|
||||
void scheduler::start(){
|
||||
started = true;
|
||||
|
||||
logging::log("Start multiprocessing");
|
||||
|
||||
init_task_switch(current_pid);
|
||||
}
|
||||
|
||||
@ -648,6 +651,8 @@ int64_t scheduler::exec(const std::string& file, const std::vector<std::string>&
|
||||
pcb[process.pid].working_directory.push_back(p);
|
||||
}
|
||||
|
||||
logging::logf("Exec process pid=%u, ppid=%u", process.pid, process.ppid);
|
||||
|
||||
return process.pid;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user