Changeset 2211 for trunk/auto-reply

Show
Ignore:
Timestamp:
08/17/00 07:02:25 (8 years ago)
Author:
graham
Message:

Added two new options, FailOnExitCode? and AbortDeleteOnExitCode? which
allows the reply to be aborted if the exit code of the program is non-zero.

Location:
trunk/auto-reply
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/auto-reply/licq_autoreply.conf

    r2204 r2211  
    2323PassMessage = 0 
    2424 
     25# If this is set, then the exit code of the command will 
     26# be used to determine if the message should be sent or 
     27# not.  A non-zero code will cause the reply to be aborted. 
     28FailOnExitCode = 0 
     29 
     30# This value is used if the above is set and the exit code 
     31# is non zero.  If set then a bad exit code will not delete 
     32# the relevant message.  If not set then the event will be 
     33# erased even if the command exit code is non-zero. 
     34AbortDeleteOnExitCode = 1 
     35 
    2536 
    2637# Here is a simple example which will bounce the event 
  • trunk/auto-reply/src/autoreply.cpp

    r2204 r2211  
    8585  conf.ReadStr("Arguments", m_szArguments, ""); 
    8686  conf.ReadBool("PassMessage", m_bPassMessage, false); 
     87  conf.ReadBool("FailOnExitCode", m_bFailOnExitCode, false); 
     88  conf.ReadBool("AbortDeleteOnExitCode", m_bAbortDeleteOnExitCode, false); 
    8789  conf.CloseFile(); 
    8890 
     
    286288    m_szMessage[pos++] = c; 
    287289  } 
    288   PClose(); 
     290  int r = 0; 
     291  if ((r = PClose()) != 0 && m_bFailOnExitCode) 
     292  { 
     293    gLog.Warn("%s%s returned abnormally: exit code %d\n", L_AUTOREPxSTR, 
     294     szCommand, r); 
     295    return !m_bAbortDeleteOnExitCode; 
     296  } 
    289297 
    290298  char *szText = new char[4096 + 256]; 
     
    367375 
    368376 
    369 void CLicqAutoReply::PClose() 
     377int CLicqAutoReply::PClose() 
    370378{ 
    371379   int r, pstat; 
     380   struct timeval tv = { 0, 200000 }; 
    372381 
    373382   // Close the file descriptors 
     
    379388   r = waitpid(pid, &pstat, WNOHANG); 
    380389   // Return if child has exited or there was an inor 
    381    if (r == pid || r == -1) return; 
     390   if (r == pid || r == -1) goto pclose_done; 
    382391 
    383392   // Give the process another .2 seconds to die 
    384    struct timeval tv = { 0, 200000 }; 
    385393   select(0, NULL, NULL, NULL, &tv); 
    386394 
    387395   // Still there? 
    388396   r = waitpid(pid, &pstat, WNOHANG); 
    389    if (r == pid || r == -1) return; 
     397   if (r == pid || r == -1) goto pclose_done; 
    390398 
    391399   // Try and kill the process 
    392    if (kill(pid, SIGTERM) == -1) return; 
     400   if (kill(pid, SIGTERM) == -1) return -1; 
    393401 
    394402   // Give it 1 more second to die 
     
    399407   // See if the child is still there 
    400408   r = waitpid(pid, &pstat, WNOHANG); 
    401    if (r == pid || r == -1) return; 
     409   if (r == pid || r == -1) goto pclose_done; 
    402410 
    403411   // Kill the bastard 
     
    405413   // Now he will die for sure 
    406414   waitpid(pid, &pstat, 0); 
    407 } 
    408  
    409  
     415 
     416pclose_done: 
     417 
     418   if (WIFEXITED(pstat)) return WEXITSTATUS(pstat); 
     419   return -1; 
     420 
     421} 
     422 
     423 
  • trunk/auto-reply/src/autoreply.h

    r2204 r2211  
    2727  char *m_szStatus; 
    2828  char m_szProgram[512], m_szArguments[512]; 
    29   bool m_bPassMessage; 
     29  bool m_bPassMessage, m_bFailOnExitCode, m_bAbortDeleteOnExitCode; 
    3030 
    3131  CICQDaemon *licqDaemon; 
     
    4141 
    4242  bool POpen(const char *cmd); 
    43   void PClose(); 
     43  int PClose(); 
    4444 
    4545protected: