better error codes to allow for diagnosing problems in recovery mode. fix system looking for sh in /system/bin/sh
diff --git a/extendedcommands.c b/extendedcommands.c
index 61b0252..1f32c49 100644
--- a/extendedcommands.c
+++ b/extendedcommands.c
@@ -16,6 +16,9 @@
#include <sys/limits.h>
#include <dirent.h>
+#include <signal.h>
+#include <sys/wait.h>
+
#include "bootloader.h"
#include "common.h"
#include "cutils/properties.h"
@@ -195,12 +198,54 @@
install_zip(sdcard_package_file);
}
+// This was pulled from bionic: The default system command always looks
+// for shell in /system/bin/sh. This is bad.
+#define _PATH_BSHELL "/sbin/sh"
+#define system recovery_system
+extern char **environ;
+int
+system(const char *command)
+{
+ pid_t pid;
+ sig_t intsave, quitsave;
+ sigset_t mask, omask;
+ int pstat;
+ char *argp[] = {"sh", "-c", NULL, NULL};
+
+ if (!command) /* just checking... */
+ return(1);
+
+ argp[2] = (char *)command;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &mask, &omask);
+ switch (pid = vfork()) {
+ case -1: /* error */
+ sigprocmask(SIG_SETMASK, &omask, NULL);
+ return(-1);
+ case 0: /* child */
+ sigprocmask(SIG_SETMASK, &omask, NULL);
+ execve(_PATH_BSHELL, argp, environ);
+ _exit(127);
+ }
+
+ intsave = (sig_t) bsd_signal(SIGINT, SIG_IGN);
+ quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
+ pid = waitpid(pid, (int *)&pstat, 0);
+ sigprocmask(SIG_SETMASK, &omask, NULL);
+ (void)bsd_signal(SIGINT, intsave);
+ (void)bsd_signal(SIGQUIT, quitsave);
+ return (pid == -1 ? -1 : pstat);
+}
+
void do_nandroid_backup()
{
ui_print("Performing backup...\n");
- if (system("/sbin/nandroid-mobile.sh backup") != 0)
+ int ret = system("/sbin/nandroid-mobile.sh backup /sdcard/clockworkmod/backup/");
+ if (ret != 0)
{
- ui_print("Error while backing up!\n");
+ ui_print("Error while backing up! Error code: %d\n", ret);
return;
}
ui_print("Backup complete.\n");