| 1 |
#ifndef HEADER_CURL_SIGPIPE_H |
| 2 |
#define HEADER_CURL_SIGPIPE_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#include "curl_setup.h" |
| 27 |
|
| 28 |
#if defined(HAVE_SIGACTION) && \ |
| 29 |
(defined(USE_OPENSSL) || defined(USE_MBEDTLS) || defined(USE_WOLFSSL)) |
| 30 |
#include <signal.h> |
| 31 |
|
| 32 |
struct sigpipe_ignore { |
| 33 |
struct sigaction old_pipe_act; |
| 34 |
BIT(no_signal); |
| 35 |
}; |
| 36 |
|
| 37 |
#define SIGPIPE_VARIABLE(x) struct sigpipe_ignore x |
| 38 |
#define SIGPIPE_MEMBER(x) struct sigpipe_ignore x |
| 39 |
|
| 40 |
static void sigpipe_init(struct sigpipe_ignore *ig) |
| 41 |
{ |
| 42 |
memset(ig, 0, sizeof(*ig)); |
| 43 |
ig->no_signal = TRUE; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
static void sigpipe_ignore(struct Curl_easy *data, |
| 52 |
struct sigpipe_ignore *ig) |
| 53 |
{ |
| 54 |
|
| 55 |
|
| 56 |
ig->no_signal = data->set.no_signal; |
| 57 |
if(!data->set.no_signal) { |
| 58 |
struct sigaction action; |
| 59 |
|
| 60 |
sigaction(SIGPIPE, NULL, &ig->old_pipe_act); |
| 61 |
action = ig->old_pipe_act; |
| 62 |
|
| 63 |
action.sa_handler = SIG_IGN; |
| 64 |
sigaction(SIGPIPE, &action, NULL); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
static void sigpipe_restore(struct sigpipe_ignore *ig) |
| 74 |
{ |
| 75 |
if(!ig->no_signal) |
| 76 |
|
| 77 |
sigaction(SIGPIPE, &ig->old_pipe_act, NULL); |
| 78 |
} |
| 79 |
|
| 80 |
static void sigpipe_apply(struct Curl_easy *data, |
| 81 |
struct sigpipe_ignore *ig) |
| 82 |
{ |
| 83 |
if(data->set.no_signal != ig->no_signal) { |
| 84 |
sigpipe_restore(ig); |
| 85 |
sigpipe_ignore(data, ig); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
#else |
| 90 |
|
| 91 |
#define sigpipe_ignore(x,y) Curl_nop_stmt |
| 92 |
#define sigpipe_apply(x,y) Curl_nop_stmt |
| 93 |
#define sigpipe_init(x) Curl_nop_stmt |
| 94 |
#define sigpipe_restore(x) Curl_nop_stmt |
| 95 |
#define SIGPIPE_VARIABLE(x) |
| 96 |
#define SIGPIPE_MEMBER(x) bool x |
| 97 |
#endif |
| 98 |
|
| 99 |
#endif |