summaryrefslogtreecommitdiffstats
path: root/03_exercise/srv
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-06-06 17:19:55 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-06-06 17:19:55 +0200
commit2821f125c91c192cdd28997e78f366f2db2d39c4 (patch)
tree7f6f4b6bbfdb3a2b65f87ed03b7b55d26a43fa1a /03_exercise/srv
parent178cbf7c04639cd24b7a1eb70d532fb64b9f908d (diff)
downloadbetriebssysteme-2821f125c91c192cdd28997e78f366f2db2d39c4.tar.gz
betriebssysteme-2821f125c91c192cdd28997e78f366f2db2d39c4.zip
stuff works
Diffstat (limited to '03_exercise/srv')
-rwxr-xr-x03_exercise/srv/serverbin60872 -> 0 bytes
-rw-r--r--03_exercise/srv/server.c6
-rw-r--r--03_exercise/srv/shell.c19
3 files changed, 11 insertions, 14 deletions
diff --git a/03_exercise/srv/server b/03_exercise/srv/server
deleted file mode 100755
index 69edeea..0000000
--- a/03_exercise/srv/server
+++ /dev/null
Binary files differ
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);