Compare commits

...

3 Commits

Author SHA1 Message Date
a18e50ff34
apps: Add cat and edit
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-24 00:52:26 +01:00
d63c8abbfd
kernel/x86_64: Terminate page faults in a waitpid-friendly way 2023-03-24 00:52:17 +01:00
e2eb9a92cb
sh: Don't do anything if Enter is pressed with no command 2023-03-24 00:51:42 +01:00
5 changed files with 83 additions and 1 deletions

View File

@ -7,4 +7,6 @@ function(luna_app SOURCE_FILE APP_NAME)
endfunction()
luna_app(init.c init)
luna_app(cat.c cat)
luna_app(edit.c edit)
luna_app(sh.c sh)

41
apps/cat.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void do_cat(FILE* f)
{
char buffer[4096];
while (1)
{
size_t nread = fread(buffer, 1, sizeof(buffer), f);
if (nread == 0) return;
fwrite(buffer, 1, nread, stdout);
}
}
int main(int argc, char** argv)
{
FILE* f;
if (argc < 2) { do_cat(stdin); }
else
{
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-")) f = stdin;
else
{
f = fopen(argv[i], "r");
if (!f)
{
perror(argv[i]);
return 1;
}
}
do_cat(f);
if (f != stdin) fclose(f);
}
}
}

35
apps/edit.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
FILE* f;
if (argc < 2)
{
fprintf(stderr, "usage: %s [file]", argv[0]);
return 1;
}
f = fopen(argv[1], "w");
if (!f)
{
perror(argv[1]);
return 1;
}
char buffer[4096];
while (1)
{
char* rc = fgets(buffer, sizeof(buffer), stdin);
if (rc == 0) break;
if (!strcmp(rc, "EOF\n")) break;
fputs(buffer, f);
}
fclose(f);
return 0;
}

View File

@ -90,6 +90,7 @@ int main()
if (child == 0)
{
char** argv = split_command_into_argv(command);
if (argv[0] == NULL) return 0;
sh_execvp(argv);
perror(argv[0]);
return 1;

View File

@ -71,7 +71,10 @@ void decode_page_fault_error_code(u64 code)
{
// FIXME: Kill this process with SIGSEGV once we have signals and all that.
kerrorln("Current task %zu was terminated because of a page fault", Scheduler::current()->id);
kernel_exit();
Scheduler::current()->state = ThreadState::Exited;
Scheduler::current()->status = 127;
kernel_yield();
unreachable();
}
CPU::print_stack_trace_at(regs);