summaryrefslogtreecommitdiffstats
path: root/03_exercise/srv/shell.c
diff options
context:
space:
mode:
Diffstat (limited to '03_exercise/srv/shell.c')
-rw-r--r--03_exercise/srv/shell.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/03_exercise/srv/shell.c b/03_exercise/srv/shell.c
index 792a26c..449905b 100644
--- a/03_exercise/srv/shell.c
+++ b/03_exercise/srv/shell.c
@@ -58,8 +58,6 @@ void receive_file(int sock, char *path, int size) {
}
}
-const char *const get_current_dir_name();
-
void signal_handler(int signal) {
if (signal == SIGINT) {
for (size_t i = 0; i < arrayLen(processes); ++i) {
@@ -75,14 +73,8 @@ int shell(int in_fd) {
setvbuf(stderr, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
- dup2(in_fd, 1);
- dup2(in_fd, 2);
-
- // I don't think the shell should exit on SIG_TERM
- if (signal(SIGINT, SIG_IGN) == SIG_ERR) {
- perror("Couldn't ignore sigterm");
- exit(errno);
- }
+ dup2(in_fd, STDOUT_FILENO);
+ dup2(in_fd, STDERR_FILENO);
printf("Welcome! Available built-ins are:\n"
"cd: `cd <path>` - if no path is given, return to the current dir\n"
@@ -94,12 +86,14 @@ int shell(int in_fd) {
);
char const *const original_wd = get_current_dir_name();
+ //char const *prompt = relative_path(original_wd, original_wd);
bool done = false;
while (!done) {
char line[BUF_SIZE];
__ssize_t length;
+ fflush(stdout);
if ((length = read(in_fd, line, BUF_SIZE)) < 0) {
fprintf(stderr, "Failed to read from STDIN");
fflush(stderr);
@@ -112,6 +106,10 @@ int shell(int in_fd) {
}
line[length - 1] = '\0'; // cut the line feed
+ if (strlen(line) == 0) {
+ continue;
+ }
+
processes = NULL;
parse_line(line, &processes);
@@ -154,7 +152,6 @@ int shell(int in_fd) {
/*if (ret)
printf("[%i] ", ret);*/
}
- signal(SIGINT, SIG_IGN);
}
free_processes(&processes);