Fix SIGPIPE causing unexpected exit of example applications

examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/etsi_iot_01.c:
examples/tiny.c:

Make the applications ignore SIGPIPE.

examples/coap-rd.c:

Support clean exit for SIGTERM / SIGQUIT for valgrind testing.
This commit is contained in:
Jon Shallow committed 2019-08-29 12:58:15 +01:00
1 parent 16b77c3e6c
commit 003b64ab3f
5 files changed
+35 -1

No files matched your search

+3
View File
@@ -1569,6 +1569,9 @@ main(int argc, char **argv) {
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
#endif
while (!quit && !(ready && !doing_getting_block && coap_can_exit(ctx)) ) {
+23 -1
View File
@@ -85,9 +85,14 @@ rd_delete(rd_t *rd) {
}
}
/* temporary storage for dynamic resource representations */
static int quit = 0;
/* SIGINT handler: set quit to 1 for graceful termination */
static void
handle_sigint(int signum UNUSED_PARAM) {
quit = 1;
}
static void
hnd_get_resource(coap_context_t *ctx UNUSED_PARAM,
struct coap_resource_t *resource,
@@ -620,6 +625,9 @@ main(int argc, char **argv) {
char *group = NULL;
int opt;
coap_log_t log_level = LOG_WARNING;
#ifndef _WIN32
struct sigaction sa;
#endif
while ((opt = getopt(argc, argv, "A:g:p:v:")) != -1) {
switch (opt) {
@@ -656,6 +664,20 @@ main(int argc, char **argv) {
init_resources(ctx);
#ifdef _WIN32
signal(SIGINT, handle_sigint);
#else
memset (&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = handle_sigint;
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
#endif
while ( !quit ) {
result = coap_run_once( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
if ( result >= 0 ) {
+3
View File
@@ -983,6 +983,9 @@ main(int argc, char **argv) {
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
#endif
wait_ms = COAP_RESOURCE_CHECK_TIME * 1000;
+3
View File
@@ -662,6 +662,9 @@ main(int argc, char **argv) {
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
while ( !quit ) {
result = coap_run_once( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
+3
View File
@@ -148,6 +148,9 @@ main(int argc, char **argv) {
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
while ( !quit ) {