diff options
Diffstat (limited to '03_exercise/srv')
-rwxr-xr-x | 03_exercise/srv/server | bin | 60872 -> 0 bytes | |||
-rw-r--r-- | 03_exercise/srv/server.c | 6 | ||||
-rw-r--r-- | 03_exercise/srv/shell.c | 19 |
3 files changed, 11 insertions, 14 deletions
diff --git a/03_exercise/srv/server b/03_exercise/srv/server Binary files differdeleted file mode 100755 index 69edeea..0000000 --- a/03_exercise/srv/server +++ /dev/null diff --git a/03_exercise/srv/server.c b/03_exercise/srv/server.c index 5c23196..8527b83 100644 --- a/03_exercise/srv/server.c +++ b/03_exercise/srv/server.c @@ -50,7 +50,7 @@ int main() { int status = shell(cfd); /* - while ((bytes = read(cfd, in_buf, BUF_SIZE)) != 0) { + while ((bytes = read(sock, in_buf, BUF_SIZE)) != 0) { if (bytes < 0) die("Couldn't receive message"); @@ -68,14 +68,14 @@ int main() { memcpy(out_buf + sizeof("got: ") - 1, in_buf, BUF_SIZE - sizeof("got: ") + 1); } - if (write(cfd, out_buf, sizeof(out_buf)) < 0) + if (write(sock, out_buf, sizeof(out_buf)) < 0) die("Couldn't send message"); memset(in_buf, 0, BUF_SIZE); memset(out_buf, 0, BUF_SIZE); }*/ - printf("srv: closing down\n"); + //printf("srv: closing down\n"); close(cfd); close(sfd); 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); |