@@ -714,6 +714,42 @@ std::shared_ptr<CommandExecute> CommandAgent::PrepareCommandExecute(const std::s
714
714
return retval;
715
715
}
716
716
717
+ void CommandAgent::StartCommandExecute (const std::shared_ptr<CommandMessage>& message)
718
+ {
719
+ Concurrency::critical_section::scoped_lock s (m_cs);
720
+
721
+ std::shared_ptr<CommandExecute> command = nullptr ;
722
+ for (const auto & runningCommand : m_RunningCommands)
723
+ {
724
+ if (runningCommand == nullptr )
725
+ {
726
+ continue ;
727
+ }
728
+
729
+ if (runningCommand->ProcessID () == message->ProcessID ())
730
+ {
731
+ command = runningCommand;
732
+ }
733
+ }
734
+
735
+ if (command == nullptr )
736
+ {
737
+ Log::Critical (L" Command '{}' resume rejected, command not found" , message->Keyword ());
738
+ return ;
739
+ }
740
+
741
+ HRESULT hr = command->ResumeChildProcess ();
742
+ if (FAILED (hr))
743
+ {
744
+ Log::Critical (L" Command '{}' resume failed [{}]" , message->Keyword (), SystemError (hr));
745
+ TerminateProcess (command->ProcessHandle (), -1 );
746
+ return ;
747
+ }
748
+
749
+ Concurrency::send<CommandNotification::Notification>(
750
+ m_target, CommandNotification::NotifyStarted (command->GetKeyword (), command->ProcessID ()));
751
+ }
752
+
717
753
typedef struct _CompletionBlock
718
754
{
719
755
CommandAgent* pAgent;
@@ -804,6 +840,7 @@ HRESULT CommandAgent::ExecuteNextCommand()
804
840
timer->start ();
805
841
}
806
842
843
+ // Register a callback that will handle process termination (release semaphore, notify, etc...)
807
844
HANDLE hWaitObject = INVALID_HANDLE_VALUE;
808
845
CompletionBlock* pBlockPtr = (CompletionBlock*)Concurrency::Alloc (sizeof (CompletionBlock));
809
846
CompletionBlock* pBlock = new (pBlockPtr) CompletionBlock;
@@ -834,17 +871,6 @@ HRESULT CommandAgent::ExecuteNextCommand()
834
871
notification->SetProcessCommandLine (command->m_commandLine );
835
872
836
873
SendResult (notification);
837
-
838
- hr = command->ResumeChildProcess ();
839
- if (FAILED (hr))
840
- {
841
- m_MaximumRunningSemaphore.Release ();
842
- command->CompleteExecution ();
843
- return S_OK;
844
- }
845
-
846
- Concurrency::send<CommandNotification::Notification>(
847
- m_target, CommandNotification::NotifyStarted (command->GetKeyword (), command->ProcessID ()));
848
874
}
849
875
850
876
return S_OK;
@@ -1230,6 +1256,11 @@ void CommandAgent::run()
1230
1256
}
1231
1257
}
1232
1258
break ;
1259
+ case CommandMessage::Start: {
1260
+ Log::Debug (L" CommandAgent: Start command '{}'" , request->Keyword ());
1261
+ StartCommandExecute (request);
1262
+ }
1263
+ break ;
1233
1264
case CommandMessage::RefreshRunningList: {
1234
1265
Concurrency::critical_section::scoped_lock s (m_cs);
1235
1266
auto new_end = std::remove_if (
0 commit comments