Merge "x86: Add vold.fstab to mount the SD card"
diff --git a/include/arch/darwin-x86/AndroidConfig.h b/include/arch/darwin-x86/AndroidConfig.h
index 2bb44c6..9914bd5 100644
--- a/include/arch/darwin-x86/AndroidConfig.h
+++ b/include/arch/darwin-x86/AndroidConfig.h
@@ -300,4 +300,12 @@
  */
 #define HAVE_PRINTF_ZD 1
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * Most systems lack (and actually don't need) this flag.
+ */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/freebsd-x86/AndroidConfig.h b/include/arch/freebsd-x86/AndroidConfig.h
index 992b689..ed5af59 100644
--- a/include/arch/freebsd-x86/AndroidConfig.h
+++ b/include/arch/freebsd-x86/AndroidConfig.h
@@ -358,4 +358,12 @@
  */
 #define HAVE_PRINTF_ZD 1
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * Most systems lack (and actually don't need) this flag.
+ */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/linux-arm/AndroidConfig.h b/include/arch/linux-arm/AndroidConfig.h
index 5b7ccee..c70618d 100644
--- a/include/arch/linux-arm/AndroidConfig.h
+++ b/include/arch/linux-arm/AndroidConfig.h
@@ -354,4 +354,12 @@
  */
 #define HAVE_PRINTF_ZD 1
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * Most systems lack (and actually don't need) this flag.
+ */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #endif /* _ANDROID_CONFIG_H */
diff --git a/include/arch/linux-ppc/AndroidConfig.h b/include/arch/linux-ppc/AndroidConfig.h
index 2c443d1..91af629 100644
--- a/include/arch/linux-ppc/AndroidConfig.h
+++ b/include/arch/linux-ppc/AndroidConfig.h
@@ -318,4 +318,12 @@
  */
 #define HAVE_PREAD 1
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * Most systems lack (and actually don't need) this flag.
+ */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/linux-sh/AndroidConfig.h b/include/arch/linux-sh/AndroidConfig.h
index 0dd7b3b..622ca50 100644
--- a/include/arch/linux-sh/AndroidConfig.h
+++ b/include/arch/linux-sh/AndroidConfig.h
@@ -361,4 +361,12 @@
  */
 #define HAVE_PRINTF_ZD 1
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * Most systems lack (and actually don't need) this flag.
+ */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #endif /* _ANDROID_CONFIG_H */
diff --git a/include/arch/linux-x86/AndroidConfig.h b/include/arch/linux-x86/AndroidConfig.h
index 24f6ccc..26dcf1f 100644
--- a/include/arch/linux-x86/AndroidConfig.h
+++ b/include/arch/linux-x86/AndroidConfig.h
@@ -328,4 +328,12 @@
  */
 #define HAVE_PRINTF_ZD 1
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * Most systems lack (and actually don't need) this flag.
+ */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/target_linux-x86/AndroidConfig.h b/include/arch/target_linux-x86/AndroidConfig.h
index d6ce3f2..9b357d9 100644
--- a/include/arch/target_linux-x86/AndroidConfig.h
+++ b/include/arch/target_linux-x86/AndroidConfig.h
@@ -345,4 +345,12 @@
  */
 #define HAVE_PRINTF_ZD 1
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * Most systems lack (and actually don't need) this flag.
+ */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #endif /* _ANDROID_CONFIG_H */
diff --git a/include/arch/windows/AndroidConfig.h b/include/arch/windows/AndroidConfig.h
index f0bf56f..17c84c7 100644
--- a/include/arch/windows/AndroidConfig.h
+++ b/include/arch/windows/AndroidConfig.h
@@ -333,4 +333,10 @@
  */
 /* #define HAVE_PRINTF_ZD 1 */
 
+/*
+ * We need to open binary files using O_BINARY on Windows.
+ * We don't define it on Windows since it is part of the io headers.
+ */
+/* #define O_BINARY 0 */
+
 #endif /*_ANDROID_CONFIG_H*/
diff --git a/init/keychords.c b/init/keychords.c
index 53ab391..febb62f 100644
--- a/init/keychords.c
+++ b/init/keychords.c
@@ -103,14 +103,14 @@
     // and on user builds for users that are developers.
     debuggable = property_get("ro.debuggable");
     adb_enabled = property_get("init.svc.adbd");
+    ret = read(keychord_fd, &id, sizeof(id));
+    if (ret != sizeof(id)) {
+        ERROR("could not read keychord id\n");
+        return;
+    }
+
     if ((debuggable && !strcmp(debuggable, "1")) ||
         (adb_enabled && !strcmp(adb_enabled, "running"))) {
-        ret = read(keychord_fd, &id, sizeof(id));
-        if (ret != sizeof(id)) {
-            ERROR("could not read keychord id\n");
-            return;
-        }
-
         svc = service_find_by_keychord(id);
         if (svc) {
             INFO("starting service %s from keychord\n", svc->name);