1
0
mirror of synced 2024-09-24 11:38:26 +02:00

impr: Use execvp() instead of system() on Linux (#1170)

This PR it just a hack to fix #1160 , it doesn't solve the underlying
problem.

It fixes the problem because by using execvp() directly, it avoids the
call to `sh` done with `system()`, which has a bug on Ubuntu 22.04 which
makes it i,compatibles with the glibc inside the AppImage.
It doesn't fix the underlying problem because the programs we call
themselves still link to the AppImage's libraries instead of the system
ones.
This commit is contained in:
iTrooz 2023-07-05 20:50:46 +02:00 committed by GitHub
parent e3ae169833
commit ac2a609d0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 30 deletions

View File

@ -21,6 +21,7 @@ set(LIBIMHEX_SOURCES
source/data_processor/node.cpp
source/helpers/utils.cpp
source/helpers/utils_linux.cpp
source/helpers/fs.cpp
source/helpers/magic.cpp
source/helpers/crypto.cpp

View File

@ -0,0 +1,9 @@
#pragma once
#if defined(OS_LINUX)
namespace hex {
void executeCmd(const std::vector<std::string> &argsVector);
}
#endif

View File

@ -4,6 +4,7 @@
#include <hex/api/project_file_manager.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/utils_linux.hpp>
#include <xdg.hpp>
@ -43,9 +44,7 @@ namespace hex::fs {
hex::format("open {}", wolv::util::toUTF8String(filePath)).c_str()
));
#elif defined(OS_LINUX)
hex::unused(system(
hex::format("xdg-open {}", wolv::util::toUTF8String(filePath)).c_str()
));
executeCmd({"xdg-open", wolv::util::toUTF8String(filePath)});
#endif
}
@ -62,9 +61,7 @@ namespace hex::fs {
hex::format("open {}", wolv::util::toUTF8String(dirPath)).c_str()
));
#elif defined(OS_LINUX)
hex::unused(system(
hex::format("xdg-open {}", wolv::util::toUTF8String(dirPath)).c_str()
));
executeCmd({"xdg-open", wolv::util::toUTF8String(dirPath)});
#endif
}
@ -87,9 +84,7 @@ namespace hex::fs {
#elif defined(OS_LINUX)
// fallback to only opening the folder for now
// TODO actually select the file
hex::unused(system(
hex::format("xdg-open {}", wolv::util::toUTF8String(selectedFilePath.parent_path())).c_str()
));
executeCmd({"xdg-open", wolv::util::toUTF8String(selectedFilePath.parent_path())});
#endif
}

View File

@ -8,6 +8,7 @@
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/crypto.hpp>
#include <hex/helpers/utils_linux.hpp>
#include <imgui.h>
#include <imgui_internal.h>
@ -313,14 +314,12 @@ namespace hex {
void runCommand(const std::string &command) {
#if defined(OS_WINDOWS)
auto result = system(hex::format("start {0}", command).c_str());
hex::unused(system(hex::format("start {0}", command).c_str()));
#elif defined(OS_MACOS)
auto result = system(hex::format("open {0}", command).c_str());
hex::unused(system(hex::format("open {0}", command).c_str()));
#elif defined(OS_LINUX)
auto result = system(hex::format("xdg-open {0}", command).c_str());
executeCmd({"xdg-open", command});
#endif
hex::unused(result);
}
void openWebpage(std::string url) {
@ -332,8 +331,7 @@ namespace hex {
#elif defined(OS_MACOS)
openWebpageMacos(url.c_str());
#elif defined(OS_LINUX)
auto result = system(hex::format("xdg-open {0}", url).c_str());
hex::unused(result);
executeCmd({"xdg-open", url});
#else
#warning "Unknown OS, can't open webpages"
#endif

View File

@ -0,0 +1,27 @@
#if defined(OS_LINUX)
#include<hex/helpers/logger.hpp>
#include<vector>
#include<string>
#include<unistd.h>
namespace hex {
void executeCmd(const std::vector<std::string> &argsVector) {
std::vector<char*> cArgsVector;
for (const auto &str : argsVector) {
cArgsVector.push_back(const_cast<char*>(str.c_str()));
}
cArgsVector.push_back(nullptr);
if (fork() == 0) {
execvp(cArgsVector[0], &cArgsVector[0]);
log::error("execvp() failed: {}", strerror(errno));
exit(EXIT_FAILURE);
}
}
}
#endif

View File

@ -7,6 +7,7 @@
#include <hex/api/event.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/utils_linux.hpp>
#include <hex/helpers/logger.hpp>
#include <wolv/utils/core.hpp>
@ -37,20 +38,6 @@ namespace hex {
return false;
}
void executeCmd(const std::vector<std::string> &argsVector) {
std::vector<char*> cArgsVector;
for (const auto &str : argsVector) {
cArgsVector.push_back(const_cast<char*>(str.c_str()));
}
cArgsVector.push_back(nullptr);
if (fork() == 0) {
execvp(cArgsVector[0], &cArgsVector[0]);
log::error("execvp() failed: {}", strerror(errno));
exit(EXIT_FAILURE);
}
}
void nativeErrorMessage(const std::string &message) {
log::fatal(message);
if (isFileInPath("zenity")) {