sigpipe.h
Go to the documentation of this file.
00001 #ifndef HEADER_CURL_SIGPIPE_H
00002 #define HEADER_CURL_SIGPIPE_H
00003 /***************************************************************************
00004  *                                  _   _ ____  _
00005  *  Project                     ___| | | |  _ \| |
00006  *                             / __| | | | |_) | |
00007  *                            | (__| |_| |  _ <| |___
00008  *                             \___|\___/|_| \_\_____|
00009  *
00010  * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
00011  *
00012  * This software is licensed as described in the file COPYING, which
00013  * you should have received as part of this distribution. The terms
00014  * are also available at https://curl.haxx.se/docs/copyright.html.
00015  *
00016  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00017  * copies of the Software, and permit persons to whom the Software is
00018  * furnished to do so, under the terms of the COPYING file.
00019  *
00020  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00021  * KIND, either express or implied.
00022  *
00023  ***************************************************************************/
00024 #include "curl_setup.h"
00025 
00026 #if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGACTION) && defined(USE_OPENSSL)
00027 #include <signal.h>
00028 
00029 struct sigpipe_ignore {
00030   struct sigaction old_pipe_act;
00031   bool no_signal;
00032 };
00033 
00034 #define SIGPIPE_VARIABLE(x) struct sigpipe_ignore x
00035 
00036 /*
00037  * sigpipe_ignore() makes sure we ignore SIGPIPE while running libcurl
00038  * internals, and then sigpipe_restore() will restore the situation when we
00039  * return from libcurl again.
00040  */
00041 static void sigpipe_ignore(struct Curl_easy *data,
00042                            struct sigpipe_ignore *ig)
00043 {
00044   /* get a local copy of no_signal because the Curl_easy might not be
00045      around when we restore */
00046   ig->no_signal = data->set.no_signal;
00047   if(!data->set.no_signal) {
00048     struct sigaction action;
00049     /* first, extract the existing situation */
00050     memset(&ig->old_pipe_act, 0, sizeof(struct sigaction));
00051     sigaction(SIGPIPE, NULL, &ig->old_pipe_act);
00052     action = ig->old_pipe_act;
00053     /* ignore this signal */
00054     action.sa_handler = SIG_IGN;
00055     sigaction(SIGPIPE, &action, NULL);
00056   }
00057 }
00058 
00059 /*
00060  * sigpipe_restore() puts back the outside world's opinion of signal handler
00061  * and SIGPIPE handling. It MUST only be called after a corresponding
00062  * sigpipe_ignore() was used.
00063  */
00064 static void sigpipe_restore(struct sigpipe_ignore *ig)
00065 {
00066   if(!ig->no_signal)
00067     /* restore the outside state */
00068     sigaction(SIGPIPE, &ig->old_pipe_act, NULL);
00069 }
00070 
00071 #else
00072 /* for systems without sigaction */
00073 #define sigpipe_ignore(x,y) Curl_nop_stmt
00074 #define sigpipe_restore(x)  Curl_nop_stmt
00075 #define SIGPIPE_VARIABLE(x)
00076 #endif
00077 
00078 #endif /* HEADER_CURL_SIGPIPE_H */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06