Merge branch 'mshell' into readwrite

This commit is contained in:
Marian Ohligs 2011-05-24 23:33:01 +02:00
commit 240d7f65c3
5 changed files with 63 additions and 9 deletions

View file

@ -119,7 +119,7 @@ static int STDCALL join_test(void* arg)
int test_init(void)
{
char* argv[] = {"/bin/tests", NULL};
char* argv[] = {"/bin/mshell", NULL};
//sem_init(&producing, 1);
//sem_init(&consuming, 0);
@ -131,7 +131,7 @@ int test_init(void)
//create_kernel_task(NULL, consumer, NULL);
//create_kernel_task(NULL, ping, NULL);
//create_user_task(NULL, "/bin/hello", argv);
create_user_task(NULL, "/bin/tests", argv);
create_user_task(NULL, "/bin/mshell", argv);
//create_user_task(NULL, "/bin/jacobi", argv);
return 0;

View file

@ -11,7 +11,7 @@ LDFLAGS =
default: all
all: hello tests jacobi hangman
all: hello tests jacobi hangman mshell
jacobi: jacobi.o
$(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< -lm
@ -37,9 +37,14 @@ hangman: hangman.o
$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@
chmod a-x $@.sym
mshell: mshell.o
$(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $<
$(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym
$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@
chmod a-x $@.sym
clean:
$(RM) hello tests *.sym *.o *~
$(RM) hello hangman jacobi mshell tests *.sym *.o *~
depend:
$(CC_FOR_TARGET) -MM $(CFLAGS) *.c > Makefile.dep

View file

@ -27,10 +27,6 @@ extern int errno;
int main(int argc, char** argv)
{
int i;
char* str = (char *)malloc(40000 * sizeof(char));
scanf("%s", str);
printf("SCANF: %s", str);
fflush(NULL);
printf("test!");
return errno;
}

BIN
newlib/examples/mshell Executable file

Binary file not shown.

53
newlib/examples/mshell.c Normal file
View file

@ -0,0 +1,53 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
void showlogo() {
printf("\n\n");
printf("================================================================================\n");
printf(" m(etalsvm)shell\n\n");
printf(" Copyright 2010 Stefan Lankes, Chair for Operating Systems,\n");
printf(" RWTH Aachen University\n\n");
printf("================================================================================\n");
}
void help() {
printf("possible commands: \n");
printf("exit > exit shell \n");
}
int main(int argc, char** argv)
{
char* command = malloc(1024*sizeof(char));
int size, status = 0;
pid_t pid;
system("clear");
showlogo();
while(1) {
printf("$ ");
size = scanf("%s", command);
if(!strcmp(command, "exit")) {
return 0;
}
if(!strcmp(command, "help")) {
help();
} else {
pid = fork();
if (pid == 0) { //child
char* newargv[] = {command, NULL};
char* newenv[] = {"USER=root", "PATH=/bin:/sbin:/usr/bin", "PWD=/", "TEMP=/tmp", NULL};
execve(command, newargv, newenv);
return errno;
} else {
wait(&status);
}
}
}
return errno;
}