2011-05-24 00:48:56 +02:00
|
|
|
#include <stdlib.h>
|
2011-05-24 17:23:10 +02:00
|
|
|
#include <stdio.h>
|
2011-05-24 00:48:56 +02:00
|
|
|
#include <string.h>
|
2011-05-24 17:23:10 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2011-05-24 00:48:56 +02:00
|
|
|
|
|
|
|
void showlogo() {
|
|
|
|
printf("\n\n");
|
|
|
|
printf("================================================================================\n");
|
|
|
|
printf(" m(etalsvm)shell\n\n");
|
2011-08-26 21:19:21 +02:00
|
|
|
printf(" Copyright 2011 Stefan Lankes, Chair for Operating Systems,\n");
|
2011-05-24 00:48:56 +02:00
|
|
|
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)
|
|
|
|
{
|
2011-07-30 19:48:44 +02:00
|
|
|
char* command = malloc(1024*sizeof(char));
|
2011-07-27 17:17:40 +02:00
|
|
|
|
2011-05-24 17:23:10 +02:00
|
|
|
int size, status = 0;
|
|
|
|
pid_t pid;
|
2011-05-24 00:48:56 +02:00
|
|
|
system("clear");
|
|
|
|
showlogo();
|
|
|
|
while(1) {
|
2011-07-30 19:48:44 +02:00
|
|
|
printf("$ ");
|
2011-05-24 00:48:56 +02:00
|
|
|
size = scanf("%s", command);
|
|
|
|
if(!strcmp(command, "exit")) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!strcmp(command, "help")) {
|
|
|
|
help();
|
2011-05-24 17:23:10 +02:00
|
|
|
} else {
|
2011-05-24 18:54:53 +02:00
|
|
|
pid = fork();
|
|
|
|
if (pid == 0) { //child
|
2011-05-24 17:23:10 +02:00
|
|
|
char* newargv[] = {command, NULL};
|
|
|
|
char* newenv[] = {"USER=root", "PATH=/bin:/sbin:/usr/bin", "PWD=/", "TEMP=/tmp", NULL};
|
|
|
|
|
|
|
|
execve(command, newargv, newenv);
|
|
|
|
return errno;
|
2011-05-24 18:54:53 +02:00
|
|
|
} else {
|
|
|
|
wait(&status);
|
|
|
|
}
|
2011-05-24 00:48:56 +02:00
|
|
|
}
|
2011-07-30 19:48:44 +02:00
|
|
|
}
|
2011-05-24 17:23:10 +02:00
|
|
|
return errno;
|
2011-05-24 00:48:56 +02:00
|
|
|
}
|
|
|
|
|