diff options
author | Ethan Yonker <dees_troy@teamw.in> | 2016-09-12 23:07:19 +0200 |
---|---|---|
committer | James Christopher Adduono <jc@adduono.com> | 2016-09-23 21:42:31 +0200 |
commit | c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39 (patch) | |
tree | dfb6e558b14e16652f6efb061c7d9e2fd83f6fb8 /twrpTar.cpp | |
parent | Fix restore of subpartitions (diff) | |
download | android_bootable_recovery-c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39.tar android_bootable_recovery-c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39.tar.gz android_bootable_recovery-c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39.tar.bz2 android_bootable_recovery-c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39.tar.lz android_bootable_recovery-c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39.tar.xz android_bootable_recovery-c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39.tar.zst android_bootable_recovery-c08b236bfc9ecfa1cf61ccb2566dc744cd3dda39.zip |
Diffstat (limited to '')
-rw-r--r-- | twrpTar.cpp | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/twrpTar.cpp b/twrpTar.cpp index dcbb28202..b56623798 100644 --- a/twrpTar.cpp +++ b/twrpTar.cpp @@ -69,6 +69,8 @@ twrpTar::twrpTar(void) { Total_Backup_Size = 0; Archive_Current_Size = 0; include_root_dir = true; + input_fd = -1; + output_fd = -1; } twrpTar::~twrpTar(void) { @@ -915,10 +917,12 @@ int twrpTar::createTar() { // pigz Child close(pipes[1]); close(pipes[2]); - close(0); - dup2(pipes[0], 0); - close(1); - dup2(pipes[3], 1); + int stdinfd = fileno(stdin); + int stdoutfd = fileno(stdout); + close(stdinfd); + dup2(pipes[0], stdinfd); + close(stdoutfd); + dup2(pipes[3], stdoutfd); if (execlp("pigz", "pigz", "-", NULL) < 0) { LOGINFO("execlp pigz ERROR!\n"); gui_err("backup_error=Error creating backup."); @@ -943,10 +947,12 @@ int twrpTar::createTar() { close(pipes[0]); close(pipes[1]); close(pipes[3]); - close(0); - dup2(pipes[2], 0); - close(1); - dup2(output_fd, 1); + int stdinfd = fileno(stdin); + int stdoutfd = fileno(stdout); + close(stdinfd); + dup2(pipes[2], stdinfd); + close(stdoutfd); + dup2(output_fd, stdoutfd); if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) { LOGINFO("execlp openaes ERROR!\n"); gui_err("backup_error=Error creating backup."); @@ -1007,8 +1013,8 @@ int twrpTar::createTar() { } else if (pigz_pid == 0) { // Child close(pigzfd[1]); // close unused output pipe - dup2(pigzfd[0], 0); // remap stdin - dup2(output_fd, 1); // remap stdout to output file + dup2(pigzfd[0], fileno(stdin)); // remap stdin + dup2(output_fd, fileno(stdout)); // remap stdout to output file if (execlp("pigz", "pigz", "-", NULL) < 0) { LOGINFO("execlp pigz ERROR!\n"); gui_err("backup_error=Error creating backup."); @@ -1057,8 +1063,8 @@ int twrpTar::createTar() { } else if (oaes_pid == 0) { // Child close(oaesfd[1]); // close unused - dup2(oaesfd[0], 0); // remap stdin - dup2(output_fd, 1); // remap stdout to output file + dup2(oaesfd[0], fileno(stdin)); // remap stdin + dup2(output_fd, fileno(stdout)); // remap stdout to output file if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) { LOGINFO("execlp openaes ERROR!\n"); gui_err("backup_error=Error creating backup."); @@ -1147,10 +1153,12 @@ int twrpTar::openTar() { close(pipes[0]); // Close pipes that are not used by this child close(pipes[2]); close(pipes[3]); - close(0); - dup2(input_fd, 0); - close(1); - dup2(pipes[1], 1); + int stdinfd = fileno(stdin); + int stdoutfd = fileno(stdout); + close(stdinfd); + dup2(input_fd, stdinfd); + close(stdoutfd); + dup2(pipes[1], stdoutfd); if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) { LOGINFO("execlp openaes ERROR!\n"); gui_err("restore_error=Error during restore process."); @@ -1173,10 +1181,12 @@ int twrpTar::openTar() { // pigz Child close(pipes[1]); // Close pipes not used by this child close(pipes[2]); - close(0); - dup2(pipes[0], 0); - close(1); - dup2(pipes[3], 1); + int stdinfd = fileno(stdin); + int stdoutfd = fileno(stdout); + close(stdinfd); + dup2(pipes[0], stdinfd); + close(stdoutfd); + dup2(pipes[3], stdoutfd); if (execlp("pigz", "pigz", "-d", "-c", NULL) < 0) { LOGINFO("execlp pigz ERROR!\n"); gui_err("restore_error=Error during restore process."); @@ -1226,9 +1236,10 @@ int twrpTar::openTar() { } else if (oaes_pid == 0) { // Child close(oaesfd[0]); // Close unused pipe - close(0); // close stdin - dup2(oaesfd[1], 1); // remap stdout - dup2(input_fd, 0); // remap input fd to stdin + int stdinfd = fileno(stdin); + close(stdinfd); // close stdin + dup2(oaesfd[1], fileno(stdout)); // remap stdout + dup2(input_fd, stdinfd); // remap input fd to stdin if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) { LOGINFO("execlp openaes ERROR!\n"); gui_err("restore_error=Error during restore process."); @@ -1281,8 +1292,8 @@ int twrpTar::openTar() { } else if (pigz_pid == 0) { // Child close(pigzfd[0]); - dup2(pigzfd[1], 1); // remap stdout - dup2(input_fd, 0); // remap input fd to stdin + dup2(pigzfd[1], fileno(stdout)); // remap stdout + dup2(input_fd, fileno(stdin)); // remap input fd to stdin if (execlp("pigz", "pigz", "-d", "-c", NULL) < 0) { close(pigzfd[1]); close(input_fd); @@ -1396,8 +1407,10 @@ int twrpTar::closeTar() { if (!twadbbu::Write_TWEOF()) return -1; } - close(input_fd); - close(output_fd); + if (input_fd >= 0) + close(input_fd); + if (output_fd >= 0) + close(output_fd); return 0; } |