summaryrefslogtreecommitdiffstats
path: root/twrpTar.cpp
diff options
context:
space:
mode:
authorbigbiff bigbiff <bigbiff@teamw.in>2013-02-18 02:18:31 +0100
committerbigbiff bigbiff <bigbiff@teamw.in>2013-02-18 02:18:31 +0100
commite6594ab9a3a89a98a06060c9790560b41eb728b1 (patch)
treedd3a9f1349c4fd0e63cc4b439b6eb4f5a31df01c /twrpTar.cpp
parentThis adds a 60 second screen timeout for TWRP. Might consider making this configurable in the future. (diff)
downloadandroid_bootable_recovery-e6594ab9a3a89a98a06060c9790560b41eb728b1.tar
android_bootable_recovery-e6594ab9a3a89a98a06060c9790560b41eb728b1.tar.gz
android_bootable_recovery-e6594ab9a3a89a98a06060c9790560b41eb728b1.tar.bz2
android_bootable_recovery-e6594ab9a3a89a98a06060c9790560b41eb728b1.tar.lz
android_bootable_recovery-e6594ab9a3a89a98a06060c9790560b41eb728b1.tar.xz
android_bootable_recovery-e6594ab9a3a89a98a06060c9790560b41eb728b1.tar.zst
android_bootable_recovery-e6594ab9a3a89a98a06060c9790560b41eb728b1.zip
Diffstat (limited to 'twrpTar.cpp')
-rw-r--r--twrpTar.cpp145
1 files changed, 117 insertions, 28 deletions
diff --git a/twrpTar.cpp b/twrpTar.cpp
index 43448672c..5d1752131 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -24,6 +24,7 @@ extern "C" {
}
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
@@ -49,51 +50,139 @@ void twrpTar::setdir(string dir) {
tardir = dir;
}
-int twrpTar::createTarGZThread() {
- pthread_t thread;
- ThreadPtr tarptr = &twrpTar::createTGZ;
- PThreadPtr p = *(PThreadPtr*)&tarptr;
- pthread_create(&thread, NULL, p, this);
- if(pthread_join(thread, NULL)) {
+int twrpTar::createTarGZFork() {
+ int status;
+ pid_t pid;
+ if ((pid = fork()) == -1) {
+ LOGI("create tar failed to fork.\n");
return -1;
}
- TWFunc::drop_caches();
+ if (pid == 0) {
+ if (createTGZ() != 0)
+ exit(-1);
+ else
+ exit(0);
+ }
+ else {
+ if ((pid = wait(&status)) == -1) {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ else {
+ if (WIFSIGNALED(status) != 0) {
+ LOGI("Child process ended with signal: %d\n", WTERMSIG(status));
+ return -1;
+ }
+ else if (WIFEXITED(status) != 0)
+ LOGI("Tar creation successful\n");
+ else {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ }
+ }
return 0;
}
-int twrpTar::createTarThread() {
- pthread_t thread;
- ThreadPtr tarptr = &twrpTar::create;
- PThreadPtr p = *(PThreadPtr*)&tarptr;
- pthread_create(&thread, NULL, p, this);
- if(pthread_join(thread, NULL)) {
+int twrpTar::createTarFork() {
+ int status;
+ pid_t pid;
+ if ((pid = fork()) == -1) {
+ LOGI("create tar failed to fork.\n");
return -1;
}
- TWFunc::drop_caches();
+ if (pid == 0) {
+ if (create() != 0)
+ exit(-1);
+ else
+ exit(0);
+ }
+ else {
+ if ((pid = wait(&status)) == -1) {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ else {
+ if (WIFSIGNALED(status) != 0) {
+ LOGI("Child process ended with signal: %d\n", WTERMSIG(status));
+ return -1;
+ }
+ else if (WIFEXITED(status) != 0)
+ LOGI("Tar creation successful\n");
+ else {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ }
+ }
return 0;
}
-int twrpTar::extractTarThread() {
- pthread_t thread;
- ThreadPtr tarptr = &twrpTar::extract;
- PThreadPtr p = *(PThreadPtr*)&tarptr;
- pthread_create(&thread, NULL, p, this);
- if(pthread_join(thread, NULL)) {
+int twrpTar::extractTarFork() {
+ int status;
+ pid_t pid;
+ if ((pid = fork()) == -1) {
+ LOGI("create tar failed to fork.\n");
return -1;
}
- TWFunc::drop_caches();
+ if (pid == 0) {
+ if (extract() != 0)
+ exit(-1);
+ else
+ exit(0);
+ }
+ else {
+ if ((pid = wait(&status)) == -1) {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ else {
+ if (WIFSIGNALED(status) != 0) {
+ LOGI("Child process ended with signal: %d\n", WTERMSIG(status));
+ return -1;
+ }
+ else if (WIFEXITED(status) != 0)
+ LOGI("Tar creation successful\n");
+ else {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ }
+ }
return 0;
}
-int twrpTar::splitArchiveThread() {
- pthread_t thread;
- ThreadPtr tarptr = &twrpTar::Split_Archive;
- PThreadPtr p = *(PThreadPtr*)&tarptr;
- pthread_create(&thread, NULL, p, this);
- if(pthread_join(thread, NULL)) {
+int twrpTar::splitArchiveFork() {
+ int status;
+ pid_t pid;
+ if ((pid = fork()) == -1) {
+ LOGI("create tar failed to fork.\n");
return -1;
}
- TWFunc::drop_caches();
+ if (pid == 0) {
+ if (Split_Archive() != 0)
+ exit(-1);
+ else
+ exit(0);
+ }
+ else {
+ if ((pid = wait(&status)) == -1) {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ else {
+ if (WIFSIGNALED(status) != 0) {
+ LOGI("Child process ended with signal: %d\n", WTERMSIG(status));
+ return -1;
+ }
+ else if (WIFEXITED(status) != 0)
+ LOGI("Tar creation successful\n");
+ else {
+ LOGI("Tar creation failed\n");
+ return -1;
+ }
+ }
+ }
return 0;
}