Merge changes from topic "apex_remount"

am: baea773324

Change-Id: If64a41f61f434b49847c954cc56530703d697b73
This commit is contained in:
Josh Gao 2019-10-17 13:15:20 -07:00 committed by android-build-merger
commit 5b7f4d9cd5
4 changed files with 3 additions and 120 deletions

View file

@ -429,7 +429,6 @@ cc_library {
"daemon/framebuffer_service.cpp",
"daemon/mdns.cpp",
"daemon/reboot_service.cpp",
"daemon/remount_service.cpp",
"daemon/restart_service.cpp",
"daemon/set_verity_enable_state_service.cpp",
],

View file

@ -1,90 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string>
#include "adb.h"
#include "adb_io.h"
#include "adb_unique_fd.h"
static constexpr char kRemountCmd[] = "/system/bin/remount";
static bool do_remount(int fd, const std::string& cmd) {
if (getuid() != 0) {
WriteFdExactly(fd, "Not running as root. Try \"adb root\" first.\n");
return false;
}
auto pid = fork();
if (pid < 0) {
WriteFdFmt(fd, "Failed to fork to %s: %s\n", kRemountCmd, strerror(errno));
return false;
}
if (pid == 0) {
// child side of the fork
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
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);
}
int wstatus = 0;
auto ret = waitpid(pid, &wstatus, 0);
if (ret == -1) {
WriteFdFmt(fd, "Failed to wait for %s: %s\n", kRemountCmd, strerror(errno));
return false;
} else if (ret != pid) {
WriteFdFmt(fd, "pid %d and waitpid return %d do not match for %s\n",
static_cast<int>(pid), static_cast<int>(ret), kRemountCmd);
return false;
}
if (WIFSIGNALED(wstatus)) {
WriteFdFmt(fd, "%s terminated with signal %s\n", kRemountCmd,
strsignal(WTERMSIG(wstatus)));
return false;
}
if (!WIFEXITED(wstatus)) {
WriteFdFmt(fd, "%s stopped with status 0x%x\n", kRemountCmd, wstatus);
return false;
}
if (WEXITSTATUS(wstatus)) {
WriteFdFmt(fd, "%s exited with status %d\n", kRemountCmd, WEXITSTATUS(wstatus));
return false;
}
return true;
}
void remount_service(unique_fd fd, const std::string& cmd) {
do_remount(fd.get(), cmd);
// The remount command will print success or failure for us.
}

View file

@ -1,25 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <string>
#include "adb_unique_fd.h"
#if defined(__ANDROID__)
void remount_service(unique_fd, const std::string&);
#endif

View file

@ -54,7 +54,6 @@
#include "daemon/file_sync_service.h"
#include "daemon/framebuffer_service.h"
#include "daemon/reboot_service.h"
#include "daemon/remount_service.h"
#include "daemon/restart_service.h"
#include "daemon/set_verity_enable_state_service.h"
#include "daemon/shell_service.h"
@ -251,9 +250,9 @@ unique_fd daemon_service_to_fd(std::string_view name, atransport* transport) {
if (name.starts_with("framebuffer:")) {
return create_service_thread("fb", framebuffer_service);
} else if (android::base::ConsumePrefix(&name, "remount:")) {
std::string arg(name);
return create_service_thread("remount",
std::bind(remount_service, std::placeholders::_1, arg));
std::string cmd = "/system/bin/remount ";
cmd += name;
return StartSubprocess(cmd, nullptr, SubprocessType::kRaw, SubprocessProtocol::kNone);
} else if (android::base::ConsumePrefix(&name, "reboot:")) {
std::string arg(name);
return create_service_thread("reboot",