From 8bd2940f1ae6eebca22229db6fbb34be876ccef7 Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Sat, 29 Oct 2022 20:29:28 -0500 Subject: [PATCH 1/2] Fixed crashing on no input --- src/Integrated.c | 12 ++++++++---- src/Pish.c | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Integrated.c b/src/Integrated.c index 0fa1ff0..38dd88c 100755 --- a/src/Integrated.c +++ b/src/Integrated.c @@ -180,6 +180,7 @@ int ExecPipe(CommandStruct* commandParent, CommandStruct* commandChild, int* pip int pipeLocation = 0; int startArgc = 0; int endArgc = commandParent->argc; + pipe(pipefd); for (int i = 0; i < pipeAmount; i++) { @@ -191,24 +192,27 @@ int ExecPipe(CommandStruct* commandParent, CommandStruct* commandChild, int* pip // if (pipeLocation < 0) // endArgc = commandParent->argc; CopyCommandStruct(commandParent, commandChild, startArgc, endArgc); - pipe(pipefd); forkPID = fork(); if (forkPID == 0) return forkPID; // if (forkPID != 0) - wait(&forkPID); + close(pipefd[0]); close(pipefd[1]); - while (read(pipefd[0], buffer, sizeof(buffer)) != 0) - printf("%s", buffer); + wait(&forkPID); startArgc = pipeLocation + 1; ResetCommandStruct(commandChild); // Clean command + pipe(pipefd); } endArgc = commandParent->argc; forkPID = fork(); CopyCommandStruct(commandParent, commandChild, startArgc, endArgc); if (forkPID == 0) return forkPID; + close(pipefd[1]); wait(&forkPID); + while (read(pipefd[0], buffer, sizeof(buffer)) != 0) + printf("%s", buffer); + close(pipefd[0]); ResetCommandStruct(commandChild); // Clean command return 1; } diff --git a/src/Pish.c b/src/Pish.c index fad10b0..26bcf70 100644 --- a/src/Pish.c +++ b/src/Pish.c @@ -34,6 +34,8 @@ void Pish(void) ResetCommandStruct(commandParent); // Clean command strcpy(inputString, ""); // Clean inputString GetInput(inputString); + if (strcmp(inputString, "") == 0) + continue; SplitInput(inputString, commandParent); if (IntegratedCheck(commandParent)) continue; From d8e729fdd6cc1b20cb2ab6b4d07dcaad0a87328d Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Sat, 29 Oct 2022 21:21:13 -0500 Subject: [PATCH 2/2] Added signal handling and fixed permissions with pishrc --- src/Pish.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Pish.c b/src/Pish.c index 26bcf70..34fce97 100644 --- a/src/Pish.c +++ b/src/Pish.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -27,6 +28,9 @@ void Pish(void) CommandStruct* commandChild = &commandChildObject; char inputString[1000]; // Max 1000 characters int forkPID; + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); ReadPishrc(commandParent, commandChild, inputString); while (1) { @@ -60,7 +64,7 @@ void ReadPishrc(CommandStruct *commandParent, CommandStruct *commandChild, char int *argc = &(commandParent->argc); char* pishLocation = GetHomeDir(); strcat(pishLocation, "/.pishrc"); - int fd = open(pishLocation, O_RDONLY | O_CREAT); + int fd = open(pishLocation, O_RDONLY | O_CREAT, 0644); assert(fd > -1); while (read(fd, buffer, 1) > 0) {