Menu

#1112 Fix Regression from fix in #104: Kill compiling with SIGTERM instead of SIGKILL

Next_Nightly
applied
Patch
2021-07-01
2021-06-30
bluehazzard
No

The fix introduced in [#104] kills the compiling process hard. This can lead to corrupt object and lib files.

with this patch i try to fix it, by check if we are compiling or running the application.
On compiling i send SIGTERM, on running i send SIGKILL

This fixes the issue for me.
A more elaborate solution would be to make the termination a two step process, first gently ask for termination with SIGTERM (and mark the terminate button with a other symbol/color) and if the user presses the button a second time, send a SIGKILL.
This requires a lot of rework in UI and SDK code.
For me the patch posted here is enough

tested on linux and windows

1 Attachments

Related

Tickets: #104

Discussion

  • bluehazzard

    bluehazzard - 2021-06-30
    • labels: --> sdk, compilergcc
     
  • Teodor Petrov

    Teodor Petrov - 2021-06-30

    I've modified the patch a bit. I think this version is a bit clearer.

    diff --git a/src/plugins/compilergcc/compilergcc.cpp b/src/plugins/compilergcc/compilergcc.cpp
    index 29338bc20..0ea4ca9f6 100644
    --- a/src/plugins/compilergcc/compilergcc.cpp
    +++ b/src/plugins/compilergcc/compilergcc.cpp
    @@ -2950,6 +2950,8 @@ int CompilerGCC::KillProcess()
         wxKillError ret = wxKILL_OK;
    
         m_CommandQueue.Clear();
    +    ProjectManager *projectManager = Manager::Get()->GetProjectManager();
    +    const bool isRunning = (projectManager->GetIsRunning() == this);
    
         for (CompilerProcess &p : m_CompilerProcessList)
         {
    @@ -2965,7 +2967,22 @@ int CompilerGCC::KillProcess()
             ((PipedProcess*) p.pProcess)->ForfeitStreams();
    
             wxLogNull nullLog;
    -        ret = wxProcess::Kill(p.PID, wxSIGKILL, wxKILL_CHILDREN);
    +
    +        if (isRunning)
    +        {
    +            // We are running a target, so just kill it to prevent any SIGTERM handlers to prevent
    +            // the termination.
    +            ret = wxProcess::Kill(p.PID, wxSIGKILL, wxKILL_CHILDREN);
    +        }
    +        else
    +        {
    +            // This is a compilation process and compilers generally don't prevent SIGTERM, in fact
    +            // they handle it correctly and clean up file, so we're supposed to use SIGTERM on them.
    +            // If we use SIGKILL they might leave some partially written files, partially written
    +            // object files pretty bad, because they lead to broken incremental builds (the linking
    +            // fails).
    +            ret = wxProcess::Kill(p.PID, wxSIGTERM, wxKILL_CHILDREN);
    +        }
    
             // According wxWidgets Documentation [1] OnTerminate is never called if we use
             // wxProcess::Kill. The pointer to the wxProcess object is used to check if the
    @@ -3002,9 +3019,8 @@ int CompilerGCC::KillProcess()
             }
         }
    
    -    ProjectManager *projectManager = Manager::Get()->GetProjectManager();
    -    if (projectManager->GetIsRunning() == this)
    -        projectManager->SetIsRunning(NULL);
    +    if (isRunning)
    +        projectManager->SetIsRunning(nullptr);
         return ret;
     }
    

    It can probably be simplified a bit further by:

    ret = wxProcess::Kill(p.PID, (isRunning ? wxSIGKILL : wxSIGTERM), wxKILL_CHILDREN);
    

    But I'm not sure if it will make it more clear by doing so.

     
  • Teodor Petrov

    Teodor Petrov - 2021-06-30
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -The fix introduced in #104 (https://sourceforge.net/p/codeblocks/tickets/104/ ) kills the compiling process hard. This can lead to corrupt object and lib files.
    +The fix introduced in [#104] kills the compiling process hard. This can lead to corrupt object and lib files.
    
     with this patch i try to fix it, by check if we are compiling or running the application.
     On compiling i send SIGTERM, on running i send SIGKILL
    
     

    Related

    Tickets: #104

  • Teodor Petrov

    Teodor Petrov - 2021-06-30
    • Milestone: Undefined --> Next_Nightly
     
  • bluehazzard

    bluehazzard - 2021-07-01
    • status: open --> applied
     
  • bluehazzard

    bluehazzard - 2021-07-01

    thank you!
    is in r12482

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.