diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-11-18 14:20:48 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-11-18 14:20:48 +0100 |
commit | 64095e733a03b5e300f952ca39ab0faf5d4908ed (patch) | |
tree | 312ecb208bf84939067977b734b3eecd903d28fb /kms/client | |
parent | 9e6f6f67d062db7b70e32061ad68aba687dd1b08 (diff) |
close socketpair before sigint
Diffstat (limited to 'kms/client')
-rw-r--r-- | kms/client/kms_client.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/kms/client/kms_client.c b/kms/client/kms_client.c index b2b153f..2fef8e7 100644 --- a/kms/client/kms_client.c +++ b/kms/client/kms_client.c @@ -15,7 +15,7 @@ #define GSR_SOCKET_PAIR_LOCAL 0 #define GSR_SOCKET_PAIR_REMOTE 1 -static void cleanup_initial_socket(gsr_kms_client *self, bool kill_server); +static void cleanup_socket(gsr_kms_client *self, bool kill_server); static int gsr_kms_client_replace_connection(gsr_kms_client *self); static bool generate_random_characters(char *buffer, int buffer_size, const char *alphabet, size_t alphabet_size) { @@ -301,7 +301,7 @@ int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) { if(gsr_kms_client_replace_connection(self) != 0) goto err; - cleanup_initial_socket(self, false); + cleanup_socket(self, false); fprintf(stderr, "gsr info: using socketpair\n"); return 0; @@ -311,7 +311,7 @@ int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) { return result; } -void cleanup_initial_socket(gsr_kms_client *self, bool kill_server) { +void cleanup_socket(gsr_kms_client *self, bool kill_server) { if(self->initial_client_fd != -1) { close(self->initial_client_fd); self->initial_client_fd = -1; @@ -322,8 +322,19 @@ void cleanup_initial_socket(gsr_kms_client *self, bool kill_server) { self->initial_socket_fd = -1; } + if(kill_server) { + for(int i = 0; i < 2; ++i) { + if(self->socket_pair[i] > 0) { + close(self->socket_pair[i]); + self->socket_pair[i] = -1; + } + } + } + if(kill_server && self->kms_server_pid != -1) { - kill(self->kms_server_pid, SIGKILL); + kill(self->kms_server_pid, SIGINT); + int status; + waitpid(self->kms_server_pid, &status, 0); self->kms_server_pid = -1; } @@ -334,14 +345,7 @@ void cleanup_initial_socket(gsr_kms_client *self, bool kill_server) { } void gsr_kms_client_deinit(gsr_kms_client *self) { - cleanup_initial_socket(self, true); - - for(int i = 0; i < 2; ++i) { - if(self->socket_pair[i] > 0) { - close(self->socket_pair[i]); - self->socket_pair[i] = -1; - } - } + cleanup_socket(self, true); } int gsr_kms_client_replace_connection(gsr_kms_client *self) { |