Merge "adb: use shell for remount to forward return codes."
This commit is contained in:
commit
edf8040152
|
@ -1704,10 +1704,23 @@ int adb_commandline(int argc, const char** argv) {
|
||||||
error_exit("tcpip: invalid port: %s", argv[1]);
|
error_exit("tcpip: invalid port: %s", argv[1]);
|
||||||
}
|
}
|
||||||
return adb_connect_command(android::base::StringPrintf("tcpip:%d", port));
|
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
|
// clang-format off
|
||||||
else if (!strcmp(argv[0], "remount") ||
|
else if (!strcmp(argv[0], "reboot") ||
|
||||||
!strcmp(argv[0], "reboot") ||
|
|
||||||
!strcmp(argv[0], "reboot-bootloader") ||
|
!strcmp(argv[0], "reboot-bootloader") ||
|
||||||
!strcmp(argv[0], "reboot-fastboot") ||
|
!strcmp(argv[0], "reboot-fastboot") ||
|
||||||
!strcmp(argv[0], "usb") ||
|
!strcmp(argv[0], "usb") ||
|
||||||
|
|
|
@ -48,6 +48,8 @@ static bool do_remount(int fd, const std::string& cmd) {
|
||||||
dup2(fd, STDERR_FILENO);
|
dup2(fd, STDERR_FILENO);
|
||||||
|
|
||||||
execl(kRemountCmd, kRemountCmd, cmd.empty() ? nullptr : cmd.c_str(), nullptr);
|
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);
|
_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) {
|
void remount_service(unique_fd fd, const std::string& cmd) {
|
||||||
const char* success = do_remount(fd.get(), cmd) ? "succeeded" : "failed";
|
do_remount(fd.get(), cmd);
|
||||||
WriteFdFmt(fd.get(), "remount %s\n", success);
|
// The remount command will print success or failure for us.
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ const char* const kFeatureFixedPushMkdir = "fixed_push_mkdir";
|
||||||
const char* const kFeatureAbb = "abb";
|
const char* const kFeatureAbb = "abb";
|
||||||
const char* const kFeatureFixedPushSymlinkTimestamp = "fixed_push_symlink_timestamp";
|
const char* const kFeatureFixedPushSymlinkTimestamp = "fixed_push_symlink_timestamp";
|
||||||
const char* const kFeatureAbbExec = "abb_exec";
|
const char* const kFeatureAbbExec = "abb_exec";
|
||||||
|
const char* const kFeatureRemountShell = "remount_shell";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -1049,6 +1050,7 @@ const FeatureSet& supported_features() {
|
||||||
kFeatureAbb,
|
kFeatureAbb,
|
||||||
kFeatureFixedPushSymlinkTimestamp,
|
kFeatureFixedPushSymlinkTimestamp,
|
||||||
kFeatureAbbExec,
|
kFeatureAbbExec,
|
||||||
|
kFeatureRemountShell,
|
||||||
// Increment ADB_SERVER_VERSION when adding a feature that adbd needs
|
// Increment ADB_SERVER_VERSION when adding a feature that adbd needs
|
||||||
// to know about. Otherwise, the client can be stuck running an old
|
// to know about. Otherwise, the client can be stuck running an old
|
||||||
// version of the server even after upgrading their copy of adb.
|
// version of the server even after upgrading their copy of adb.
|
||||||
|
|
|
@ -69,6 +69,7 @@ extern const char* const kFeatureFixedPushMkdir;
|
||||||
extern const char* const kFeatureAbb;
|
extern const char* const kFeatureAbb;
|
||||||
// adbd properly updates symlink timestamps on push.
|
// adbd properly updates symlink timestamps on push.
|
||||||
extern const char* const kFeatureFixedPushSymlinkTimestamp;
|
extern const char* const kFeatureFixedPushSymlinkTimestamp;
|
||||||
|
extern const char* const kFeatureRemountShell;
|
||||||
|
|
||||||
TransportId NextTransportId();
|
TransportId NextTransportId();
|
||||||
|
|
||||||
|
|
|
@ -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,
|
void MyLogger(android::base::LogId id, android::base::LogSeverity severity, const char* tag,
|
||||||
const char* file, unsigned int line, const char* message) {
|
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);
|
fprintf(stderr, "%s\n", message);
|
||||||
|
|
||||||
static auto logd = android::base::LogdLogger();
|
static auto logd = android::base::LogdLogger();
|
||||||
logd(id, severity, tag, file, line, message);
|
logd(id, severity, tag, file, line, message);
|
||||||
}
|
}
|
||||||
|
@ -107,11 +101,9 @@ void MyLogger(android::base::LogId id, android::base::LogSeverity severity, cons
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
static int do_remount(int argc, char* argv[]) {
|
||||||
android::base::InitLogging(argv, MyLogger);
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SUCCESS,
|
SUCCESS = 0,
|
||||||
NOT_USERDEBUG,
|
NOT_USERDEBUG,
|
||||||
BADARG,
|
BADARG,
|
||||||
NOT_ROOT,
|
NOT_ROOT,
|
||||||
|
@ -165,7 +157,7 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
// Make sure we are root.
|
// Make sure we are root.
|
||||||
if (::getuid() != 0) {
|
if (::getuid() != 0) {
|
||||||
LOG(ERROR) << "must be run as root";
|
LOG(ERROR) << "Not running as root. Try \"adb root\" first.";
|
||||||
return NOT_ROOT;
|
return NOT_ROOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,3 +382,10 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
return retval;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue