adb: Attempt to unmount the SD card before rebooting.
Change-Id: Idd4d96b4704f4e1bd324e72bca87611a23e30801
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/services.c b/services.c
index b5df554..487c7d3 100644
--- a/services.c
+++ b/services.c
@@ -176,9 +176,23 @@
void reboot_service(int fd, void *arg)
{
char buf[100];
- int ret;
+ int pid, ret;
sync();
+
+ /* Attempt to unmount the SD card first.
+ * No need to bother checking for errors.
+ */
+ pid = fork();
+ if (pid == 0) {
+ /* ask vdc to unmount it */
+ execl("/system/bin/vdc", "/system/bin/vdc", "volume", "unmount",
+ getenv("EXTERNAL_STORAGE"), "force", NULL);
+ } else if (pid > 0) {
+ /* wait until vdc succeeds or fails */
+ waitpid(pid, &ret, 0);
+ }
+
ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_CMD_RESTART2, (char *)arg);
if (ret < 0) {