Le lancement de processus de Studio host (CoreProcess) devient sequa::platform::ChildProcess dans platform/process, pour être partagé par Studio host et le Core (qui lancera le rendu, ADR 0009). Nouvelle option kill_with_parent : l'enfant meurt avec le parent, même brutalement (job object KILL_ON_JOB_CLOSE sous Windows, fork + PR_SET_PDEATHSIG sous Linux, ignorée sous macOS). Les tests de copie fantôme restent dans studio/host/supervisor (test_shadow.cpp) avec l'enfant de test de platform/process.
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
// SPDX-License-Identifier: MPL-2.0
|
|
//
|
|
// Processus enfant des tests de la brique processus. Arguments traités dans l'ordre :
|
|
// --out <texte> ligne sur stdout --err <texte> ligne sur stderr
|
|
// --echo-rest recopie chaque argument suivant entre crochets, un par ligne
|
|
// --sleep <ms> attend --exit <code> sort avec ce code
|
|
// Les arguments sont relus en UTF-16 sous Windows et écrits en UTF-8 : on vérifie ce que
|
|
// le lanceur a réellement transmis, pas la conversion de la page de code locale.
|
|
|
|
#include <chrono>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#if defined(_WIN32)
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
#include <Windows.h>
|
|
#include <shellapi.h>
|
|
#endif
|
|
|
|
namespace {
|
|
|
|
std::vector<std::string> arguments(int argc, char** argv)
|
|
{
|
|
std::vector<std::string> result;
|
|
#if defined(_WIN32)
|
|
(void)argc;
|
|
(void)argv;
|
|
int count = 0;
|
|
LPWSTR* wide = CommandLineToArgvW(GetCommandLineW(), &count);
|
|
for (int i = 1; i < count; ++i) {
|
|
const int size = WideCharToMultiByte(CP_UTF8, 0, wide[i], -1, nullptr, 0, nullptr, nullptr);
|
|
std::string text(static_cast<std::size_t>(size > 0 ? size - 1 : 0), '\0');
|
|
WideCharToMultiByte(CP_UTF8, 0, wide[i], -1, text.data(), size, nullptr, nullptr);
|
|
result.push_back(std::move(text));
|
|
}
|
|
LocalFree(wide);
|
|
#else
|
|
for (int i = 1; i < argc; ++i) {
|
|
result.emplace_back(argv[i]);
|
|
}
|
|
#endif
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
const std::vector<std::string> args = arguments(argc, argv);
|
|
for (std::size_t i = 0; i < args.size(); ++i) {
|
|
const std::string& arg = args[i];
|
|
const bool has_value = i + 1 < args.size();
|
|
if (arg == "--out" && has_value) {
|
|
std::printf("%s\n", args[++i].c_str());
|
|
} else if (arg == "--err" && has_value) {
|
|
std::fprintf(stderr, "%s\n", args[++i].c_str());
|
|
} else if (arg == "--echo-rest") {
|
|
for (++i; i < args.size(); ++i) {
|
|
std::printf("[%s]\n", args[i].c_str());
|
|
}
|
|
} else if (arg == "--sleep" && has_value) {
|
|
std::fflush(stdout);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(std::atoi(args[++i].c_str())));
|
|
} else if (arg == "--exit" && has_value) {
|
|
std::fflush(stdout);
|
|
return std::atoi(args[++i].c_str());
|
|
}
|
|
}
|
|
return 0;
|
|
}
|