Changeset 481 for trunk/src/sh_unix.c


Ignore:
Timestamp:
Jul 18, 2015, 5:06:52 PM (10 years ago)
Author:
katerina
Message:

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_unix.c

    r474 r481  
    103103#include "sh_prelink.h"
    104104#include "sh_pthread.h"
     105#include "sh_sem.h"
    105106
    106107/* moved here from far below
     
    482483  sl_strlcat(msg, details, 128);
    483484  (void) safe_logger (thesignal, method, msg);
     485
     486  close_ipc ();
    484487  raise(SIGKILL);
    485488}
     
    526529          } while (val_return < 0 && errno == EINTR);
    527530
     531          close_ipc ();
    528532          safe_logger (mysignal, 0, NULL);
    529533        }
     
    594598      if (skey != NULL)
    595599        memset (skey, '\0', sizeof(sh_key_t));
    596 #ifdef WITH_MESSAGE_QUEUE
    597600      close_ipc ();
    598 #endif
    599601      safe_logger (mysignal, 0, NULL);
    600602      do {
     
    636638  if (skey != NULL)
    637639    memset (skey, '\0', sizeof(sh_key_t));
    638 #ifdef WITH_MESSAGE_QUEUE
    639640  close_ipc ();
    640 #endif
    641641
    642642  do {
     
    669669#endif
    670670#ifdef SIGTTOU
    671   if (mysignal == SIGTTOU)
    672     sig_force_check = 1;
     671  if (mysignal == SIGTTOU) {
     672    sig_force_check = 1; sh_sem_trylock(); }
    673673#endif
    674674#ifdef SIGTTIN
     
    682682#ifdef SIGQUIT
    683683  if (mysignal == SIGQUIT)
    684     {
    685       sig_terminate       = 1;
    686       ++sig_urgent;
    687     }
     684    sig_terminate       = 1;
    688685#endif
    689686#ifdef SIGTERM
     
    10421039      if ((status == ERANGE) && (w == NULL))
    10431040        {
    1044           if (SL_TRUE ==  sl_ok_adds( gbufsize, SH_GRBUF_SIZE ))
     1041          if (S_TRUE ==  sl_ok_adds( gbufsize, SH_GRBUF_SIZE ))
    10451042            {
    10461043              SH_FREE(buffer);
     
    17221719  struct utsname   buf;
    17231720  int              i;
    1724   int              ddot;
     1721  unsigned int     ddot;
    17251722  int              len;
    17261723  char           * p;
     
    18921889   */
    18931890#if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
    1894   if (skey->mlock_failed == SL_FALSE)
     1891  if (skey->mlock_failed == S_FALSE)
    18951892    {
    18961893      if ( (-1) == sh_unix_mlock( FIL__, __LINE__,
     
    18981895        {
    18991896          SH_MUTEX_LOCK_UNSAFE(mutex_skey);
    1900           skey->mlock_failed = SL_TRUE;
     1897          skey->mlock_failed = S_TRUE;
    19011898          SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
    19021899        }
    19031900    }
    19041901#else
    1905   if (skey->mlock_failed == SL_FALSE)
     1902  if (skey->mlock_failed == S_FALSE)
    19061903    {
    19071904      SH_MUTEX_LOCK_UNSAFE(mutex_skey);
    1908       skey->mlock_failed = SL_TRUE;
     1905      skey->mlock_failed = S_TRUE;
    19091906      SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
    19101907    }
     
    19801977
    19811978  if (dummy == NULL)
    1982     sh.flag.isdaemon = ON;
     1979    sh.flag.isdaemon = S_TRUE;
    19831980  else
    19841981    res = sh_util_flagval (dummy, &sh.flag.isdaemon);
     
    20032000
    20042001  if (dummy == NULL)
    2005     sh.flag.isdaemon = OFF;
     2002    sh.flag.isdaemon = S_FALSE;
    20062003  else
    20072004    res = sh_util_flagval (dummy, &sh.flag.isdaemon);
     
    22212218    char * tz = sh_util_strdup(getenv("TZ")); /* flawfinder: ignore */
    22222219    size_t tzlen = strlen(tz);
    2223     if (SL_TRUE == sl_ok_adds (4, tzlen)) {
     2220    if (S_TRUE == sl_ok_adds (4, tzlen)) {
    22242221        env[3] = SH_ALLOC(4+tzlen);
    22252222        sl_strlcpy(env[3], "TZ=", 4);
     
    22442241      memset(skey, 0, sizeof(sh_key_t));
    22452242      (void) umask(S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
    2246       sh_unix_closeall (3, -1, SL_TRUE); /* in child process */
     2243      sh_unix_closeall (3, -1, S_TRUE); /* in child process */
    22472244      execve(path, arg, env);
    22482245      _exit(EXIT_FAILURE);
     
    22842281  struct tm   bb;
    22852282
     2283  struct tm * aptr;
     2284  struct tm * bptr;
     2285
    22862286  int  sign =  0;
    22872287  int  diff =  0;
     
    22922292
    22932293#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GMTIME_R)
    2294   gmtime_r (xx, &aa);
     2294  aptr = gmtime_r (xx, &aa);
    22952295#else
    2296   memcpy (&aa, gmtime(xx), sizeof(struct tm));
     2296  aptr = gmtime(xx);
     2297  if (aptr)
     2298    memcpy (&aa, aptr, sizeof(struct tm));
    22972299#endif
    22982300
    22992301#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_LOCALTIME_R)
    2300   localtime_r (xx, &bb);
     2302  bptr = localtime_r (xx, &bb);
    23012303#else
    2302   memcpy (&bb, localtime(xx), sizeof(struct tm));
    2303 #endif
    2304 
    2305   /* Check for datum wrap-around.
    2306    */
    2307   if      (aa.tm_year < bb.tm_year)
    2308     sign = (-1);
    2309   else if (aa.tm_mon  < bb.tm_mon)
    2310     sign = (-1);
    2311   else if (aa.tm_mday < bb.tm_mday)
    2312     sign = (-1);
    2313   else if (bb.tm_year < aa.tm_year)
    2314     sign = ( 1);
    2315   else if (bb.tm_mon  < aa.tm_mon)
    2316     sign = ( 1);
    2317   else if (bb.tm_mday < aa.tm_mday)
    2318     sign = ( 1);
    2319 
    2320   diff = aa.tm_hour * 60 + aa.tm_min;
    2321   diff = (bb.tm_hour * 60 + bb.tm_min) - diff;
    2322   diff = diff - (sign * 24 * 60);   /* datum wrap-around correction */
    2323   hh = diff / 60;
    2324   mm = diff - (hh * 60);
    2325   sprintf (tz, _("%+03d%02d"), hh, mm);                /* known to fit  */
    2326 
     2304  bptr = localtime(xx);
     2305  if (bptr)
     2306    memcpy (&bb, bptr, sizeof(struct tm));
     2307#endif
     2308
     2309  if (bptr && aptr)
     2310    {
     2311      /* Check for datum wrap-around.
     2312       */
     2313      if      (aa.tm_year < bb.tm_year)
     2314        sign = (-1);
     2315      else if (aa.tm_mon  < bb.tm_mon)
     2316        sign = (-1);
     2317      else if (aa.tm_mday < bb.tm_mday)
     2318        sign = (-1);
     2319      else if (bb.tm_year < aa.tm_year)
     2320        sign = ( 1);
     2321      else if (bb.tm_mon  < aa.tm_mon)
     2322        sign = ( 1);
     2323      else if (bb.tm_mday < aa.tm_mday)
     2324        sign = ( 1);
     2325     
     2326      diff = aa.tm_hour * 60 + aa.tm_min;
     2327      diff = (bb.tm_hour * 60 + bb.tm_min) - diff;
     2328      diff = diff - (sign * 24 * 60);   /* datum wrap-around correction */
     2329      hh = diff / 60;
     2330      mm = diff - (hh * 60);
     2331      sprintf (tz, _("%+03d%02d"), hh, mm);                /* known to fit  */
     2332    }
     2333  else
     2334    {
     2335      sprintf (tz, _("%+03d%02d"), 0, 0);
     2336    }
    23272337  SL_RETURN(tz, _("t_zone"));
    23282338}
     
    25602570static int sh_unix_use_localtime = S_FALSE;
    25612571
    2562 /* whether to use localtime for file timesatams in logs
     2572/* whether to use localtime for file timestamps in logs
    25632573 */
    25642574int sh_unix_uselocaltime (const char * c)
     
    34853495
    34863496int sh_unix_checksum_size (char * filename, off_t size, int is_max_size,
    3487                            char * fileHash, int alert_timeout, SL_TICKET fd)
     3497                           char * fileHash, int alert_timeout, SL_TICKET fd, unsigned long mask)
    34883498{
    34893499  file_type * tmpFile;
     
    35173527      char hashbuf[KEYBUF_SIZE];
    35183528      UINT64 local_length = (UINT64) (tmpFile->size < 0 ? 0 : tmpFile->size);
     3529      if (sh.flag.opts == S_TRUE) sh_tiger_set_hashtype_mask(mask);
    35193530      sl_strlcpy(fileHash,
    35203531                 sh_tiger_generic_hash (filename, fd, &(local_length),
     
    35413552
    35423553int sh_check_rotated_log (const char * path, 
    3543                           UINT64 old_size, UINT64 old_inode, const char * old_hash)
     3554                          UINT64 old_size, UINT64 old_inode, const char * old_hash, unsigned long mask)
    35443555{
    35453556  struct stat obuf;
     
    35603571          if (!SL_ISERROR(fd))
    35613572            {
    3562               sh_unix_checksum_size (rotated_file, old_size, S_FALSE, hashbuf, 120 /* alert_timeout */, fd);
     3573              sh_unix_checksum_size (rotated_file, old_size, S_FALSE,
     3574                                     hashbuf, 120 /* alert_timeout */, fd, mask);
    35633575             
    35643576              sl_close(fd);
     
    38143826  SL_ENTER(_("sh_unix_getinfo"));
    38153827
    3816   if (!MODI_INITIALIZED(theFile->check_mask))
     3828  if (!MODI_INITIALIZED(theFile->check_flags))
    38173829    {
    38183830      tmp2 = sh_util_safe_name (theFile->fullpath);
     
    38233835      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    38243836      SH_FREE(tmp2);
     3837      SL_RETURN((-1),_("sh_unix_getinfo"));
    38253838    }
    38263839
     
    39894002      if (fileHash != NULL)
    39904003        {
    3991           if ((theFile->check_mask & MODI_CHK) == 0 ||
     4004          if ((theFile->check_flags & MODI_CHK) == 0 ||
    39924005              sh_restrict_this(theFile->fullpath, (UINT64) fbuf.st_size,
    39934006                               (UINT64) fbuf.st_mode, rval_open))
     
    39954008              sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1);
    39964009            }
    3997           else if ((theFile->check_mask & MODI_PREL) != 0 &&
     4010          else if ((theFile->check_flags & MODI_PREL) != 0 &&
    39984011                   S_TRUE == sh_prelink_iself(rval_open, fbuf.st_size,
    39994012                                              alert_timeout, theFile->fullpath))
    40004013            {
    40014014              if (0 != sh_prelink_run (theFile->fullpath,
    4002                                        fileHash, alert_timeout))
     4015                                       fileHash, alert_timeout, theFile->check_flags))
    40034016                sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1);
    40044017            }
     
    40084021              UINT64 length_current = TIGER_NOLIM;
    40094022
    4010               if (MODI_TXT_ENABLED(theFile->check_mask) && fbuf.st_size < (10 * SH_TXT_MAX))
     4023              if (MODI_TXT_ENABLED(theFile->check_flags) && fbuf.st_size < (10 * SH_TXT_MAX))
    40114024                {
    40124025                  sl_init_content (rval_open, fbuf.st_size);
    40134026                }
    40144027
     4028              if (sh.flag.opts == S_TRUE) sh_tiger_set_hashtype_mask(theFile->check_flags);
    40154029              sl_strlcpy(fileHash,
    40164030                         sh_tiger_generic_hash (theFile->fullpath,
     
    40234037              content = sh_string_copy(content);
    40244038
    4025               if ((theFile->check_mask & MODI_SGROW) != 0)
     4039              if ((theFile->check_flags & MODI_SGROW) != 0)
    40264040                {
    40274041                  /* Update size so it matches the one for which the checksum
     
    40324046                  sh_unix_checksum_size (theFile->fullpath, length_current, S_TRUE,
    40334047                                         &fileHash[KEY_LEN + 1],
    4034                                          alert_timeout, rval_open);
     4048                                         alert_timeout, rval_open, theFile->check_flags);
    40354049                }
    40364050            }
     
    40464060      if (fileHash != NULL)
    40474061        {
    4048           if ((theFile->check_mask & MODI_CHK) == 0 ||
     4062          if ((theFile->check_flags & MODI_CHK) == 0 ||
    40494063              sh_restrict_this(theFile->fullpath, (UINT64) fbuf.st_size,
    40504064                               (UINT64) fbuf.st_mode, rval_open))
     
    40574071            {
    40584072              if (0 != sh_prelink_run (theFile->fullpath,
    4059                                        fileHash, alert_timeout))
     4073                                       fileHash, alert_timeout, theFile->check_flags))
    40604074                sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1);
    40614075            }
     
    40654079              UINT64 length_current = TIGER_NOLIM;
    40664080
    4067               if (MODI_TXT_ENABLED(theFile->check_mask) && fbuf.st_size < (10 * SH_TXT_MAX))
     4081              if (MODI_TXT_ENABLED(theFile->check_flags) && fbuf.st_size < (10 * SH_TXT_MAX))
    40684082                {
    40694083                  sl_init_content (rval_open, fbuf.st_size);
    40704084                }
    40714085
     4086              if (sh.flag.opts == S_TRUE) sh_tiger_set_hashtype_mask(theFile->check_flags);
    40724087              sl_strlcpy(fileHash,
    40734088                         sh_tiger_generic_hash (theFile->fullpath, rval_open,
     
    40804095              content = sh_string_copy(content);
    40814096
    4082               if ((theFile->check_mask & MODI_SGROW) != 0)
     4097              if ((theFile->check_flags & MODI_SGROW) != 0)
    40834098                {
    40844099                  /* Update size so it matches the one for which the checksum
     
    40894104                  sh_unix_checksum_size (theFile->fullpath, length_current, S_TRUE,
    40904105                                         &fileHash[KEY_LEN + 1],
    4091                                          alert_timeout, rval_open);
     4106                                         alert_timeout, rval_open, theFile->check_flags);
    40924107                }
    40934108            }
     
    41054120        sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1);
    41064121
    4107       if ((theFile->check_mask & MODI_CHK) != 0)
     4122      if ((theFile->check_flags & MODI_CHK) != 0)
    41084123        {
    41094124          tmp2 = sh_util_safe_name (theFile->fullpath);
     
    42764291  /* --- Output the file. ---
    42774292   */
    4278   if (flag_err_debug == SL_TRUE)
     4293  if (flag_err_debug == S_TRUE)
    42794294    {
    42804295      tmp2 = sh_util_safe_name ((filename == NULL) ?
     
    52945309int sh_unix_count_mlock()
    52955310{
    5296   int i = 0;
     5311  unsigned int i = 0;
    52975312  char str[32][64];
    52985313  sh_page_l * page_list;
     
    53255340#ifdef WITH_TPT
    53265341  {
    5327     int j = 0;
     5342    unsigned int j = 0;
    53285343    while (j < i && j < 32)
    53295344      {
    5330         sh_error_handle(SH_ERR_INFO, FIL__, __LINE__, j, MSG_E_SUBGEN,
     5345        sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, j, MSG_E_SUBGEN,
    53315346                        str[j], _("sh_unix_count_mlock"));
    53325347        ++j;
     
    53365351
    53375352  sl_snprintf(str[0], 64, _("%d pages locked"), i);
    5338   sh_error_handle(SH_ERR_INFO, FIL__, __LINE__, i, MSG_E_SUBGEN,
     5353  sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, i, MSG_E_SUBGEN,
    53395354                  str[0], _("sh_unix_count_mlock"));
    53405355  SL_RETURN((i), _("sh_unix_count_mlock"));
     
    55155530      this_line  = 0;
    55165531      c          = '\0';
    5517       while (c != '\n' && num > 0 && this_line < (sizeof(theline)-1))
     5532      while (c != '\n' && this_line < (sizeof(theline)-1))
    55185533        {
    55195534          do {
Note: See TracChangeset for help on using the changeset viewer.