From 4377234daafd210152a4aa0b9739d07cde20cfbf Mon Sep 17 00:00:00 2001 From: Sandeep Patil Date: Thu, 4 Apr 2019 09:35:51 -0700 Subject: [PATCH] vdc: print the failed command with failure status. vdc currently only prints generic binder failure status on failure. This doesn't help debugging early boot failures at all since we don't know which exact vdc command failed. Fix that by adding the command as part of the failure message. Bug: 129946805 Test: Boot cuttlefish Change-Id: Ic2367cf592d6b5bf23d6d4b1447baa1baf41afe7 Signed-off-by: Sandeep Patil --- vdc.cpp | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/vdc.cpp b/vdc.cpp index 76eca3e..6136413 100644 --- a/vdc.cpp +++ b/vdc.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -55,9 +56,10 @@ static android::sp getServiceAggressive() { return res; } -static void checkStatus(android::binder::Status status) { +static void checkStatus(std::vector& cmd, android::binder::Status status) { if (status.isOk()) return; - LOG(ERROR) << "Failed: " << status.toString8().string(); + std::string command = ::android::base::Join(cmd, " "); + LOG(ERROR) << "Command: " << command << " Failed: " << status.toString8().string(); exit(ENOTTY); } @@ -88,63 +90,63 @@ int main(int argc, char** argv) { auto vold = android::interface_cast(binder); if (args[0] == "cryptfs" && args[1] == "enablefilecrypto") { - checkStatus(vold->fbeEnable()); + checkStatus(args, vold->fbeEnable()); } else if (args[0] == "cryptfs" && args[1] == "init_user0") { - checkStatus(vold->initUser0()); + checkStatus(args, vold->initUser0()); } else if (args[0] == "cryptfs" && args[1] == "enablecrypto") { int passwordType = android::os::IVold::PASSWORD_TYPE_DEFAULT; int encryptionFlags = android::os::IVold::ENCRYPTION_FLAG_NO_UI; - checkStatus(vold->fdeEnable(passwordType, "", encryptionFlags)); + checkStatus(args, vold->fdeEnable(passwordType, "", encryptionFlags)); } else if (args[0] == "cryptfs" && args[1] == "mountdefaultencrypted") { - checkStatus(vold->mountDefaultEncrypted()); + checkStatus(args, vold->mountDefaultEncrypted()); } else if (args[0] == "volume" && args[1] == "shutdown") { - checkStatus(vold->shutdown()); + checkStatus(args, vold->shutdown()); } else if (args[0] == "cryptfs" && args[1] == "checkEncryption" && args.size() == 3) { - checkStatus(vold->checkEncryption(args[2])); + checkStatus(args, vold->checkEncryption(args[2])); } else if (args[0] == "cryptfs" && args[1] == "mountFstab" && args.size() == 3) { - checkStatus(vold->mountFstab(args[2])); + checkStatus(args, vold->mountFstab(args[2])); } else if (args[0] == "cryptfs" && args[1] == "encryptFstab" && args.size() == 3) { - checkStatus(vold->encryptFstab(args[2])); + checkStatus(args, vold->encryptFstab(args[2])); } else if (args[0] == "checkpoint" && args[1] == "supportsCheckpoint" && args.size() == 2) { bool supported = false; - checkStatus(vold->supportsCheckpoint(&supported)); + checkStatus(args, vold->supportsCheckpoint(&supported)); return supported ? 1 : 0; } else if (args[0] == "checkpoint" && args[1] == "supportsBlockCheckpoint" && args.size() == 2) { bool supported = false; - checkStatus(vold->supportsBlockCheckpoint(&supported)); + checkStatus(args, vold->supportsBlockCheckpoint(&supported)); return supported ? 1 : 0; } else if (args[0] == "checkpoint" && args[1] == "supportsFileCheckpoint" && args.size() == 2) { bool supported = false; - checkStatus(vold->supportsFileCheckpoint(&supported)); + checkStatus(args, vold->supportsFileCheckpoint(&supported)); return supported ? 1 : 0; } else if (args[0] == "checkpoint" && args[1] == "startCheckpoint" && args.size() == 3) { int retry; if (!android::base::ParseInt(args[2], &retry)) exit(EINVAL); - checkStatus(vold->startCheckpoint(retry)); + checkStatus(args, vold->startCheckpoint(retry)); } else if (args[0] == "checkpoint" && args[1] == "needsCheckpoint" && args.size() == 2) { bool enabled = false; - checkStatus(vold->needsCheckpoint(&enabled)); + checkStatus(args, vold->needsCheckpoint(&enabled)); return enabled ? 1 : 0; } else if (args[0] == "checkpoint" && args[1] == "needsRollback" && args.size() == 2) { bool enabled = false; - checkStatus(vold->needsRollback(&enabled)); + checkStatus(args, vold->needsRollback(&enabled)); return enabled ? 1 : 0; } else if (args[0] == "checkpoint" && args[1] == "commitChanges" && args.size() == 2) { - checkStatus(vold->commitChanges()); + checkStatus(args, vold->commitChanges()); } else if (args[0] == "checkpoint" && args[1] == "prepareCheckpoint" && args.size() == 2) { - checkStatus(vold->prepareCheckpoint()); + checkStatus(args, vold->prepareCheckpoint()); } else if (args[0] == "checkpoint" && args[1] == "restoreCheckpoint" && args.size() == 3) { - checkStatus(vold->restoreCheckpoint(args[2])); + checkStatus(args, vold->restoreCheckpoint(args[2])); } else if (args[0] == "checkpoint" && args[1] == "restoreCheckpointPart" && args.size() == 4) { int count; if (!android::base::ParseInt(args[3], &count)) exit(EINVAL); - checkStatus(vold->restoreCheckpointPart(args[2], count)); + checkStatus(args, vold->restoreCheckpointPart(args[2], count)); } else if (args[0] == "checkpoint" && args[1] == "markBootAttempt" && args.size() == 2) { - checkStatus(vold->markBootAttempt()); + checkStatus(args, vold->markBootAttempt()); } else if (args[0] == "checkpoint" && args[1] == "abortChanges" && args.size() == 4) { int retry; if (!android::base::ParseInt(args[2], &retry)) exit(EINVAL); - checkStatus(vold->abortChanges(args[2], retry != 0)); + checkStatus(args, vold->abortChanges(args[2], retry != 0)); } else { LOG(ERROR) << "Raw commands are no longer supported"; exit(EINVAL);