Compare commits
3 Commits
b6fb5f3dfe
...
a18e50ff34
Author | SHA1 | Date | |
---|---|---|---|
a18e50ff34 | |||
d63c8abbfd | |||
e2eb9a92cb |
@ -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
41
apps/cat.c
Normal 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
35
apps/edit.c
Normal 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;
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user