From 6333c6510ae56b65a2f36bde55c8618a08260e10 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Sun, 7 Jun 2020 15:03:56 +0200 Subject: more fixes --- 03_exercise/cli/client | Bin 28360 -> 28464 bytes 03_exercise/cli/client.c | 9 ++++++--- 03_exercise/srv/shell.c | 12 ++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/03_exercise/cli/client b/03_exercise/cli/client index 0935c2b..c593e95 100755 Binary files a/03_exercise/cli/client and b/03_exercise/cli/client differ diff --git a/03_exercise/cli/client.c b/03_exercise/cli/client.c index e5f2f84..ea4eda9 100644 --- a/03_exercise/cli/client.c +++ b/03_exercise/cli/client.c @@ -16,6 +16,7 @@ #define BUF_SIZE 2048 int sock; +pid_t pid; /* Signal Handler for SIGINT */ void sigintHandler(int sig_num) { @@ -26,6 +27,7 @@ void sigintHandler(int sig_num) { } printf("Terminating client\n"); fflush(stdout); + kill(pid, SIGKILL); exit(-1); } @@ -147,10 +149,10 @@ int main() { signal(SIGINT, &sigintHandler); - pid_t pid = fork(); + pid = fork(); int done = 0; - if (pid == 0) { + if (pid != 0) { read_stdin(&done); } else { read_server_sock(&done); @@ -174,6 +176,7 @@ void read_server_sock(int *done) { } } } + kill(pid, SIGKILL); } @@ -186,7 +189,6 @@ void read_stdin(int *done) { if ((length = read(STDIN_FILENO, stdinp_buffer, BUF_SIZE)) > 0) { switch (parse(sock, stdinp_buffer, length)) { case CONTINUE: - printf("$> "); continue; case BREAK: *done = 1; @@ -196,4 +198,5 @@ void read_stdin(int *done) { } } } + kill(pid, SIGKILL); } diff --git a/03_exercise/srv/shell.c b/03_exercise/srv/shell.c index aea1a68..5d7d33d 100644 --- a/03_exercise/srv/shell.c +++ b/03_exercise/srv/shell.c @@ -12,6 +12,8 @@ #include "prompt_utils.h" #include "builtins.h" +char *get_current_dir_name(void); + #define BUF_SIZE 2048 process *processes; @@ -51,7 +53,9 @@ void receive_file(int sock, char *path, int size) { received += nread; } - write_all(file_fd, buffer, strlen(buffer) + 1); + if (write_all(file_fd, buffer, strlen(buffer) + 1) == strlen(buffer) + 1) { + printf("successfully wrote to remote file \"%s/%s\"\n", get_current_dir_name(), path); + } close(file_fd); } @@ -120,7 +124,7 @@ int shell(int in_fd) { "And with `|` you can pipe the output from one process to the input of another\n" ); - char const *const original_wd = ".";//get_current_dir_name(); + char const *const original_wd = get_current_dir_name(); //char const *prompt = relative_path(original_wd, original_wd); bool done = false; @@ -172,7 +176,7 @@ int shell(int in_fd) { if (ret) printf("[%i] ", ret); else - printf("%s\n", "."/*get_current_dir_name()*/); + printf("%s\n", get_current_dir_name()); } else if (strcmp(processes[0].argv[0], "exit") == 0) { done = true; @@ -197,7 +201,7 @@ int shell(int in_fd) { printf("Disconnecting..."); - //free((void *) original_wd); + free((void *) original_wd); return 0; } -- cgit v1.2.3-54-g00ecf