Skip to content

Commit 8a9e048

Browse files
mrdeep1boaks
authored andcommitted
sigint: Handle SIGINT cleanups cleanly
Signed-off-by: Jon Shallow <[email protected]>
1 parent 1f1bc2a commit 8a9e048

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tests/dtls-client.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ static const dtls_cipher_t* ciphers = NULL;
7070
static unsigned int force_extended_master_secret = 0;
7171
static unsigned int force_renegotiation_info = 0;
7272

73+
static volatile int quit = 0;
74+
7375

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

299301
static void
300302
dtls_handle_signal(int sig) {
301-
dtls_free_context(dtls_context);
302-
dtls_free_context(orig_dtls_context);
303-
signal(sig, SIG_DFL);
304-
kill(getpid(), sig);
303+
(void)sig;
304+
quit = 1;
305305
}
306306

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

597597
dtls_connect(dtls_context, &dst);
598598

599-
while (1) {
599+
while (!quit) {
600600
FD_ZERO(&rfds);
601601
FD_ZERO(&wfds);
602602

tests/dtls-server.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static const dtls_cipher_t* ciphers = NULL;
5050
static unsigned int force_extended_master_secret = 0;
5151
static unsigned int force_renegotiation_info = 0;
5252

53+
static volatile int quit = 0;
54+
5355
#ifdef DTLS_ECC
5456
static const unsigned char ecdsa_priv_key[] = {
5557
0xD9, 0xE2, 0x70, 0x7A, 0x72, 0xDA, 0x6A, 0x05,
@@ -252,9 +254,8 @@ dtls_handle_read(struct dtls_context_t *ctx) {
252254

253255
static void dtls_handle_signal(int sig)
254256
{
255-
dtls_free_context(the_context);
256-
signal(sig, SIG_DFL);
257-
kill(getpid(), sig);
257+
(void)sig;
258+
quit = 1;
258259
}
259260

260261
static int
@@ -455,7 +456,7 @@ main(int argc, char **argv) {
455456

456457
dtls_set_handler(the_context, &cb);
457458

458-
while (1) {
459+
while (!quit) {
459460
FD_ZERO(&rfds);
460461
FD_ZERO(&wfds);
461462

0 commit comments

Comments
 (0)