Przeglądaj źródła

Merge branch 'candidate-5.4.0'

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 10 lat temu
rodzic
commit
484806ff8e

+ 4 - 4
ecl/agentexec/agentexec.cpp

@@ -241,14 +241,14 @@ int CEclAgentExecutionServer::executeWorkunit(const char * wuid)
 
 //---------------------------------------------------------------------------------
 
-bool ControlHandler() 
-{ 
+bool ControlHandler()
+{
     if (execSvr)
     {
         execSvr->stop();
     }
-    return false; 
-} 
+    return false;
+}
 
 //---------------------------------------------------------------------------------
 

+ 45 - 8
system/jlib/jmisc.cpp

@@ -696,21 +696,31 @@ class AbortHandlerInfo : public CInterface
 public:
     ThreadId installer;
     AbortHandler handler;
+    SimpleAbortHandler shandler;
     IAbortHandler *ihandler;
     AbortHandlerInfo(AbortHandler _handler)
     {
         handler = _handler;
+        shandler = NULL;
+        ihandler = NULL;
+        installer = GetCurrentThreadId();
+    }
+    AbortHandlerInfo(SimpleAbortHandler _handler)
+    {
+        handler = NULL;
+        shandler = _handler;
         ihandler = NULL;
         installer = GetCurrentThreadId();
     }
     AbortHandlerInfo(IAbortHandler *_ihandler)
     {
         handler = NULL;
+        shandler = NULL;
         ihandler = _ihandler;
         installer = GetCurrentThreadId();
     }
 
-    bool handle()
+    bool handle(ahType type)
     {
 #ifndef _WIN32
         if (installer == GetCurrentThreadId())
@@ -718,7 +728,9 @@ public:
         {
 //          DBGLOG("handle abort %x", GetCurrentThreadId());
             if (handler)
-                return handler();
+                return handler(type);
+            else if (shandler)
+                return shandler();
             else
                 return ihandler->onAbort();
         }
@@ -731,7 +743,7 @@ public:
 
 CIArrayOf<AbortHandlerInfo> handlers;
 
-bool notifyOnAbort()
+bool notifyOnAbort(ahType type)
 {
 //  DBGLOG("notifyOnAbort %x", GetCurrentThreadId());
 //      CriticalBlock c(abortCrit); You would think that this was needed, but it locks up.
@@ -739,7 +751,7 @@ bool notifyOnAbort()
     bool doExit = false;
     ForEachItemInRev(idx, handlers)
     {
-        if (handlers.item(idx).handle())
+        if (handlers.item(idx).handle(type))
             doExit = true;
     }
 //  DBGLOG("notifyOnAbort returning %d", (int) doExit);
@@ -756,13 +768,13 @@ BOOL WINAPI WindowsAbortHandler ( DWORD dwCtrlType )
         case CTRL_CLOSE_EVENT:
         {
             hadAbortSignal = true;
-            bool doExit = notifyOnAbort();
+            bool doExit = notifyOnAbort(ahInterrupt);
             return !doExit; 
         }
         case CTRL_LOGOFF_EVENT:
         case CTRL_SHUTDOWN_EVENT:
             hadAbortSignal = true;
-            notifyOnAbort();
+            notifyOnAbort(ahTerminate);
             return FALSE;
     }
     return FALSE; 
@@ -782,10 +794,14 @@ BOOL WINAPI ModuleExitHandler ( DWORD dwCtrlType )
     return FALSE; 
 } 
 #else
-static void UnixAbortHandler(int sig)
+static void UnixAbortHandler(int signo)
 {
+    ahType type = ahInterrupt;
+    if (SIGTERM == signo)
+            type = ahTerminate;
+
     hadAbortSignal = true;
-    if (handlers.length()==0 || notifyOnAbort())
+    if (handlers.length()==0 || notifyOnAbort(type))
     {
         _exit(0);
     }
@@ -850,6 +866,13 @@ void addAbortHandler(AbortHandler handler)
     handlers.append(*new AbortHandlerInfo(handler));
 }
 
+void addAbortHandler(SimpleAbortHandler handler)
+{
+    CriticalBlock c(abortCrit);
+    queryInstallAbortHandler();
+    handlers.append(*new AbortHandlerInfo(handler));
+}
+
 void addAbortHandler(IAbortHandler & handler)
 {
     CriticalBlock c(abortCrit);
@@ -871,6 +894,20 @@ void removeAbortHandler(AbortHandler handler)
     queryUninstallAbortHandler();
 }
 
+void removeAbortHandler(SimpleAbortHandler handler)
+{
+    CriticalBlock c(abortCrit);
+    ForEachItemInRev(idx, handlers)
+    {
+        if (handlers.item(idx).shandler == handler)
+        {
+            handlers.remove(idx);
+            break;
+        }
+    }
+    queryUninstallAbortHandler();
+}
+
 void removeAbortHandler(IAbortHandler & handler)
 {
     CriticalBlock c(abortCrit);

+ 10 - 3
system/jlib/jmisc.hpp

@@ -246,7 +246,10 @@ inline unsigned __int32 low(__int64 n)
 
 //MORE - We really should restructure this file.  Also would this be better with a class interface?
 //Handle ^C/break from a console program.
-typedef bool (*AbortHandler)();                                                 // return true to exit program
+
+enum ahType { ahTerminate, ahInterrupt};
+typedef bool (*AbortHandler)(ahType);                                       // return true to exit program
+typedef bool (*SimpleAbortHandler)();
 
 interface IAbortHandler : public IInterface
 {
@@ -256,8 +259,10 @@ interface IAbortHandler : public IInterface
 #define JLIBERR_UserAbort       0xffffff00
 
 extern jlib_decl void addAbortHandler(AbortHandler handler=NULL);               // no parameter means just set the flag for later testing.
+extern jlib_decl void addAbortHandler(SimpleAbortHandler handler=NULL);
 extern jlib_decl void addAbortHandler(IAbortHandler & handler);
 extern jlib_decl void removeAbortHandler(AbortHandler handler);
+extern jlib_decl void removeAbortHandler(SimpleAbortHandler handler);
 extern jlib_decl void removeAbortHandler(IAbortHandler & handler);
 extern jlib_decl bool isAborting();
 extern jlib_decl void throwAbortException();
@@ -272,10 +277,12 @@ interface IAbortRequestCallback
 class LocalAbortHandler
 {
 public:
-    LocalAbortHandler(AbortHandler _handler=NULL)   { handler = _handler; addAbortHandler(handler); }
-    ~LocalAbortHandler()                            { removeAbortHandler(handler); }
+    LocalAbortHandler(AbortHandler _handler=NULL)   { handler = _handler; shandler = NULL; addAbortHandler(handler); }
+    LocalAbortHandler(SimpleAbortHandler _handler=NULL) { shandler = _handler; handler = NULL; addAbortHandler(shandler); }
+    ~LocalAbortHandler()                            { if (handler) { removeAbortHandler(handler); } else removeAbortHandler(shandler); }
 private:
     AbortHandler            handler;
+    SimpleAbortHandler        shandler;
 };
 
 class LocalIAbortHandler

+ 7 - 4
thorlcr/master/thgraphmanager.cpp

@@ -776,12 +776,15 @@ void abortThor(IException *e, unsigned errCode, bool abortCurrentJob)
     if (0 == aborting)
     {
         aborting = 1;
-        if (!e)
+        if (errCode != TEC_Clean)
         {
-            _e.setown(MakeThorException(TE_AbortException, "THOR ABORT"));
-            e = _e;
+            if (!e)
+            {
+                _e.setown(MakeThorException(TE_AbortException, "THOR ABORT"));
+                e = _e;
+            }
+            EXCLOG(e,"abortThor");
         }
-        EXCLOG(e,"abortThor");
         LOG(MCdebugProgress, thorJob, "abortThor called");
         if (jM)
             jM->stop();

+ 41 - 28
thorlcr/master/thmastermain.cpp

@@ -401,42 +401,55 @@ bool checkClusterRelicateDAFS(IGroup *grp)
 static bool auditStartLogged = false;
 
 static bool firstCtrlC = true;
-bool ControlHandler() 
-{ 
-    if (firstCtrlC)
+bool ControlHandler(ahType type)
+{
+    if (ahInterrupt == type)
     {
-        LOG(MCdebugProgress, thorJob, "CTRL-C detected");
-        firstCtrlC = false;
+        if (firstCtrlC)
         {
-            Owned<CRegistryServer> registry = CRegistryServer::getRegistryServer();
-            if (registry)
-                registry->stop();
+            LOG(MCdebugProgress, thorJob, "CTRL-C detected");
+            firstCtrlC = false;
+            {
+                Owned<CRegistryServer> registry = CRegistryServer::getRegistryServer();
+                if (registry)
+                    registry->stop();
+            }
+            abortThor(NULL, TEC_CtrlC);
         }
-        abortThor(NULL, TEC_CtrlC);
-    }
-    else
-    {
-        LOG(MCdebugProgress, thorJob, "2nd CTRL-C detected - terminating process");
-
-        if (auditStartLogged)
+        else
         {
-            auditStartLogged = false;
-            LOG(daliAuditLogCat,",Progress,Thor,Terminate,%s,%s,%s,ctrlc",
-                queryServerStatus().queryProperties()->queryProp("@thorname"),
-                queryServerStatus().queryProperties()->queryProp("@nodeGroup"),
-                queryServerStatus().queryProperties()->queryProp("@queue"));
-        }
-        queryLogMsgManager()->flushQueue(10*1000);
+            LOG(MCdebugProgress, thorJob, "2nd CTRL-C detected - terminating process");
+
+            if (auditStartLogged)
+            {
+                auditStartLogged = false;
+                LOG(daliAuditLogCat,",Progress,Thor,Terminate,%s,%s,%s,ctrlc",
+                    queryServerStatus().queryProperties()->queryProp("@thorname"),
+                    queryServerStatus().queryProperties()->queryProp("@nodeGroup"),
+                    queryServerStatus().queryProperties()->queryProp("@queue"));
+            }
+            queryLogMsgManager()->flushQueue(10*1000);
 #ifdef _WIN32
-        TerminateProcess(GetCurrentProcess(), 1);
+            TerminateProcess(GetCurrentProcess(), 1);
 #else
-        //MORE- verify this
-        kill(getpid(), SIGKILL);
+            //MORE- verify this
+            // why not just raise(SIGKILL);  ?
+            kill(getpid(), SIGKILL);
 #endif
-        _exit(1);
+            _exit(1);
+        }
     }
-    return false; 
-} 
+    // ahTerminate
+    else
+    {
+        LOG(MCdebugProgress, thorJob, "SIGTERM detected, shutting down");
+        Owned<CRegistryServer> registry = CRegistryServer::getRegistryServer();
+        if (registry)
+            registry->stop();
+        abortThor(NULL, TEC_Clean);
+    }
+    return false;
+}
 
 
 #include "thactivitymaster.hpp"

+ 7 - 5
thorlcr/slave/thslavemain.cpp

@@ -192,12 +192,14 @@ void UnregisterSelf(IException *e)
     }
 }
 
-bool ControlHandler() 
-{ 
-    LOG(MCdebugProgress, thorJob, "CTRL-C pressed");
-    if (masterNode) UnregisterSelf(NULL);
+bool ControlHandler(ahType type)
+{
+    if (ahInterrupt == type)
+        LOG(MCdebugProgress, thorJob, "CTRL-C pressed");
+    if (masterNode)
+        UnregisterSelf(NULL);
     abortSlave();
-    return false; 
+    return false;
 }
 
 void usage()