Changeset 379


Ignore:
Timestamp:
Nov 28, 2011, 9:56:30 PM (13 years ago)
Author:
katerina
Message:

Fix for ticket #277 (sigpipe).

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/sh_unix.h

    r373 r379  
    169169int sh_unix_run_command (const char * str);
    170170
     171/* Ignore SIGPIPE
     172 */
     173void sh_unix_ign_sigpipe();
     174
    171175/* mlock utilities
    172176 */
  • trunk/src/samhain.c

    r373 r379  
    13761376  /* --------  INIT  --------   
    13771377   */
     1378  sh_unix_ign_sigpipe();
    13781379
    13791380  /* Restrict error logging to stderr.
  • trunk/src/sh_err_console.c

    r362 r379  
    290290  /* static int logkey_seen = 0; */
    291291  int    error;
    292   struct sigaction sa_new, sa_old;
    293292  static int blockMe = 0;
    294293  int    val_return;
     
    311310#endif
    312311
    313   sa_new.sa_handler = SIG_IGN;
    314   (void) sigemptyset(&sa_new.sa_mask);
    315   sa_new.sa_flags   = 0;
    316 
    317   /* Ignore SIGPIPE in case the console is actually a pipe.
    318    */
    319   (void) retry_sigaction(FIL__, __LINE__, SIGPIPE, &sa_new, &sa_old);
    320  
    321312  if (sh.flag.isdaemon == S_FALSE || OnlyStderr == S_TRUE)
    322313    {
     
    331322       * fprintf (stderr, "%s\n", errmsg);
    332323       */
    333       (void) retry_sigaction(FIL__, __LINE__, SIGPIPE, &sa_old, NULL);
    334324      blockMe = 0;
    335325      SL_RETURN(0, _("sh_log_console"));
     
    392382    retval = 0;
    393383
    394   (void) retry_sigaction(FIL__, __LINE__, SIGPIPE, &sa_old, NULL);
    395384  blockMe = 0;
    396385  SL_RETURN(retval, _("sh_log_console"));
  • trunk/src/sh_forward.c

    r363 r379  
    50555055  unsigned long tchkold;
    50565056
    5057   struct  sigaction  new_act;
    5058   struct  sigaction  old_act;
    5059 
    50605057  int setsize_fd;
    50615058
     
    50675064 
    50685065  SL_ENTER(_("sh_receive"));
    5069 
    5070   /* ignore SIGPIPE (instead get EPIPE if connection is closed)
    5071    *      --- we have called sh_unix_init() already ---
    5072    */
    5073   new_act.sa_handler = SIG_IGN;
    5074   sigemptyset( &new_act.sa_mask );         /* set an empty mask       */
    5075   new_act.sa_flags = 0;                    /* init sa_flags           */
    5076   retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act);
    50775066
    50785067  if ( sh_forward_printerr_final(0) < 0)
  • trunk/src/sh_log_check.c

    r362 r379  
    876876  struct task_entry * entry;
    877877
    878   struct  sigaction   new_act;
    879   struct  sigaction   old_act;
    880 
    881878  volatile int        status;
    882879  char * tmp;
     
    886883  if (logfile->fp)
    887884    {
    888       /* ignore SIGPIPE (instead get EPIPE if connection is closed)
    889        */
    890       memset(&new_act, 0, sizeof(struct  sigaction));
    891       new_act.sa_handler = SIG_IGN;
    892       (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act);
    893 
    894885      /* Result cannot be larger than 8192, thus cast is ok
    895886       */
    896887      status = (int) sh_string_read(s, logfile->fp, 8192);
    897 
    898       /* restore old signal handler
    899        */
    900       (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &old_act, NULL);
    901888
    902889      if (status <= 0)
  • trunk/src/sh_mail.c

    r362 r379  
    531531    static int   failcount = 0;
    532532    FILE       * connfile  = NULL;
    533 
    534     struct  sigaction  old_act;
    535     struct  sigaction  new_act;
    536533
    537534    static  time_t fail_time = 0;
     
    671668
    672669    /* ---------- Connect ---------------------------------------- */
    673 
    674     /* -- Catch (ignore) 'broken pipe'.
    675      */
    676     new_act.sa_handler = SIG_IGN;
    677     sigemptyset( &new_act.sa_mask );         /* set an empty mask       */
    678     new_act.sa_flags = 0;                    /* init sa_flags           */
    679 
    680     (void) sigaction (SIGPIPE, &new_act, &old_act);
    681670
    682671    errcount = 0;
     
    825814      }
    826815
    827     /* --- Reset signal. ---
    828      */
    829     (void) sigaction (SIGPIPE, &old_act, NULL);
    830 
    831816    if (errcount == address_num)
    832817      {
  • trunk/src/sh_prelink.c

    r374 r379  
    164164  int    status = 0;
    165165  char * p;
    166   struct  sigaction  new_act;
    167   struct  sigaction  old_act;
    168166
    169167  SL_ENTER(_("sh_prelink_run"));
     
    256254      SL_RETURN ((-1), _("sh_prelink_run"));
    257255    }
    258 
    259   /* ignore SIGPIPE (instead get EPIPE if connection is closed)
    260    */
    261   new_act.sa_handler = SIG_IGN;
    262   (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act);
    263256
    264257  /* read from pipe
     
    275268  }
    276269
    277   /* restore old signal handler
    278    */
    279   (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &old_act, NULL);
    280 
    281270  /* close pipe and return exit status
    282271   */
  • trunk/src/sh_processcheck.c

    r374 r379  
    10221022  int    status = 0;
    10231023  char * p;
    1024   struct  sigaction  new_act;
    1025   struct  sigaction  old_act;
    10261024  int retval = 0;
    10271025  char  dir[SH_PATHBUF];
     
    10761074    }
    10771075
    1078   /* ignore SIGPIPE (instead get EPIPE if connection is closed)
    1079    */
    1080   new_act.sa_handler = SIG_IGN;
    1081   (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act);
    1082 
    10831076  /* read from the open pipe
    10841077   */
     
    10871080      retval = sh_processes_readps (task.pipe, res, str, len, flag, pid);
    10881081    }
    1089 
    1090   /* restore old signal handler
    1091    */
    1092   (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &old_act, NULL);
    10931082
    10941083  /* close pipe and return exit status
  • trunk/src/sh_tools.c

    r352 r379  
    10461046  int    num_sel;
    10471047 
    1048   struct  sigaction  new_act;
    1049   struct  sigaction  old_act;
    10501048  char    errbuf[SH_ERRBUF_SIZE];
    10511049
    10521050  SL_ENTER(_("sh_write_select"));
    10531051
    1054   /* ignore SIGPIPE (instead get EPIPE if connection is closed)
    1055    */
    1056   new_act.sa_handler = SIG_IGN;
    1057   sigemptyset( &new_act.sa_mask );         /* set an empty mask       */
    1058   new_act.sa_flags = 0;                    /* init sa_flags           */
    1059   sigaction (SIGPIPE, &new_act, &old_act);
    1060  
    10611052  FD_ZERO(&fds);
    10621053  FD_SET(sockfd, &fds);
     
    10861077              continue;
    10871078            *w_error = errno;
    1088             sigaction (SIGPIPE, &old_act, NULL);
     1079
    10891080            sh_error_message(*w_error, errbuf, sizeof(errbuf));
    10901081            sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN,
     
    11071098              continue;
    11081099            *w_error = errno;
    1109             sigaction (SIGPIPE, &old_act, NULL);
     1100
    11101101            sh_error_message(*w_error, errbuf, sizeof(errbuf));
    11111102            sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN,
     
    11361127            *w_error = 0;
    11371128#endif
    1138             sigaction (SIGPIPE, &old_act, NULL);
     1129
    11391130            TPT(( 0, FIL__, __LINE__, _("msg=<Timeout>\n")));
    11401131            SL_RETURN( countbytes, _("sh_write_select"));
     
    11621153          {
    11631154            *w_error = errno;
    1164             sigaction (SIGPIPE, &old_act, NULL);
     1155
    11651156            sh_error_message(*w_error, errbuf, sizeof(errbuf));
    11661157            sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN,
     
    11741165          {
    11751166            *w_error = errno;
    1176             sigaction (SIGPIPE, &old_act, NULL);
     1167
    11771168            TPT(( 0, FIL__, __LINE__, _("msg=<count == 0>\n")));
    11781169            SL_RETURN( countbytes, _("sh_write_select"));
     
    11801171      }
    11811172  }
    1182 
    1183 
    1184   /* restore signal handler
    1185    */
    1186   sigaction (SIGPIPE, &old_act, NULL);
    11871173
    11881174  *w_error = 0;
  • trunk/src/sh_unix.c

    r373 r379  
    699699}
    700700
     701void sh_unix_ign_sigpipe()
     702{
     703  struct sigaction ignact;
     704
     705  ignact.sa_handler = SIG_IGN;            /* signal action           */
     706  sigemptyset( &ignact.sa_mask );         /* set an empty mask       */
     707  ignact.sa_flags = 0;                    /* init sa_flags           */
     708
     709#ifdef SIGPIPE
     710  retry_sigaction(FIL__, __LINE__, SIGPIPE,   &ignact, NULL);
     711#endif
     712
     713  return;
     714}
    701715static
    702716void sh_unix_siginstall (int goDaemon)
     
    831845#endif
    832846#ifdef SIGPIPE
    833 #ifdef HAVE_PTHREAD
    834847  retry_sigaction(FIL__, __LINE__, SIGPIPE,   &ignact, &oldact);
    835 #else
    836   retry_sigaction(FIL__, __LINE__, SIGPIPE,      &act, &oldact);
    837 #endif
    838848#endif
    839849#ifdef SIGALRM
Note: See TracChangeset for help on using the changeset viewer.