Skip to content

Commit

Permalink
Merge pull request #89 from doronz88/bugfix/pthread_close
Browse files Browse the repository at this point in the history
server: spawn: bugfix: remove pthread_kill
  • Loading branch information
doronz88 authored Feb 21, 2022
2 parents 0e5b746 + 991b779 commit 424d51f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/rpcclient/tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def test_spawn_sanity(client, argv, expected_stdout, errorcode):
assert expected_stdout == stdout.read().strip()


@pytest.mark.local_only
def test_spawn_bad_value_stress(client):
for i in range(100):
for i in range(1000):
stdout = StringIO()
assert 256 == client.spawn(['/bin/ls', 'INVALID_PATH'], stdout=stdout, stdin='').error

Expand Down
14 changes: 8 additions & 6 deletions src/rpcserver/rpcserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,13 @@ void wait_process_exit_thread(wait_process_exit_thread_t *params)
TRACE("sent exit code to client fd: %d", params->sockfd);

error:
close(params->pipe[0]);
close(params->pipe[1]);
free(params);
return;
}

bool handle_exec(int sockfd)
{
pthread_t thread = 0;
wait_process_exit_thread_t *thread_params = NULL;
pid_t pid = INVALID_PID;
int master = -1;
int result = false;
Expand Down Expand Up @@ -287,7 +285,7 @@ bool handle_exec(int sockfd)

// create a new thread to wait for the exit of the new process, but lock it until after
// all stdin/stdout/stderr has been forwarded
wait_process_exit_thread_t *thread_params = (wait_process_exit_thread_t *)malloc(sizeof(wait_process_exit_thread_t));
thread_params = (wait_process_exit_thread_t *)malloc(sizeof(wait_process_exit_thread_t));
thread_params->sockfd = sockfd;
thread_params->pid = pid;
CHECK(0 == pipe(thread_params->pipe));
Expand Down Expand Up @@ -354,15 +352,19 @@ bool handle_exec(int sockfd)

TRACE("wait for thread to finish");
CHECK(0 != pthread_join(thread, NULL));

thread = NULL;

TRACE("thread exit");

result = true;

error:
if (thread)
if (thread_params)
{
pthread_kill(thread, SIGKILL);
close(thread_params->pipe[0]);
close(thread_params->pipe[1]);
free(thread_params);
}

if (INVALID_PID == pid)
Expand Down

0 comments on commit 424d51f

Please sign in to comment.