*/
void Threads_Exit(int TID, int Status)
{
- Threads_Kill( Proc_GetCurThread(), (Uint)Status & 0xFF );
+ if( TID == 0 )
+ Threads_Kill( Proc_GetCurThread(), (Uint)Status & 0xFF );
+ else
+ Threads_Kill( Threads_GetThread(TID), (Uint)Status & 0xFF );
}
/**
tMsg *msg;
// Kill all children
- #if 0
+ #if 1
{
tThread *child;
for(child = gActiveThreads;
child;
child = child->Next)
{
- if(child->PTID == gCurrentThread->TID)
+ if(child->PTID == Thread->TID)
Threads_Kill(child, -1);
}
}
/**
* \fn void Threads_SendSignal(int TID, int Num)
+ * \brief Send a signal to a thread
*/
void Threads_SendSignal(int TID, int Num)
{
return thread;
}
+
+/**
+ * \fn void Threads_SegFault(tVAddr Addr)
+ * \brief Called when a Segment Fault occurs
+ */
+void Threads_SegFault(tVAddr Addr)
+{
+ //Threads_SendSignal( Proc_GetCurThread()->TID, SIGSEGV );
+ Threads_Kill( Proc_GetCurThread(), 0 );
+}
{"colour", Command_Colour}, {"clear", Command_Clear},\r
{"cd", Command_Cd}, {"dir", Command_Dir}\r
};\r
+static char *cDEFAULT_PATH[] = {"/Acess"};\r
#define BUILTIN_COUNT (sizeof(cBUILTINS)/sizeof(cBUILTINS[0]))\r
\r
// ==== LOCAL VARIABLES ====\r
+ int giNumPathDirs = 1;\r
+char **gasPathDirs = cDEFAULT_PATH;\r
char **gasEnvironment;\r
char gsCommandBuffer[1024];\r
char *gsCurrentDirectory = NULL;\r
-char gsTmpBuffer[1024];\r
char **gasCommandHistory;\r
int giLastCommand = 0;\r
int giCommandSpace = 0;\r
char *sCommandStr;\r
char *saArgs[32];\r
int length = 0;\r
+ int i;\r
int iArgCount = 0;\r
int bCached = 1;\r
\r
if(saArgs[1][0] == '\0') continue;\r
\r
// Check Built-In Commands\r
- // [HACK] Mem Usage - Use Length in place of `i'\r
- for(length=0;length<BUILTIN_COUNT;length++)\r
+ for( i = 0; i < BUILTIN_COUNT; i++ )\r
{\r
- if(strcmp(saArgs[1], cBUILTINS[length].name) == 0)\r
+ if( strcmp(saArgs[1], cBUILTINS[i].name) == 0 )\r
{\r
- cBUILTINS[length].fcn(iArgCount-1, &saArgs[1]);\r
+ cBUILTINS[i].fcn(iArgCount-1, &saArgs[1]);\r
break;\r
}\r
}\r
- \r
- if(length != BUILTIN_COUNT) continue;\r
+ if(i != BUILTIN_COUNT) continue;\r
\r
// Shall we?\r
CallCommand( &saArgs[1] );\r
// Preset Variables\r
ret = malloc( space+1 );\r
if(!ret) return NULL;\r
- len = 0;\r
- pos = 0;\r
+ len = 0; pos = 0;\r
\r
// Read In Command Line\r
do {\r
t_sysFInfo info;\r
int pid = -1;\r
int fd = 0;\r
+ char sTmpBuffer[1024];\r
+ char *exefile = Args[0];\r
\r
- \r
- // - Calling a file\r
- GeneratePath(Args[0], gsCurrentDirectory, gsTmpBuffer);\r
- \r
- \r
- // Check file existence\r
- fd = open(gsTmpBuffer, 0);\r
- if(fd == -1) {\r
- Print("Unknown Command: `");Print(Args[0]);Print("'\n"); // Error Message\r
- return ;\r
+ if(exefile[0] == '/'\r
+ || (exefile[0] == '.' && exefile[1] == '/')\r
+ || (exefile[0] == '.' && exefile[1] == '.' && exefile[2] == '/')\r
+ )\r
+ {\r
+ GeneratePath(exefile, gsCurrentDirectory, sTmpBuffer);\r
+ // Check file existence\r
+ fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
+ if(fd == -1) {\r
+ Print("Unknown Command: `");Print(Args[0]);Print("'\n"); // Error Message\r
+ return ;\r
+ }\r
+ \r
+ // Get File info and close file\r
+ finfo( fd, &info, 0 );\r
+ close( fd );\r
+ \r
+ // Check if the file is a directory\r
+ if(info.flags & FILEFLAG_DIRECTORY) {\r
+ Print("`");Print(sTmpBuffer); // Error Message\r
+ Print("' is a directory.\n");\r
+ return ;\r
+ }\r
}\r
- \r
- // Check if the file is a directory\r
- finfo( fd, &info, 0 );\r
- close( fd );\r
- if(info.flags & FILEFLAG_DIRECTORY) {\r
- Print("`");Print(gsTmpBuffer); // Error Message\r
- Print("' is a directory.\n");\r
- return ;\r
+ else\r
+ {\r
+ int i;\r
+ \r
+ // Check all components of $PATH\r
+ for( i = 0; i < giNumPathDirs; i++ )\r
+ {\r
+ GeneratePath(exefile, gasPathDirs[i], sTmpBuffer);\r
+ fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
+ if(fd == -1) continue;\r
+ finfo( fd, &info, 0 );\r
+ close( fd );\r
+ if(info.flags & FILEFLAG_DIRECTORY) continue;\r
+ // Woohoo! We found a valid command\r
+ break;\r
+ }\r
+ \r
+ // Exhausted path directories\r
+ if( i == giNumPathDirs ) {\r
+ Print("Unknown Command: `");Print(exefile);Print("'\n");\r
+ return ;\r
+ }\r
}\r
\r
// Create new process\r
pid = clone(CLONE_VM, 0);\r
// Start Task\r
if(pid == 0)\r
- execve(gsTmpBuffer, Args, gasEnvironment);\r
+ execve(sTmpBuffer, Args, gasEnvironment);\r
if(pid <= 0) {\r
- Print("Unablt to create process: `");Print(gsTmpBuffer);Print("'\n"); // Error Message\r
+ Print("Unablt to create process: `");Print(sTmpBuffer);Print("'\n"); // Error Message\r
}\r
else {\r
int status;\r
// Verify Arg Count\r
if(argc < 2)\r
{\r
- Print("Please specify a colour\n");\r
goto usage;\r
}\r
\r
\r
// Function Usage (Requested via a Goto (I know it's ugly))\r
usage:\r
+ Print("Usage: colour <foreground> [<background>]\n");\r
Print("Valid Colours are ");\r
for(fg=0;fg<8;fg++)\r
{\r
return;\r
}\r
\r
+/**\r
+ * \fn void Command_Clear(int argc, char **argv)\r
+ * \brief Clear the screen\r
+ */\r
void Command_Clear(int argc, char **argv)\r
{\r
write(_stdout, 4, "\x1B[2J"); //Clear Screen\r