summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-06-07 15:03:56 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-06-07 15:03:56 +0200
commit6333c6510ae56b65a2f36bde55c8618a08260e10 (patch)
tree0faa1af3f81d82366e488ddabb22b24201cf1235
parent896cc4c94ee319b64be0a4c543e936d99d172515 (diff)
downloadbetriebssysteme-6333c6510ae56b65a2f36bde55c8618a08260e10.tar.gz
betriebssysteme-6333c6510ae56b65a2f36bde55c8618a08260e10.zip
more fixes
-rwxr-xr-x03_exercise/cli/clientbin28360 -> 28464 bytes
-rw-r--r--03_exercise/cli/client.c9
-rw-r--r--03_exercise/srv/shell.c12
3 files changed, 14 insertions, 7 deletions
diff --git a/03_exercise/cli/client b/03_exercise/cli/client
index 0935c2b..c593e95 100755
--- a/03_exercise/cli/client
+++ b/03_exercise/cli/client
Binary files 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;
}