Merge "Make crasher smash-stack work."
diff --git a/fastbootd/commands.c b/fastbootd/commands.c
index 98b7866..9be96dc 100644
--- a/fastbootd/commands.c
+++ b/fastbootd/commands.c
@@ -173,7 +173,7 @@
         return;
     }
 
-    if (path == NULL) {
+    if (!path[0]) {
         fastboot_fail(phandle, "Couldn't find partition");
         return;
     }
diff --git a/include/utils/Singleton.h b/include/utils/Singleton.h
index c60680e..ffc03cb 100644
--- a/include/utils/Singleton.h
+++ b/include/utils/Singleton.h
@@ -65,9 +65,10 @@
  */
 
 #define ANDROID_SINGLETON_STATIC_INSTANCE(TYPE)                 \
-    template<> Mutex Singleton< TYPE >::sLock(Mutex::PRIVATE);  \
-    template<> TYPE* Singleton< TYPE >::sInstance(0);           \
-    template class Singleton< TYPE >;
+    template<> ::android::Mutex  \
+        (::android::Singleton< TYPE >::sLock)(::android::Mutex::PRIVATE);  \
+    template<> TYPE* ::android::Singleton< TYPE >::sInstance(0);  \
+    template class ::android::Singleton< TYPE >;
 
 
 // ---------------------------------------------------------------------------
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 249f91e..e7e5a5b 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -112,7 +112,6 @@
 
 OUR_TOOLS := \
     chcon \
-    chmod \
     cmp \
     date \
     df \
@@ -120,7 +119,6 @@
     getevent \
     getprop \
     getsebool \
-    hd \
     id \
     ifconfig \
     iftop \
diff --git a/toolbox/chmod.c b/toolbox/chmod.c
deleted file mode 100644
index 2a524e9..0000000
--- a/toolbox/chmod.c
+++ /dev/null
@@ -1,101 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <sys/limits.h>
-#include <sys/stat.h>
-
-#include <unistd.h>
-#include <time.h>
-
-void recurse_chmod(char* path, int mode)
-{
-    struct dirent *dp;
-    DIR *dir = opendir(path);
-    if (dir == NULL) {
-        // not a directory, carry on
-        return;
-    }
-    char *subpath = malloc(sizeof(char)*PATH_MAX);
-    int pathlen = strlen(path);
-
-    while ((dp = readdir(dir)) != NULL) {
-        if (strcmp(dp->d_name, ".") == 0 ||
-            strcmp(dp->d_name, "..") == 0) continue;
-
-        if (strlen(dp->d_name) + pathlen + 2/*NUL and slash*/ > PATH_MAX) {
-            fprintf(stderr, "Invalid path specified: too long\n");
-            exit(1);
-        }
-
-        strcpy(subpath, path);
-        strcat(subpath, "/");
-        strcat(subpath, dp->d_name);
-
-        if (chmod(subpath, mode) < 0) {
-            fprintf(stderr, "Unable to chmod %s: %s\n", subpath, strerror(errno));
-            exit(1);
-        }
-
-        recurse_chmod(subpath, mode);
-    }
-    free(subpath);
-    closedir(dir);
-}
-
-static int usage()
-{
-    fprintf(stderr, "Usage: chmod [OPTION] <MODE> <FILE>\n");
-    fprintf(stderr, "  -R, --recursive         change files and directories recursively\n");
-    fprintf(stderr, "  --help                  display this help and exit\n");
-
-    return 10;
-}
-
-int chmod_main(int argc, char **argv)
-{
-    int i;
-
-    if (argc < 3 || strcmp(argv[1], "--help") == 0) {
-        return usage();
-    }
-
-    int recursive = (strcmp(argv[1], "-R") == 0 ||
-                     strcmp(argv[1], "--recursive") == 0) ? 1 : 0;
-
-    if (recursive && argc < 4) {
-        return usage();
-    }
-
-    if (recursive) {
-        argc--;
-        argv++;
-    }
-
-    int mode = 0;
-    const char* s = argv[1];
-    while (*s) {
-        if (*s >= '0' && *s <= '7') {
-            mode = (mode<<3) | (*s-'0');
-        }
-        else {
-            fprintf(stderr, "Bad mode\n");
-            return 10;
-        }
-        s++;
-    }
-
-    for (i = 2; i < argc; i++) {
-        if (chmod(argv[i], mode) < 0) {
-            fprintf(stderr, "Unable to chmod %s: %s\n", argv[i], strerror(errno));
-            return 10;
-        }
-        if (recursive) {
-            recurse_chmod(argv[i], mode);
-        }
-    }
-    return 0;
-}
-
diff --git a/toolbox/hd.c b/toolbox/hd.c
deleted file mode 100644
index 7c9998e..0000000
--- a/toolbox/hd.c
+++ /dev/null
@@ -1,97 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-int hd_main(int argc, char *argv[])
-{
-    int c;
-    int fd;
-	unsigned char buf[4096];
-    int res;
-	int read_len;
-	int i;
-	int filepos = 0;
-	int sum;
-	int lsum;
-
-	int base = -1;
-	int count = 0;
-	int repeat = 0;
-
-    do {
-        c = getopt(argc, argv, "b:c:r:");
-        if (c == EOF)
-            break;
-        switch (c) {
-        case 'b':
-            base = strtol(optarg, NULL, 0);
-            break;
-        case 'c':
-            count = strtol(optarg, NULL, 0);
-            break;
-		case 'r':
-			repeat = strtol(optarg, NULL, 0);
-			break;
-        case '?':
-            fprintf(stderr, "%s: invalid option -%c\n",
-                argv[0], optopt);
-            exit(1);
-        }
-    } while (1);
-
-    if (optind + 1 != argc) {
-        fprintf(stderr, "Usage: %s [-b base] [-c count] [-r delay] file\n", argv[0]);
-        exit(1);
-    }
-
-    fd = open(argv[optind], O_RDONLY);
-    if(fd < 0) {
-        fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
-        return 1;
-    }
-
-	do {
-		if(base >= 0) {
-			lseek(fd, base, SEEK_SET);
-			filepos = base;
-		}
-		sum = 0;
-		lsum = 0;
-	    while(1) {
-			read_len = sizeof(buf);
-			if(count > 0 && base + count - filepos < read_len)
-				read_len = base + count - filepos;
-	        res = read(fd, &buf, read_len);
-			if(res == 0)
-				break;
-			for(i = 0; i < res; i++) {
-				if((i & 15) == 0) {
-					printf("%08x: ", filepos + i);
-				}
-				lsum += buf[i];
-				sum += buf[i];
-				printf("%02x ", buf[i]);
-				if(((i & 15) == 15) || (i == res - 1)) {
-					printf("s %x\n", lsum);
-					lsum = 0;
-				}
-			}
-			if(res < 0) {
-				printf("Read error on %s, offset %d len %d, %s\n", argv[optind], filepos, read_len, strerror(errno));
-				return 1;
-			}
-			filepos += res;
-			if(filepos == base + count)
-				break;
-	    }
-		printf("sum %x\n", sum);
-		if(repeat)
-			sleep(repeat);
-	} while(repeat);
-	return 0;
-}