Compare commits
No commits in common. "a815beacfb5d399d0a97bdbc3b2027cb919b2b0c" and "7e9744419ed6013e60fe7b34181f0258f65c5f62" have entirely different histories.
a815beacfb
...
7e9744419e
@ -67,14 +67,11 @@ int main()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t result;
|
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
while ((result = wait(NULL)) == 0) // No child has exited yet
|
while (wait(NULL) == 0) // No child has exited yet
|
||||||
{
|
{
|
||||||
msleep(100);
|
msleep(100);
|
||||||
}
|
}
|
||||||
if (result == child) { return 0; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include <luna.h>
|
#include <luna.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -10,8 +9,8 @@ static int status;
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char* buffer;
|
char* buffer;
|
||||||
size_t size;
|
long size;
|
||||||
size_t capacity;
|
long capacity;
|
||||||
} command;
|
} command;
|
||||||
|
|
||||||
void show_prompt()
|
void show_prompt()
|
||||||
@ -19,33 +18,6 @@ void show_prompt()
|
|||||||
printf("[%ld]> ", getpid());
|
printf("[%ld]> ", getpid());
|
||||||
}
|
}
|
||||||
|
|
||||||
int command_matches(command* cmd, const char* string)
|
|
||||||
{
|
|
||||||
if (cmd->size <= strlen(string)) // cmd->size includes null terminator
|
|
||||||
return 0;
|
|
||||||
return strncmp(cmd->buffer, string, strlen(string)) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int command_matches_exactly(command* cmd, const char* string)
|
|
||||||
{
|
|
||||||
if (cmd->size <= strlen(string)) // cmd->size includes null terminator
|
|
||||||
return 0;
|
|
||||||
if (cmd->size > (strlen(string) + 1)) return 0;
|
|
||||||
return strncmp(cmd->buffer, string, strlen(string)) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int command_match_builtins(command* cmd)
|
|
||||||
{
|
|
||||||
if (command_matches(cmd, "exit ")) { exit(atoi(cmd->buffer + 5)); }
|
|
||||||
if (command_matches_exactly(cmd, "exit")) { exit(0); }
|
|
||||||
if (command_matches_exactly(cmd, "pid"))
|
|
||||||
{
|
|
||||||
printf("pid %ld, ppid %ld\n", getpid(), getppid());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void command_expand(command* cmd, long new_capacity)
|
void command_expand(command* cmd, long new_capacity)
|
||||||
{
|
{
|
||||||
char* buffer = realloc(cmd->buffer, new_capacity);
|
char* buffer = realloc(cmd->buffer, new_capacity);
|
||||||
@ -86,12 +58,6 @@ void command_clear(command* cmd)
|
|||||||
void command_execute(command* cmd)
|
void command_execute(command* cmd)
|
||||||
{
|
{
|
||||||
command_push(cmd, '\0');
|
command_push(cmd, '\0');
|
||||||
if (command_match_builtins(cmd))
|
|
||||||
{
|
|
||||||
command_clear(cmd);
|
|
||||||
show_prompt();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pid_t child = fork();
|
pid_t child = fork();
|
||||||
if (child < 0)
|
if (child < 0)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "memory/PMM.h"
|
#include "memory/PMM.h"
|
||||||
#include "memory/VMM.h"
|
#include "memory/VMM.h"
|
||||||
#include "misc/hang.h"
|
#include "misc/hang.h"
|
||||||
#include "misc/reboot.h"
|
|
||||||
#include "misc/utils.h"
|
#include "misc/utils.h"
|
||||||
#include "panic/Panic.h"
|
#include "panic/Panic.h"
|
||||||
#include "std/assert.h"
|
#include "std/assert.h"
|
||||||
@ -281,7 +280,6 @@ void Scheduler::task_exit(Context* context, int64_t status)
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else { reboot(); }
|
|
||||||
task_yield(context);
|
task_yield(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +298,6 @@ void Scheduler::task_misbehave(Context* context, int64_t status)
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else { reboot(); }
|
|
||||||
task_yield(context);
|
task_yield(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user