Ignore:
Timestamp:
Mar 10, 2010, 9:24:17 PM (15 years ago)
Author:
katerina
Message:

Fix for ticket #195 (broken immediate mailing of highest priority messages).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_log_check.c

    r272 r275  
    3939#include "sh_log_mark.h"
    4040#include "sh_log_repeat.h"
     41#include "sh_extern.h"
    4142
    4243/* List of supported logfile types, format is
     
    5758    {  "PACCT",  sh_read_pacct,   sh_parse_pacct,  NULL },
    5859#endif
     60    {  "SHELL",  sh_read_shell,   sh_parse_generic,  sh_eval_fileinfo_generic },
    5961};
    6062
     
    237239    }
    238240
    239   if (splits[1][0] != '/')
     241  if (splits[1][0] != '/' && 0 != strcmp(splits[0], _("SHELL")))
    240242    {
    241243      sh_string * msg =  sh_string_new(0);
     
    258260
    259261  thisfile->filename     = filename;
    260   thisfile->flags        = SH_LOGFILE_REWIND;
     262  if (strcmp(splits[0], _("SHELL")))
     263    thisfile->flags        = SH_LOGFILE_NOFILE;
     264  else
     265    thisfile->flags        = SH_LOGFILE_REWIND;
    261266  thisfile->inode        = 0;
    262267  thisfile->device_id    = 0;
     
    323328  /* Try reading saved offset. On success clear rewind flag.
    324329   */
    325   if (0 == stat(thisfile->filename, &buf))
    326     {
    327       if (S_ISREG(buf.st_mode)
     330  if ((thisfile->flags & SH_LOGFILE_NOFILE) == 0)
     331    {
     332      if (0 == stat(thisfile->filename, &buf))
     333        {
     334          if (S_ISREG(buf.st_mode)
    328335#ifdef S_ISLNK
    329           || S_ISLNK(buf.st_mode)
     336              || S_ISLNK(buf.st_mode)
    330337#endif
    331           )
    332         {
    333           thisfile->inode     = buf.st_ino;
    334           thisfile->device_id = buf.st_dev;
     338              )
     339            {
     340              thisfile->inode     = buf.st_ino;
     341              thisfile->device_id = buf.st_dev;
     342             
     343              if (0 != read_pos(thisfile))
     344                {
     345                  thisfile->flags &= ~SH_LOGFILE_REWIND;
     346                }
     347            }
     348          else if (S_ISFIFO(buf.st_mode))
     349            {
     350              thisfile->inode      = buf.st_ino;
     351              thisfile->device_id  = buf.st_dev;
     352              thisfile->flags     |= SH_LOGFILE_PIPE;
     353            }
     354        }
     355      else
     356        {
     357          sh_string * msg =  sh_string_new(0);
     358          sh_string_add_from_char(msg, _("Logfile is not a regular file, link, or named pipe: "));
     359          sh_string_add_from_char(msg, splits[1]);
    335360         
    336           if (0 != read_pos(thisfile))
    337             {
    338               thisfile->flags &= ~SH_LOGFILE_REWIND;
    339             }
    340         }
    341       else if (S_ISFIFO(buf.st_mode))
    342         {
    343           thisfile->inode      = buf.st_ino;
    344           thisfile->device_id  = buf.st_dev;
    345           thisfile->flags     |= SH_LOGFILE_PIPE;
    346         }
    347     }
    348   else
    349     {
    350       sh_string * msg =  sh_string_new(0);
    351       sh_string_add_from_char(msg, _("Logfile is not a regular file, link, or named pipe: "));
    352       sh_string_add_from_char(msg, splits[1]);
    353      
    354       SH_MUTEX_LOCK(mutex_thread_nolog);
    355       sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, 0, MSG_E_SUBGEN,
    356                       sh_string_str(msg),
    357                       _("sh_add_watch"));
    358       SH_MUTEX_UNLOCK(mutex_thread_nolog);
    359       sh_string_destroy(&msg);
    360      
    361       SH_FREE(filename);
    362       SH_FREE(thisfile);
    363       SH_FREE(new);
    364       return -1;
     361          SH_MUTEX_LOCK(mutex_thread_nolog);
     362          sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, 0, MSG_E_SUBGEN,
     363                          sh_string_str(msg),
     364                          _("sh_add_watch"));
     365          SH_MUTEX_UNLOCK(mutex_thread_nolog);
     366          sh_string_destroy(&msg);
     367         
     368          SH_FREE(filename);
     369          SH_FREE(thisfile);
     370          SH_FREE(new);
     371          return -1;
     372        }
    365373    }
    366374
     
    380388      sh_watched_logs = thisfile->next;
    381389
    382       if ((thisfile->flags & SH_LOGFILE_PIPE) == 0)
     390      if ((thisfile->flags & SH_LOGFILE_NOFILE) == 0 &&
     391          (thisfile->flags & SH_LOGFILE_PIPE) == 0)
    383392        {
    384393          save_pos(thisfile);
    385394        }
    386395
    387       if (thisfile->fp)
    388         sl_fclose(FIL__, __LINE__, thisfile->fp);
     396      if ((thisfile->flags & SH_LOGFILE_NOFILE) == 0)
     397        {
     398          if (thisfile->fp)
     399            sl_fclose(FIL__, __LINE__, thisfile->fp);
     400        }
     401
    389402      if (thisfile->filename)
    390403        SH_FREE(thisfile->filename);
     
    677690sh_string * sh_default_reader (sh_string * s, struct sh_logfile * logfile)
    678691{
    679   int         status;
     692  volatile int         status;
    680693  char * tmp;
    681694
     
    712725  if (0 != sh_open_for_reader(logfile))
    713726    goto start_read;
     727
     728  return NULL;
     729}
     730
     731sh_string * sh_command_reader (sh_string * s, struct sh_logfile * logfile)
     732{
     733  sh_tas_t task;
     734  struct  sigaction  new_act;
     735  struct  sigaction  old_act;
     736
     737  volatile int         status;
     738  char * tmp;
     739
     740 start_read:
     741
     742  if (logfile->fp)
     743    {
     744      /* ignore SIGPIPE (instead get EPIPE if connection is closed)
     745       */
     746      new_act.sa_handler = SIG_IGN;
     747      (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act);
     748
     749      /* Result cannot be larger than 8192, thus cast is ok
     750       */
     751      status = (int) sh_string_read(s, logfile->fp, 8192);
     752
     753      /* restore old signal handler
     754       */
     755      (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &old_act, NULL);
     756
     757      if (status <= 0)
     758        {
     759          sh_ext_pclose (&task);
     760          logfile->fp = NULL;
     761          sh_string_destroy(&s);
     762
     763          if (status == 0)
     764            {
     765              return NULL;
     766            }
     767
     768          SH_MUTEX_LOCK(mutex_thread_nolog);
     769          tmp = sh_util_safe_name (logfile->filename);
     770          sh_error_handle((-1), FIL__, __LINE__, 0, MSG_LOGMON_EREAD,
     771                          tmp);
     772          SH_FREE(tmp);
     773          SH_MUTEX_UNLOCK(mutex_thread_nolog);
     774
     775          return NULL;
     776        }
     777      return s;
     778    }
     779
     780  status = sh_ext_popen_init (&task, logfile->filename);
     781  if (0 == status)
     782    {
     783      logfile->fp = task.pipe;
     784      goto start_read;
     785    }
     786  else
     787    {
     788      SH_MUTEX_LOCK(mutex_thread_nolog);
     789      sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, status, MSG_E_SUBGEN,
     790                      _("Could not open pipe"), _("sh_command reader"));
     791      SH_MUTEX_UNLOCK(mutex_thread_nolog);
     792    }
    714793
    715794  return NULL;
Note: See TracChangeset for help on using the changeset viewer.