summaryrefslogtreecommitdiffstats
path: root/twrpTar.cpp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2016-09-12 23:07:19 +0200
committerEthan Yonker <dees_troy@teamw.in>2016-09-12 23:07:19 +0200
commitea2fcf0179c75f7f9aeea19bbdea7571f7a0425f (patch)
treeafca33d7dd46330af4d04439e5c05037b0155821 /twrpTar.cpp
parentFix restore of subpartitions (diff)
downloadandroid_bootable_recovery-ea2fcf0179c75f7f9aeea19bbdea7571f7a0425f.tar
android_bootable_recovery-ea2fcf0179c75f7f9aeea19bbdea7571f7a0425f.tar.gz
android_bootable_recovery-ea2fcf0179c75f7f9aeea19bbdea7571f7a0425f.tar.bz2
android_bootable_recovery-ea2fcf0179c75f7f9aeea19bbdea7571f7a0425f.tar.lz
android_bootable_recovery-ea2fcf0179c75f7f9aeea19bbdea7571f7a0425f.tar.xz
android_bootable_recovery-ea2fcf0179c75f7f9aeea19bbdea7571f7a0425f.tar.zst
android_bootable_recovery-ea2fcf0179c75f7f9aeea19bbdea7571f7a0425f.zip
Diffstat (limited to '')
-rw-r--r--twrpTar.cpp67
1 files changed, 40 insertions, 27 deletions
diff --git a/twrpTar.cpp b/twrpTar.cpp
index d192f2cc5..c18b0622b 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -69,6 +69,8 @@ twrpTar::twrpTar(void) {
tar_type.openfunc = open;
tar_type.closefunc = close;
tar_type.readfunc = read;
+ 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;
}