cmake: running with no stdin causes libuv assertion failure
Tested on cmake version 3.14.3 (Fedora 30 or Debian Buster)
cmake called from C system or popen function raises an error about uv__close. Same code to call cmake works with older cmake version.
-- Build files have been written to: /tmp/module_skeleton/src
cmake: src/unix/core.c:532: uv__close: Assertion `fd > STDERR_FILENO' failed.
make: *** [Makefile:176: cmake_check_build_system] Abandon (core dump créé)
Here way to call cmake:
static std::wstring
SystemCommandAttachedW_others(const std::wstring& command, int& ierr)
{
#define BUFFER_POPEN 4096
std::string utf8commmand = wstring_to_utf8(command);
std::wstring result;
if (!utf8commmand.empty() && utf8commmand[0] != '\"' && utf8commmand.find(" ") != std::string::npos)
{
utf8commmand = "\"" + utf8commmand + "\"";
}
int stdinBackup = dup(STDIN_FILENO);
if (stdinBackup == -1) {
Error(_W("Cannot duplicate stdin (1)."));
}
close(STDIN_FILENO);
std::string commandwithredirection = utf8commmand + " 2>&1";
FILE* pPipe = popen(commandwithredirection.c_str(), "r");
if (pPipe == nullptr) {
Error(_W("Cannot call unix command."));
} else {
char psBuffer[BUFFER_POPEN];
if (feof(pPipe) != 0) {
ierr = pclose(pPipe);
pPipe = nullptr;
} else {
while (fgets(psBuffer, BUFFER_POPEN, pPipe) != nullptr) {
result.append(utf8_to_wstring(psBuffer));
}
ierr = pclose(pPipe);
}
}
fflush(NULL);
ierr = WEXITSTATUS(ierr);
if (dup2(stdinBackup, STDIN_FILENO) == -1) {
Error(_W("Cannot restore stdin."));
}
return result;
}