Skip to content

Commit

Permalink
wait for task to die before killing MTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed committed Dec 19, 2024
1 parent 760db24 commit a38cdda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/helpers/mterm/MTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <OS.h>
#include <SupportDefs.h>
#include "GMessage.h"
#include <syslog.h>

/* handshake interface */
typedef struct
Expand Down Expand Up @@ -162,8 +161,6 @@ MTerm::MTerm(const BMessenger& msgr) : fExecProcessID(-1), fFd(-1), fMessenger(m
MTerm::~MTerm()
{
Kill();
syslog(LOG_INFO|LOG_PID|LOG_CONS|LOG_USER, "S) Genio: ~MTerm() called (fMessenger.IsValid() = %d)",fMessenger.IsValid());
fMessenger = BMessenger();
}

void
Expand All @@ -181,8 +178,6 @@ MTerm::Run(int argc, const char* const* argv)
void
MTerm::Kill()
{
syslog(LOG_INFO|LOG_PID|LOG_CONS|LOG_USER, "S) Genio: MTerm::Kill called (fExecProcessID %d fReadTask %p fFd %d)", fExecProcessID, fReadTask, fFd);

if (fReadTask) {
fReadTask->Stop();
fReadTask = nullptr;
Expand All @@ -195,7 +190,6 @@ MTerm::Kill()
wait(&status);
fFd = -1;
}
syslog(LOG_INFO|LOG_PID|LOG_CONS|LOG_USER, "E) Genio: MTerm::Kill called (fExecProcessID %d fReadTask %p fFd %d)", fExecProcessID, fReadTask, fFd);
}


Expand Down
20 changes: 20 additions & 0 deletions src/helpers/mterm/MTermView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <ScrollView.h>
#include <String.h>
#include "KeyTextViewScintilla.h"
#include "Log.h"

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "TermView"
Expand Down Expand Up @@ -100,6 +101,25 @@ MTermView::MessageReceived(BMessage* message)
break;
}
case Genio::Task::TASK_RESULT_MESSAGE:
{
// The task is ending. Let's avoid calling _EnsureStopped() (which terminates the task)
// before it has fully completed, to prevent potentially entering an inconsistent
// kernel lock state.

thread_id taskId = (thread_id)message->GetInt32("TaskResult::TaskID", -1);
if (taskId > -1) {
status_t threadStatus = B_OK;
status_t waitStatus = wait_for_thread(taskId, &threadStatus);
LogInfo("TASK_RESULT_MESSAGE for thread %d: threadStatus (%s) waitStatus (%s)",
taskId,
strerror(threadStatus),
strerror(waitStatus));
_EnsureStopped();
}


break;
}
case kTermViewStop:
{
_EnsureStopped();
Expand Down

0 comments on commit a38cdda

Please sign in to comment.