@@ -69,6 +69,8 @@ twrpTar::twrpTar(void) {
69
69
Total_Backup_Size = 0 ;
70
70
Archive_Current_Size = 0 ;
71
71
include_root_dir = true ;
72
+ input_fd = -1 ;
73
+ output_fd = -1 ;
72
74
}
73
75
74
76
twrpTar::~twrpTar (void ) {
@@ -915,10 +917,12 @@ int twrpTar::createTar() {
915
917
// pigz Child
916
918
close (pipes[1 ]);
917
919
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);
922
926
if (execlp (" pigz" , " pigz" , " -" , NULL ) < 0 ) {
923
927
LOGINFO (" execlp pigz ERROR!\n " );
924
928
gui_err (" backup_error=Error creating backup." );
@@ -943,10 +947,12 @@ int twrpTar::createTar() {
943
947
close (pipes[0 ]);
944
948
close (pipes[1 ]);
945
949
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);
950
956
if (execlp (" openaes" , " openaes" , " enc" , " --key" , password.c_str (), NULL ) < 0 ) {
951
957
LOGINFO (" execlp openaes ERROR!\n " );
952
958
gui_err (" backup_error=Error creating backup." );
@@ -1007,8 +1013,8 @@ int twrpTar::createTar() {
1007
1013
} else if (pigz_pid == 0 ) {
1008
1014
// Child
1009
1015
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
1012
1018
if (execlp (" pigz" , " pigz" , " -" , NULL ) < 0 ) {
1013
1019
LOGINFO (" execlp pigz ERROR!\n " );
1014
1020
gui_err (" backup_error=Error creating backup." );
@@ -1057,8 +1063,8 @@ int twrpTar::createTar() {
1057
1063
} else if (oaes_pid == 0 ) {
1058
1064
// Child
1059
1065
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
1062
1068
if (execlp (" openaes" , " openaes" , " enc" , " --key" , password.c_str (), NULL ) < 0 ) {
1063
1069
LOGINFO (" execlp openaes ERROR!\n " );
1064
1070
gui_err (" backup_error=Error creating backup." );
@@ -1147,10 +1153,12 @@ int twrpTar::openTar() {
1147
1153
close (pipes[0 ]); // Close pipes that are not used by this child
1148
1154
close (pipes[2 ]);
1149
1155
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);
1154
1162
if (execlp (" openaes" , " openaes" , " dec" , " --key" , password.c_str (), NULL ) < 0 ) {
1155
1163
LOGINFO (" execlp openaes ERROR!\n " );
1156
1164
gui_err (" restore_error=Error during restore process." );
@@ -1173,10 +1181,12 @@ int twrpTar::openTar() {
1173
1181
// pigz Child
1174
1182
close (pipes[1 ]); // Close pipes not used by this child
1175
1183
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);
1180
1190
if (execlp (" pigz" , " pigz" , " -d" , " -c" , NULL ) < 0 ) {
1181
1191
LOGINFO (" execlp pigz ERROR!\n " );
1182
1192
gui_err (" restore_error=Error during restore process." );
@@ -1226,9 +1236,10 @@ int twrpTar::openTar() {
1226
1236
} else if (oaes_pid == 0 ) {
1227
1237
// Child
1228
1238
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
1232
1243
if (execlp (" openaes" , " openaes" , " dec" , " --key" , password.c_str (), NULL ) < 0 ) {
1233
1244
LOGINFO (" execlp openaes ERROR!\n " );
1234
1245
gui_err (" restore_error=Error during restore process." );
@@ -1281,8 +1292,8 @@ int twrpTar::openTar() {
1281
1292
} else if (pigz_pid == 0 ) {
1282
1293
// Child
1283
1294
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
1286
1297
if (execlp (" pigz" , " pigz" , " -d" , " -c" , NULL ) < 0 ) {
1287
1298
close (pigzfd[1 ]);
1288
1299
close (input_fd);
@@ -1396,8 +1407,10 @@ int twrpTar::closeTar() {
1396
1407
if (!twadbbu::Write_TWEOF ())
1397
1408
return -1 ;
1398
1409
}
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);
1401
1414
return 0 ;
1402
1415
}
1403
1416
0 commit comments