Skip to content

Commit

Permalink
Fix/consoleio crash (#467)
Browse files Browse the repository at this point in the history
* updated kill procedure

* wait for task to die before killing MTerm
  • Loading branch information
Freaxed authored Dec 20, 2024
1 parent 2ddb731 commit 1c24238
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/helpers/mterm/MTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ MTerm::Run(int argc, const char* const* argv)
void
MTerm::Kill()
{
if(fExecProcessID > -1) {
kill_thread(fExecProcessID);
fExecProcessID = -1;
}
if (fReadTask) {
fReadTask->Stop();
fReadTask = nullptr;
}
if (fFd > -1) {
if (fFd >= 0) {
close(fFd);
kill(-fExecProcessID, SIGHUP);
fExecProcessID = -1;
int status;
wait(&status);
fFd = -1;
}
}
Expand Down Expand Up @@ -291,7 +291,7 @@ MTerm::_Spawn(int argc, const char* const* argv)
/*
* set terminal interface.
*/
tio.c_lflag &= ~ECHO;
tio.c_lflag &= ~ECHO;
if (tcsetattr(0, TCSANOW, &tio) == -1) {
handshake.status = PTY_NG;
snprintf(handshake.msg, sizeof(handshake.msg),
Expand Down
21 changes: 20 additions & 1 deletion src/helpers/mterm/MTermView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "ConfigManager.h"
#include "KeyTextViewScintilla.h"
#include "Log.h"
#include "MTerm.h"
#include "Styler.h"

Expand Down Expand Up @@ -147,6 +148,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 Expand Up @@ -176,7 +196,6 @@ void
MTermView::_EnsureStopped()
{
if (fMTerm != nullptr) {
fMTerm->Kill();
delete fMTerm;
fMTerm = nullptr;
fKeyTextView->EnableInput(false);
Expand Down

0 comments on commit 1c24238

Please sign in to comment.