Merge "fastboot: pass environment variables to exec_e2fs_cmd"
This commit is contained in:
commit
7ed1a15efe
2 changed files with 22 additions and 13 deletions
|
|
@ -39,7 +39,7 @@ LOCAL_MODULE := fastboot
|
||||||
LOCAL_MODULE_TAGS := debug
|
LOCAL_MODULE_TAGS := debug
|
||||||
LOCAL_MODULE_HOST_OS := darwin linux windows
|
LOCAL_MODULE_HOST_OS := darwin linux windows
|
||||||
LOCAL_CFLAGS += -Wall -Wextra -Werror -Wunreachable-code
|
LOCAL_CFLAGS += -Wall -Wextra -Werror -Wunreachable-code
|
||||||
LOCAL_REQUIRED_MODULES := mke2fs e2fsdroid make_f2fs
|
LOCAL_REQUIRED_MODULES := mke2fs e2fsdroid mke2fs.conf make_f2fs
|
||||||
|
|
||||||
LOCAL_SRC_FILES_linux := usb_linux.cpp
|
LOCAL_SRC_FILES_linux := usb_linux.cpp
|
||||||
LOCAL_STATIC_LIBRARIES_linux := libselinux
|
LOCAL_STATIC_LIBRARIES_linux := libselinux
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,12 @@
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
|
|
||||||
|
using android::base::GetExecutableDirectory;
|
||||||
using android::base::StringPrintf;
|
using android::base::StringPrintf;
|
||||||
using android::base::unique_fd;
|
using android::base::unique_fd;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
static int exec_e2fs_cmd(const char* /*path*/, char* const argv[]) {
|
static int exec_e2fs_cmd(const char* /*path*/, const char** argv, const char** envp) {
|
||||||
std::string cmd;
|
std::string cmd;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (argv[i] != nullptr) {
|
while (argv[i] != nullptr) {
|
||||||
|
|
@ -44,7 +45,13 @@ static int exec_e2fs_cmd(const char* /*path*/, char* const argv[]) {
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
ZeroMemory(&pi, sizeof(pi));
|
ZeroMemory(&pi, sizeof(pi));
|
||||||
|
|
||||||
SetEnvironmentVariableA("MKE2FS_CONFIG", "");
|
std::string env_str;
|
||||||
|
if (envp != nullptr) {
|
||||||
|
while (*envp != nullptr) {
|
||||||
|
env_str += std::string(*envp) + std::string("\0", 1);
|
||||||
|
envp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!CreateProcessA(nullptr, // No module name (use command line)
|
if (!CreateProcessA(nullptr, // No module name (use command line)
|
||||||
const_cast<char*>(cmd.c_str()), // Command line
|
const_cast<char*>(cmd.c_str()), // Command line
|
||||||
|
|
@ -52,10 +59,10 @@ static int exec_e2fs_cmd(const char* /*path*/, char* const argv[]) {
|
||||||
nullptr, // Thread handle not inheritable
|
nullptr, // Thread handle not inheritable
|
||||||
FALSE, // Set handle inheritance to FALSE
|
FALSE, // Set handle inheritance to FALSE
|
||||||
0, // No creation flags
|
0, // No creation flags
|
||||||
nullptr, // Use parent's environment block
|
env_str.empty() ? nullptr : LPSTR(env_str.c_str()),
|
||||||
nullptr, // Use parent's starting directory
|
nullptr, // Use parent's starting directory
|
||||||
&si, // Pointer to STARTUPINFO structure
|
&si, // Pointer to STARTUPINFO structure
|
||||||
&pi) // Pointer to PROCESS_INFORMATION structure
|
&pi) // Pointer to PROCESS_INFORMATION structure
|
||||||
) {
|
) {
|
||||||
fprintf(stderr, "CreateProcess failed: %s\n",
|
fprintf(stderr, "CreateProcess failed: %s\n",
|
||||||
android::base::SystemErrorCodeToString(GetLastError()).c_str());
|
android::base::SystemErrorCodeToString(GetLastError()).c_str());
|
||||||
|
|
@ -72,12 +79,11 @@ static int exec_e2fs_cmd(const char* /*path*/, char* const argv[]) {
|
||||||
return exit_code != 0;
|
return exit_code != 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int exec_e2fs_cmd(const char* path, char* const argv[]) {
|
static int exec_e2fs_cmd(const char* path, const char** argv, const char** envp) {
|
||||||
int status;
|
int status;
|
||||||
pid_t child;
|
pid_t child;
|
||||||
if ((child = fork()) == 0) {
|
if ((child = fork()) == 0) {
|
||||||
setenv("MKE2FS_CONFIG", "", 1);
|
execvpe(path, const_cast<char**>(argv), const_cast<char**>(envp));
|
||||||
execvp(path, argv);
|
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (child < 0) {
|
if (child < 0) {
|
||||||
|
|
@ -131,7 +137,10 @@ static int generate_ext4_image(const char* fileName, long long partSize,
|
||||||
mke2fs_args.push_back(size_str.c_str());
|
mke2fs_args.push_back(size_str.c_str());
|
||||||
mke2fs_args.push_back(nullptr);
|
mke2fs_args.push_back(nullptr);
|
||||||
|
|
||||||
int ret = exec_e2fs_cmd(mke2fs_args[0], const_cast<char**>(mke2fs_args.data()));
|
const std::string mke2fs_env = "MKE2FS_CONFIG=" + GetExecutableDirectory() + "/mke2fs.conf";
|
||||||
|
std::vector<const char*> mke2fs_envp = {mke2fs_env.c_str(), nullptr};
|
||||||
|
|
||||||
|
int ret = exec_e2fs_cmd(mke2fs_args[0], mke2fs_args.data(), mke2fs_envp.data());
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "mke2fs failed: %d\n", ret);
|
fprintf(stderr, "mke2fs failed: %d\n", ret);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -145,7 +154,7 @@ static int generate_ext4_image(const char* fileName, long long partSize,
|
||||||
std::vector<const char*> e2fsdroid_args = {e2fsdroid_path.c_str(), "-f", initial_dir.c_str(),
|
std::vector<const char*> e2fsdroid_args = {e2fsdroid_path.c_str(), "-f", initial_dir.c_str(),
|
||||||
fileName, nullptr};
|
fileName, nullptr};
|
||||||
|
|
||||||
ret = exec_e2fs_cmd(e2fsdroid_args[0], const_cast<char**>(e2fsdroid_args.data()));
|
ret = exec_e2fs_cmd(e2fsdroid_args[0], e2fsdroid_args.data(), nullptr);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "e2fsdroid failed: %d\n", ret);
|
fprintf(stderr, "e2fsdroid failed: %d\n", ret);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -173,7 +182,7 @@ static int generate_f2fs_image(const char* fileName, long long partSize, const s
|
||||||
mkf2fs_args.push_back(fileName);
|
mkf2fs_args.push_back(fileName);
|
||||||
mkf2fs_args.push_back(nullptr);
|
mkf2fs_args.push_back(nullptr);
|
||||||
|
|
||||||
int ret = exec_e2fs_cmd(mkf2fs_args[0], const_cast<char**>(mkf2fs_args.data()));
|
int ret = exec_e2fs_cmd(mkf2fs_args[0], mkf2fs_args.data(), nullptr);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "mkf2fs failed: %d\n", ret);
|
fprintf(stderr, "mkf2fs failed: %d\n", ret);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue