Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs283
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joey Le
Cs283
Commits
6bb57da0
Commit
6bb57da0
authored
3 months ago
by
Joey Le
Browse files
Options
Downloads
Patches
Plain Diff
MINOR BUG FIXES IN MAKE
parent
a7b4c2ec
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Assignment-06/starter/rsh_server.c
+6
-11
6 additions, 11 deletions
Assignment-06/starter/rsh_server.c
Assignment-06/starter/rshlib.h
+1
-1
1 addition, 1 deletion
Assignment-06/starter/rshlib.h
with
7 additions
and
12 deletions
Assignment-06/starter/rsh_server.c
+
6
−
11
View file @
6bb57da0
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Assignment-06/starter/rshlib.h
+
1
−
1
View file @
6bb57da0
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment