Skip to content

Commit c08b236

Browse files
Dees-Troyjcadduono
authored andcommitted
Fix compressed backups with split archives
Change-Id: I526d4e6a009c40c7fc7803553ba0c70701fbfb77
1 parent bedb920 commit c08b236

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

twrpTar.cpp

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ twrpTar::twrpTar(void) {
6969
Total_Backup_Size = 0;
7070
Archive_Current_Size = 0;
7171
include_root_dir = true;
72+
input_fd = -1;
73+
output_fd = -1;
7274
}
7375

7476
twrpTar::~twrpTar(void) {
@@ -915,10 +917,12 @@ int twrpTar::createTar() {
915917
// pigz Child
916918
close(pipes[1]);
917919
close(pipes[2]);
918-
close(0);
919-
dup2(pipes[0], 0);
920-
close(1);
921-
dup2(pipes[3], 1);
920+
int stdinfd = fileno(stdin);
921+
int stdoutfd = fileno(stdout);
922+
close(stdinfd);
923+
dup2(pipes[0], stdinfd);
924+
close(stdoutfd);
925+
dup2(pipes[3], stdoutfd);
922926
if (execlp("pigz", "pigz", "-", NULL) < 0) {
923927
LOGINFO("execlp pigz ERROR!\n");
924928
gui_err("backup_error=Error creating backup.");
@@ -943,10 +947,12 @@ int twrpTar::createTar() {
943947
close(pipes[0]);
944948
close(pipes[1]);
945949
close(pipes[3]);
946-
close(0);
947-
dup2(pipes[2], 0);
948-
close(1);
949-
dup2(output_fd, 1);
950+
int stdinfd = fileno(stdin);
951+
int stdoutfd = fileno(stdout);
952+
close(stdinfd);
953+
dup2(pipes[2], stdinfd);
954+
close(stdoutfd);
955+
dup2(output_fd, stdoutfd);
950956
if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) {
951957
LOGINFO("execlp openaes ERROR!\n");
952958
gui_err("backup_error=Error creating backup.");
@@ -1007,8 +1013,8 @@ int twrpTar::createTar() {
10071013
} else if (pigz_pid == 0) {
10081014
// Child
10091015
close(pigzfd[1]); // close unused output pipe
1010-
dup2(pigzfd[0], 0); // remap stdin
1011-
dup2(output_fd, 1); // remap stdout to output file
1016+
dup2(pigzfd[0], fileno(stdin)); // remap stdin
1017+
dup2(output_fd, fileno(stdout)); // remap stdout to output file
10121018
if (execlp("pigz", "pigz", "-", NULL) < 0) {
10131019
LOGINFO("execlp pigz ERROR!\n");
10141020
gui_err("backup_error=Error creating backup.");
@@ -1057,8 +1063,8 @@ int twrpTar::createTar() {
10571063
} else if (oaes_pid == 0) {
10581064
// Child
10591065
close(oaesfd[1]); // close unused
1060-
dup2(oaesfd[0], 0); // remap stdin
1061-
dup2(output_fd, 1); // remap stdout to output file
1066+
dup2(oaesfd[0], fileno(stdin)); // remap stdin
1067+
dup2(output_fd, fileno(stdout)); // remap stdout to output file
10621068
if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) {
10631069
LOGINFO("execlp openaes ERROR!\n");
10641070
gui_err("backup_error=Error creating backup.");
@@ -1147,10 +1153,12 @@ int twrpTar::openTar() {
11471153
close(pipes[0]); // Close pipes that are not used by this child
11481154
close(pipes[2]);
11491155
close(pipes[3]);
1150-
close(0);
1151-
dup2(input_fd, 0);
1152-
close(1);
1153-
dup2(pipes[1], 1);
1156+
int stdinfd = fileno(stdin);
1157+
int stdoutfd = fileno(stdout);
1158+
close(stdinfd);
1159+
dup2(input_fd, stdinfd);
1160+
close(stdoutfd);
1161+
dup2(pipes[1], stdoutfd);
11541162
if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) {
11551163
LOGINFO("execlp openaes ERROR!\n");
11561164
gui_err("restore_error=Error during restore process.");
@@ -1173,10 +1181,12 @@ int twrpTar::openTar() {
11731181
// pigz Child
11741182
close(pipes[1]); // Close pipes not used by this child
11751183
close(pipes[2]);
1176-
close(0);
1177-
dup2(pipes[0], 0);
1178-
close(1);
1179-
dup2(pipes[3], 1);
1184+
int stdinfd = fileno(stdin);
1185+
int stdoutfd = fileno(stdout);
1186+
close(stdinfd);
1187+
dup2(pipes[0], stdinfd);
1188+
close(stdoutfd);
1189+
dup2(pipes[3], stdoutfd);
11801190
if (execlp("pigz", "pigz", "-d", "-c", NULL) < 0) {
11811191
LOGINFO("execlp pigz ERROR!\n");
11821192
gui_err("restore_error=Error during restore process.");
@@ -1226,9 +1236,10 @@ int twrpTar::openTar() {
12261236
} else if (oaes_pid == 0) {
12271237
// Child
12281238
close(oaesfd[0]); // Close unused pipe
1229-
close(0); // close stdin
1230-
dup2(oaesfd[1], 1); // remap stdout
1231-
dup2(input_fd, 0); // remap input fd to stdin
1239+
int stdinfd = fileno(stdin);
1240+
close(stdinfd); // close stdin
1241+
dup2(oaesfd[1], fileno(stdout)); // remap stdout
1242+
dup2(input_fd, stdinfd); // remap input fd to stdin
12321243
if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) {
12331244
LOGINFO("execlp openaes ERROR!\n");
12341245
gui_err("restore_error=Error during restore process.");
@@ -1281,8 +1292,8 @@ int twrpTar::openTar() {
12811292
} else if (pigz_pid == 0) {
12821293
// Child
12831294
close(pigzfd[0]);
1284-
dup2(pigzfd[1], 1); // remap stdout
1285-
dup2(input_fd, 0); // remap input fd to stdin
1295+
dup2(pigzfd[1], fileno(stdout)); // remap stdout
1296+
dup2(input_fd, fileno(stdin)); // remap input fd to stdin
12861297
if (execlp("pigz", "pigz", "-d", "-c", NULL) < 0) {
12871298
close(pigzfd[1]);
12881299
close(input_fd);
@@ -1396,8 +1407,10 @@ int twrpTar::closeTar() {
13961407
if (!twadbbu::Write_TWEOF())
13971408
return -1;
13981409
}
1399-
close(input_fd);
1400-
close(output_fd);
1410+
if (input_fd >= 0)
1411+
close(input_fd);
1412+
if (output_fd >= 0)
1413+
close(output_fd);
14011414
return 0;
14021415
}
14031416

0 commit comments

Comments
 (0)