Skip to content

Commit cc41c89

Browse files
committed
Everything but the signals
1 parent df381a6 commit cc41c89

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

Framework/Core/include/Framework/DeviceExecution.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,25 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
#ifndef FRAMEWORK_DEVICEEXECUTION_H
12-
#define FRAMEWORK_DEVICEEXECUTION_H
11+
#ifndef O2_FRAMEWORK_DEVICEEXECUTION_H_
12+
#define O2_FRAMEWORK_DEVICEEXECUTION_H_
1313

1414
#include <vector>
1515

16-
namespace o2
17-
{
18-
namespace framework
16+
namespace o2::framework
1917
{
2018

2119
/// This represent one single execution of a Device. It's meant to hold
2220
/// information which can change between one execution of a Device and the
2321
/// other, e.g. the executable name or the arguments it is started with.
2422
struct DeviceExecution {
23+
std::string plugin;
2524
/// The options passed to a given device
2625
std::vector<char*> args;
2726
/// The environment to be passed to a given device
2827
std::vector<char*> environ;
2928
};
3029

31-
} // namespace framework
32-
} // namespace o2
33-
#endif
30+
} // namespace o2::framework
31+
32+
#endif // O2_FRAMEWORK_DEVICEEXECUTION_H_

Framework/Core/src/DeviceSpecHelpers.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,8 @@ void DeviceSpecHelpers::prepareArguments(bool defaultQuiet, bool defaultStopped,
17111711
}
17121712
O2_SIGNPOST_END(device_spec_helpers, poid, "prepareArguments", "The following options are being forwarded to %{public}s: %{public}s",
17131713
spec.id.c_str(), str.str().c_str());
1714+
// Copy the plugin over from the DataProcessingInfo
1715+
execution.plugin = pi->plugin;
17141716
}
17151717
}
17161718

Framework/Core/src/runDataProcessing.cxx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)