@@ -717,6 +717,12 @@ std::string spawnDevice(uv_loop_t* loop,
717717 id = fork ();
718718 // We are the child: prepare options and reexec.
719719 if (id == 0 ) {
720+ if (driverControl.defaultStopped && (execution.plugin .empty () == false )) {
721+ kill (getpid (), SIGSTOP);
722+ }
723+ // Needed in case we want to reuse the same loop of the parent.
724+ uv_loop_fork (loop);
725+ uv_loop_fork (uv_default_loop ());
720726 // We allow being debugged and do not terminate on SIGTRAP
721727 signal (SIGTRAP, SIG_IGN);
722728 // We immediately ignore SIGUSR1 and SIGUSR2 so that we do not
@@ -761,7 +767,11 @@ std::string spawnDevice(uv_loop_t* loop,
761767 for (auto & env : execution.environ ) {
762768 putenv (strdup (DeviceSpecHelpers::reworkTimeslicePlaceholder (env, spec).data ()));
763769 }
764- execvp (execution.args [0 ], execution.args .data ());
770+ if (execution.plugin .empty ()) {
771+ LOG (info) << " Child device runs in a separate executable. Launching " << execution.args [0 ] << " ..." ;
772+ execvp (execution.args [0 ], execution.args .data ());
773+ }
774+ LOG (info) << " Child device uses plugins. Loading " << execution.plugin << " ." ;
765775 // In the general case we never end up here, because execvp is used.
766776 // Once we move to plugins however, the run the plugin without loading
767777 // a new environment so the new pid can be used to identify.
@@ -1098,14 +1108,13 @@ int doChild(int argc, char** argv, ServiceRegistry& serviceRegistry,
10981108 &deviceProxy,
10991109 &processingPolicies,
11001110 &deviceContext,
1101- &driverConfig,
1102- &loop](fair::mq::DeviceRunner& r) {
1111+ &driverConfig](fair::mq::DeviceRunner& r) {
11031112 ServiceRegistryRef serviceRef = {serviceRegistry};
11041113 simpleRawDeviceService = std::make_unique<SimpleRawDeviceService>(nullptr , spec);
11051114 serviceRef.registerService (ServiceRegistryHelpers::handleForService<RawDeviceService>(simpleRawDeviceService.get ()));
11061115
11071116 deviceState = std::make_unique<DeviceState>();
1108- deviceState->loop = loop ;
1117+ deviceState->loop = uv_loop_new () ;
11091118 deviceState->tracingFlags = DeviceStateHelpers::parseTracingFlags (r.fConfig .GetPropertyAsString (" dpl-tracing-flags" ));
11101119 serviceRef.registerService (ServiceRegistryHelpers::handleForService<DeviceState>(deviceState.get ()));
11111120
@@ -1962,10 +1971,15 @@ int runStateMachine(DataProcessorSpecs const& workflow,
19621971 if (driverControl.defaultStopped ) {
19631972 kill (getpid (), SIGSTOP);
19641973 }
1974+ // We are in the child here, the frameworkId must be set.
1975+ assert (!frameworkId.empty ());
19651976 for (size_t di = 0 ; di < runningWorkflow.devices .size (); di++) {
19661977 RunningDeviceRef ref{di};
19671978 if (runningWorkflow.devices [di].id == frameworkId) {
1968- return doChild (driverInfo.argc , driverInfo.argv ,
1979+ auto &execution = deviceExecutions[ref.index ];
1980+ // Last pointer is nullptr
1981+ assert (execution.args .data ()[execution.args .size () -1 ] == nullptr );
1982+ return doChild (execution.args .size ()-1 , execution.args .data (),
19691983 serviceRegistry,
19701984 runningWorkflow, ref,
19711985 driverConfig,
0 commit comments