Skip to content
Snippets Groups Projects
Commit 6bb57da0 authored by Joey Le's avatar Joey Le
Browse files

MINOR BUG FIXES IN MAKE

parent a7b4c2ec
No related branches found
No related tags found
No related merge requests found
...@@ -249,6 +249,7 @@ int process_cli_requests(int svr_socket) { ...@@ -249,6 +249,7 @@ int process_cli_requests(int svr_socket) {
} }
/* /*
* exec_client_requests(cli_socket) * exec_client_requests(cli_socket)
* cli_socket: The server-side socket that is connected to the client * cli_socket: The server-side socket that is connected to the client
...@@ -291,22 +292,20 @@ int process_cli_requests(int svr_socket) { ...@@ -291,22 +292,20 @@ int process_cli_requests(int svr_socket) {
* or receive errors. * or receive errors.
*/ */
void *exec_client_requests(void *socket_handle) { void *exec_client_requests(void *socket_handle) {
int cli_socket = *((int *)socket_handle); int cli_socket = *((int *)socket_handle);
char cmd_buff[RDSH_COMM_BUFF_SZ]; char cmd_buff[RDSH_COMM_BUFF_SZ];
ssize_t recv_bytes; ssize_t recv_bytes;
int rc = OK;
printf("SERVER: New client connected. Socket: %d\n", cli_socket); printf("SERVER: Handling client request. Socket: %d\n", cli_socket);
// Receive the command from the client
recv_bytes = recv(cli_socket, cmd_buff, sizeof(cmd_buff), 0); recv_bytes = recv(cli_socket, cmd_buff, sizeof(cmd_buff), 0);
if (recv_bytes <= 0) { if (recv_bytes <= 0) {
perror("SERVER: recv failed"); perror("SERVER: recv failed");
close(cli_socket); close(cli_socket);
pthread_exit(NULL); pthread_exit(NULL);
} }
cmd_buff[recv_bytes] = '\0'; cmd_buff[recv_bytes] = '\0';
printf("SERVER: Received command: %s\n", cmd_buff); printf("SERVER: Received command: %s\n", cmd_buff);
...@@ -320,7 +319,7 @@ void *exec_client_requests(void *socket_handle) { ...@@ -320,7 +319,7 @@ void *exec_client_requests(void *socket_handle) {
pthread_exit(NULL); pthread_exit(NULL);
} }
rc = rsh_execute_pipeline(cli_socket, &cmd_list); rsh_execute_pipeline(cli_socket, &cmd_list);
for (int i = 0; i < cmd_list.num; i++) { for (int i = 0; i < cmd_list.num; i++) {
free(cmd_list.commands[i]._cmd_buffer); free(cmd_list.commands[i]._cmd_buffer);
...@@ -363,8 +362,8 @@ void *exec_client_requests(void *socket_handle) { ...@@ -363,8 +362,8 @@ void *exec_client_requests(void *socket_handle) {
pthread_exit(NULL); pthread_exit(NULL);
} else if (pid == 0) { } else if (pid == 0) {
// Child process: execute the command // Child process: execute the command
dup2(cli_socket, STDOUT_FILENO); // Redirect stdout to client socket dup2(cli_socket, STDOUT_FILENO);
dup2(cli_socket, STDERR_FILENO); // Redirect stderr to client socket dup2(cli_socket, STDERR_FILENO);
execvp(cmd.argv[0], cmd.argv); execvp(cmd.argv[0], cmd.argv);
perror("SERVER: execvp failed"); perror("SERVER: execvp failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -390,10 +389,6 @@ void *exec_client_requests(void *socket_handle) { ...@@ -390,10 +389,6 @@ void *exec_client_requests(void *socket_handle) {
} }
/* /*
* send_message_eof(cli_socket) * send_message_eof(cli_socket)
* cli_socket: The server-side socket that is connected to the client * cli_socket: The server-side socket that is connected to the client
......
...@@ -65,7 +65,7 @@ int stop_server(int svr_socket); ...@@ -65,7 +65,7 @@ int stop_server(int svr_socket);
int send_message_eof(int cli_socket); int send_message_eof(int cli_socket);
int send_message_string(int cli_socket, char *buff); int send_message_string(int cli_socket, char *buff);
int process_cli_requests(int svr_socket); int process_cli_requests(int svr_socket);
int exec_client_requests(int cli_socket); int *exec_client_requests(int cli_socket);
int rsh_execute_pipeline(int socket_fd, command_list_t *clist); int rsh_execute_pipeline(int socket_fd, command_list_t *clist);
Built_In_Cmds rsh_match_command(const char *input); Built_In_Cmds rsh_match_command(const char *input);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment