summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDees_Troy <dees_troy@teamw.in>2013-08-24 14:06:47 +0200
committerGerrit Code Review <gerrit@198.50.184.117>2013-08-24 14:42:48 +0200
commit29a0635b93738a3b7b322360437b548664b0437d (patch)
treeb765f0ff6e4bf1a0fb3c60316dc395e6efd0b8d8
parentAdd SELinux support (diff)
downloadandroid_bootable_recovery-29a0635b93738a3b7b322360437b548664b0437d.tar
android_bootable_recovery-29a0635b93738a3b7b322360437b548664b0437d.tar.gz
android_bootable_recovery-29a0635b93738a3b7b322360437b548664b0437d.tar.bz2
android_bootable_recovery-29a0635b93738a3b7b322360437b548664b0437d.tar.lz
android_bootable_recovery-29a0635b93738a3b7b322360437b548664b0437d.tar.xz
android_bootable_recovery-29a0635b93738a3b7b322360437b548664b0437d.tar.zst
android_bootable_recovery-29a0635b93738a3b7b322360437b548664b0437d.zip
Diffstat (limited to '')
-rw-r--r--twrp-functions.cpp55
1 files changed, 12 insertions, 43 deletions
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 463522664..d9014b364 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -36,52 +36,21 @@ extern "C" {
/* Execute a command */
int TWFunc::Exec_Cmd(string cmd, string &result) {
- int fd[2];
- int ret = -1;
- if(pipe(fd) < 0)
- return -1;
-
- pid_t pid = fork();
- if (pid < 0)
- {
- close(fd[0]);
- close(fd[1]);
- return -1;
- }
-
- if(pid == 0) // child
- {
- close(fd[0]);
- dup2(fd[1], 1); // send stdout to the pipe
- dup2(fd[1], 2); // send stderr to the pipe
- close(fd[1]);
-
- ret = system(cmd.c_str());
- if(ret != -1)
- ret = WEXITSTATUS(ret);
- else
- LOGERR("Exec_Cmd: system() failed with -1 (%d)!\n", errno);
- exit(ret);
- }
- else
- {
- close(fd[1]);
-
- int len;
- char buffer[128];
- buffer[sizeof(buffer)-1] = 0;
- while ((len = read(fd[0], buffer, sizeof(buffer)-1)) > 0)
- {
- buffer[len] = 0;
- buffer[sizeof(buffer)-2] = '\n';
- LOGINFO("%s", buffer);
+ FILE* exec;
+ char buffer[130];
+ int ret = 0;
+ exec = __popen(cmd.c_str(), "r");
+ if (!exec) return -1;
+ while(!feof(exec)) {
+ memset(&buffer, 0, sizeof(buffer));
+ if (fgets(buffer, 128, exec) != NULL) {
+ buffer[128] = '\n';
+ buffer[129] = NULL;
result += buffer;
}
-
- waitpid(pid, &ret, 0);
- return WEXITSTATUS(ret);
}
- return -1;
+ ret = __pclose(exec);
+ return ret;
}
// Returns "file.name" from a full /path/to/file.name