Merge "adb: use shell for remount to forward return codes."

This commit is contained in:
Josh Gao 2019-08-14 00:26:04 +00:00 committed by Gerrit Code Review
commit edf8040152
5 changed files with 32 additions and 15 deletions

View File

@ -1704,10 +1704,23 @@ int adb_commandline(int argc, const char** argv) {
error_exit("tcpip: invalid port: %s", argv[1]);
}
return adb_connect_command(android::base::StringPrintf("tcpip:%d", port));
} else if (!strcmp(argv[0], "remount")) {
FeatureSet features;
std::string error;
if (!adb_get_feature_set(&features, &error)) {
fprintf(stderr, "error: %s\n", error.c_str());
return 1;
}
if (CanUseFeature(features, kFeatureRemountShell)) {
const char* arg[2] = {"shell", "remount"};
return adb_shell(2, arg);
} else {
return adb_connect_command("remount:");
}
}
// clang-format off
else if (!strcmp(argv[0], "remount") ||
!strcmp(argv[0], "reboot") ||
else if (!strcmp(argv[0], "reboot") ||
!strcmp(argv[0], "reboot-bootloader") ||
!strcmp(argv[0], "reboot-fastboot") ||
!strcmp(argv[0], "usb") ||

View File

@ -48,6 +48,8 @@ static bool do_remount(int fd, const std::string& cmd) {
dup2(fd, STDERR_FILENO);
execl(kRemountCmd, kRemountCmd, cmd.empty() ? nullptr : cmd.c_str(), nullptr);
const char* msg = "failed to exec remount\n";
write(STDERR_FILENO, msg, strlen(msg));
_exit(errno);
}
@ -83,6 +85,6 @@ static bool do_remount(int fd, const std::string& cmd) {
}
void remount_service(unique_fd fd, const std::string& cmd) {
const char* success = do_remount(fd.get(), cmd) ? "succeeded" : "failed";
WriteFdFmt(fd.get(), "remount %s\n", success);
do_remount(fd.get(), cmd);
// The remount command will print success or failure for us.
}

View File

@ -73,6 +73,7 @@ const char* const kFeatureFixedPushMkdir = "fixed_push_mkdir";
const char* const kFeatureAbb = "abb";
const char* const kFeatureFixedPushSymlinkTimestamp = "fixed_push_symlink_timestamp";
const char* const kFeatureAbbExec = "abb_exec";
const char* const kFeatureRemountShell = "remount_shell";
namespace {
@ -1049,6 +1050,7 @@ const FeatureSet& supported_features() {
kFeatureAbb,
kFeatureFixedPushSymlinkTimestamp,
kFeatureAbbExec,
kFeatureRemountShell,
// Increment ADB_SERVER_VERSION when adding a feature that adbd needs
// to know about. Otherwise, the client can be stuck running an old
// version of the server even after upgrading their copy of adb.

View File

@ -69,6 +69,7 @@ extern const char* const kFeatureFixedPushMkdir;
extern const char* const kFeatureAbb;
// adbd properly updates symlink timestamps on push.
extern const char* const kFeatureFixedPushSymlinkTimestamp;
extern const char* const kFeatureRemountShell;
TransportId NextTransportId();

View File

@ -82,13 +82,7 @@ const android::fs_mgr::FstabEntry* is_wrapped(const android::fs_mgr::Fstab& over
void MyLogger(android::base::LogId id, android::base::LogSeverity severity, const char* tag,
const char* file, unsigned int line, const char* message) {
static const char log_characters[] = "VD\0WEFF";
if (severity < sizeof(log_characters)) {
auto severity_char = log_characters[severity];
if (severity_char) fprintf(stderr, "%c ", severity_char);
}
fprintf(stderr, "%s\n", message);
static auto logd = android::base::LogdLogger();
logd(id, severity, tag, file, line, message);
}
@ -107,11 +101,9 @@ void MyLogger(android::base::LogId id, android::base::LogSeverity severity, cons
} // namespace
int main(int argc, char* argv[]) {
android::base::InitLogging(argv, MyLogger);
static int do_remount(int argc, char* argv[]) {
enum {
SUCCESS,
SUCCESS = 0,
NOT_USERDEBUG,
BADARG,
NOT_ROOT,
@ -165,7 +157,7 @@ int main(int argc, char* argv[]) {
// Make sure we are root.
if (::getuid() != 0) {
LOG(ERROR) << "must be run as root";
LOG(ERROR) << "Not running as root. Try \"adb root\" first.";
return NOT_ROOT;
}
@ -390,3 +382,10 @@ int main(int argc, char* argv[]) {
return retval;
}
int main(int argc, char* argv[]) {
android::base::InitLogging(argv, MyLogger);
int result = do_remount(argc, argv);
printf("remount %s\n", result ? "failed" : "succeeded");
return result;
}