Skip to content

Commit

Permalink
sigint: Handle SIGINT cleanups cleanly
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
  • Loading branch information
mrdeep1 committed Jan 17, 2025
1 parent 1f1bc2a commit 78f6a23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions tests/dtls-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static const dtls_cipher_t* ciphers = NULL;
static unsigned int force_extended_master_secret = 0;
static unsigned int force_renegotiation_info = 0;

static volatile int quit = 0;


#ifdef DTLS_ECC
static const unsigned char ecdsa_priv_key[] = {
Expand Down Expand Up @@ -298,10 +300,8 @@ dtls_handle_read(struct dtls_context_t *ctx) {

static void
dtls_handle_signal(int sig) {
dtls_free_context(dtls_context);
dtls_free_context(orig_dtls_context);
signal(sig, SIG_DFL);
kill(getpid(), sig);
(void)sig;
quit = 1;
}

/* stolen from libcoap: */
Expand Down Expand Up @@ -596,7 +596,7 @@ main(int argc, char **argv) {

dtls_connect(dtls_context, &dst);

while (1) {
while (!quit) {
FD_ZERO(&rfds);
FD_ZERO(&wfds);

Expand Down
9 changes: 5 additions & 4 deletions tests/dtls-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ static const dtls_cipher_t* ciphers = NULL;
static unsigned int force_extended_master_secret = 0;
static unsigned int force_renegotiation_info = 0;

static volatile int quit = 0;

#ifdef DTLS_ECC
static const unsigned char ecdsa_priv_key[] = {
0xD9, 0xE2, 0x70, 0x7A, 0x72, 0xDA, 0x6A, 0x05,
Expand Down Expand Up @@ -252,9 +254,8 @@ dtls_handle_read(struct dtls_context_t *ctx) {

static void dtls_handle_signal(int sig)
{
dtls_free_context(the_context);
signal(sig, SIG_DFL);
kill(getpid(), sig);
(void)sig;
quit = 1;
}

static int
Expand Down Expand Up @@ -455,7 +456,7 @@ main(int argc, char **argv) {

dtls_set_handler(the_context, &cb);

while (1) {
while (!quit) {
FD_ZERO(&rfds);
FD_ZERO(&wfds);

Expand Down

0 comments on commit 78f6a23

Please sign in to comment.