Merge "Revert "fs_mgr: Add a library for managing logical partitions.""
diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp
index 39983ab..06fcf16 100644
--- a/adb/client/commandline.cpp
+++ b/adb/client/commandline.cpp
@@ -1136,8 +1136,7 @@
cmd += " " + escape_arg(*argv++);
}
- // No need for shell protocol with logcat, always disable for simplicity.
- return send_shell_command(cmd, true);
+ return send_shell_command(cmd);
}
static void write_zeros(int bytes, int fd) {
@@ -1861,7 +1860,7 @@
cmd += " " + escape_arg(*argv++);
}
- return send_shell_command(cmd, false);
+ return send_shell_command(cmd);
}
static int install_app(int argc, const char** argv) {
@@ -2049,7 +2048,7 @@
cmd += " " + escape_arg(*argv++);
}
- return send_shell_command(cmd, false);
+ return send_shell_command(cmd);
}
static int uninstall_app_legacy(int argc, const char** argv) {
@@ -2073,7 +2072,7 @@
static int delete_file(const std::string& filename) {
std::string cmd = "rm -f " + escape_arg(filename);
- return send_shell_command(cmd, false);
+ return send_shell_command(cmd);
}
static int install_app_legacy(int argc, const char** argv) {
diff --git a/adb/client/commandline.h b/adb/client/commandline.h
index 36cd798..3d10030 100644
--- a/adb/client/commandline.h
+++ b/adb/client/commandline.h
@@ -92,7 +92,7 @@
// resulting output.
// if |callback| is non-null, stdout/stderr output will be handled by it.
int send_shell_command(
- const std::string& command, bool disable_shell_protocol,
- StandardStreamsCallbackInterface* callback = &DEFAULT_STANDARD_STREAMS_CALLBACK);
+ const std::string& command, bool disable_shell_protocol = false,
+ StandardStreamsCallbackInterface* callback = &DEFAULT_STANDARD_STREAMS_CALLBACK);
#endif // COMMANDLINE_H
diff --git a/bootstat/Android.bp b/bootstat/Android.bp
index dd9ba88..8fc2171 100644
--- a/bootstat/Android.bp
+++ b/bootstat/Android.bp
@@ -63,7 +63,6 @@
name: "bootstat",
defaults: ["bootstat_defaults"],
static_libs: ["libbootstat"],
- shared_libs: ["liblogcat"],
init_rc: ["bootstat.rc"],
product_variables: {
pdk: {
diff --git a/bootstat/boot_reason_test.sh b/bootstat/boot_reason_test.sh
index 8ed92a6..ddd1caf 100755
--- a/bootstat/boot_reason_test.sh
+++ b/bootstat/boot_reason_test.sh
@@ -480,23 +480,25 @@
- (wait until screen is up, boot has completed)
- adb shell getprop ro.boot.bootreason (bootloader reason)
- adb shell getprop persist.sys.boot.reason (last reason)
+- adb shell getprop sys.boot.reason.last (last last reason)
- adb shell getprop sys.boot.reason (system reason)
- NB: all should have a value that is compliant with our known set." ]
test_properties() {
duration_test 1
wait_for_screen
retval=0
- check_set="ro.boot.bootreason persist.sys.boot.reason sys.boot.reason"
+ check_set="ro.boot.bootreason sys.boot.reason.last sys.boot.reason"
bootloader=""
# NB: this test could fail if performed _after_ optional_factory_reset test
# and will report
# ERROR: expected "reboot" got ""
- # for Android property persist.sys.boot.reason
+ # for Android property sys.boot.reason.last
# following is mitigation for the persist.sys.boot.reason, skip it
if [ "reboot,factory_reset" = "`validate_property ro.boot_bootreason`" ]; then
check_set="ro.boot.bootreason sys.boot.reason"
bootloader="bootloader"
fi
+ EXPECT_PROPERTY persist.sys.boot.reason ""
for prop in ${check_set}; do
reason=`validate_property ${prop}`
EXPECT_PROPERTY ${prop} ${reason} || retval=${?}
@@ -554,7 +556,8 @@
popd >&2
wait_for_screen
EXPECT_PROPERTY sys.boot.reason "\(reboot,ota\|bootloader\)"
- EXPECT_PROPERTY persist.sys.boot.reason bootloader
+ EXPECT_PROPERTY sys.boot.reason.last bootloader
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs reboot,ota bootloader
}
@@ -568,7 +571,8 @@
adb reboot ota
wait_for_screen
EXPECT_PROPERTY sys.boot.reason reboot,ota
- EXPECT_PROPERTY persist.sys.boot.reason reboot,ota
+ EXPECT_PROPERTY sys.boot.reason.last reboot,ota
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs reboot,ota
}
@@ -593,9 +597,15 @@
wait_for_screen
bootloader_reason=`validate_property ro.boot.bootreason`
EXPECT_PROPERTY ro.boot.bootreason ${bootloader_reason}
- EXPECT_PROPERTY sys.boot.reason ${reason}
- EXPECT_PROPERTY persist.sys.boot.reason ${reason}
- report_bootstat_logs ${reason}
+ # to make sys.boot.reason report user friendly
+ reasons=${reason}
+ if [ "${bootloader_reason}" != "${reason}" -a -n "${bootloader_reason}" ]; then
+ reasons="\(${reason}\|${bootloader_reason}\)"
+ fi
+ EXPECT_PROPERTY sys.boot.reason ${reasons}
+ EXPECT_PROPERTY sys.boot.reason.last ${reason}
+ EXPECT_PROPERTY persist.sys.boot.reason ""
+ report_bootstat_logs ${reason} ${bootloader_reason}
}
[ "USAGE: test_cold
@@ -627,7 +637,8 @@
adb reboot >&2
wait_for_screen
EXPECT_PROPERTY sys.boot.reason reboot,factory_reset
- EXPECT_PROPERTY persist.sys.boot.reason "reboot,.*"
+ EXPECT_PROPERTY sys.boot.reason.last "reboot,.*"
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs reboot,factory_reset reboot, reboot,adb \
"-bootstat: Failed to read /data/misc/bootstat/build_date: No such file or directory" \
"-bootstat: Failed to parse boot time record: /data/misc/bootstat/build_date"
@@ -658,6 +669,7 @@
wait_for_screen
( exit ${save_ret} ) # because one can not just do ?=${save_ret}
EXPECT_PROPERTY sys.boot.reason reboot,factory_reset
+ EXPECT_PROPERTY sys.boot.reason.last ""
EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs reboot,factory_reset bootloader \
"-bootstat: Failed to read /data/misc/bootstat/last_boot_time_utc: No such file or directory" \
@@ -731,7 +743,8 @@
)
EXPECT_PROPERTY sys.boot.reason shutdown,battery
- EXPECT_PROPERTY persist.sys.boot.reason cold
+ EXPECT_PROPERTY sys.boot.reason.last cold
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs shutdown,battery "-bootstat: Battery level at shutdown 2%"
exitPstore
}
@@ -752,7 +765,8 @@
echo -n "WARNING: Please power device back up, waiting ... " >&2
wait_for_screen -n >&2
EXPECT_PROPERTY sys.boot.reason shutdown,battery
- EXPECT_PROPERTY persist.sys.boot.reason shutdown,battery
+ EXPECT_PROPERTY sys.boot.reason.last shutdown,battery
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs shutdown,battery
}
@@ -772,7 +786,8 @@
echo -n "WARNING: Please power device back up, waiting ... " >&2
wait_for_screen -n >&2
EXPECT_PROPERTY sys.boot.reason shutdown,thermal,battery
- EXPECT_PROPERTY persist.sys.boot.reason shutdown,thermal,battery
+ EXPECT_PROPERTY sys.boot.reason.last shutdown,thermal,battery
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs shutdown,thermal,battery
}
@@ -808,7 +823,8 @@
echo c | adb shell su root tee /proc/sysrq-trigger >/dev/null
wait_for_screen
EXPECT_PROPERTY sys.boot.reason ${panic_msg}
- EXPECT_PROPERTY persist.sys.boot.reason ${panic_msg}
+ EXPECT_PROPERTY sys.boot.reason.last ${panic_msg}
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs kernel_panic,sysrq
exitPstore
}
@@ -835,7 +851,8 @@
echo c | adb shell su root tee /proc/sysrq-trigger >/dev/null
wait_for_screen
EXPECT_PROPERTY sys.boot.reason ${panic_msg}
- EXPECT_PROPERTY persist.sys.boot.reason ${panic_msg}
+ EXPECT_PROPERTY sys.boot.reason.last ${panic_msg}
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs kernel_panic,sysrq,test \
"-bootstat: Unknown boot reason: kernel_panic,sysrq,test"
exitPstore
@@ -865,7 +882,8 @@
adb reboot warm
wait_for_screen
EXPECT_PROPERTY sys.boot.reason ${panic_msg}
- EXPECT_PROPERTY persist.sys.boot.reason ${panic_msg}
+ EXPECT_PROPERTY sys.boot.reason.last ${panic_msg}
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs kernel_panic,hung
exitPstore
}
@@ -897,7 +915,8 @@
echo -n "WARNING: Please power device back up, waiting ... " >&2
wait_for_screen -n >&2
EXPECT_PROPERTY sys.boot.reason shutdown,thermal
- EXPECT_PROPERTY persist.sys.boot.reason shutdown,thermal
+ EXPECT_PROPERTY sys.boot.reason.last shutdown,thermal
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs shutdown,thermal
}
@@ -917,7 +936,8 @@
echo -n "WARNING: Please power device back up, waiting ... " >&2
wait_for_screen -n >&2
EXPECT_PROPERTY sys.boot.reason shutdown,userrequested
- EXPECT_PROPERTY persist.sys.boot.reason shutdown,userrequested
+ EXPECT_PROPERTY sys.boot.reason.last shutdown,userrequested
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs shutdown,userrequested
}
@@ -933,7 +953,8 @@
adb shell reboot
wait_for_screen
EXPECT_PROPERTY sys.boot.reason reboot,shell
- EXPECT_PROPERTY persist.sys.boot.reason reboot,shell
+ EXPECT_PROPERTY sys.boot.reason.last reboot,shell
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs reboot,shell
}
@@ -949,7 +970,8 @@
adb reboot
wait_for_screen
EXPECT_PROPERTY sys.boot.reason reboot,adb
- EXPECT_PROPERTY persist.sys.boot.reason reboot,adb
+ EXPECT_PROPERTY sys.boot.reason.last reboot,adb
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs reboot,adb
}
@@ -984,23 +1006,8 @@
adb shell 'reboot "Its Just So Hard"'
wait_for_screen
EXPECT_PROPERTY sys.boot.reason reboot,its_just_so_hard
- EXPECT_PROPERTY persist.sys.boot.reason "reboot,Its Just So Hard"
- # Do not leave this test with an illegal value in persist.sys.boot.reason
- save_ret=${?} # hold on to error code from above two lines
- if isDebuggable; then # can do this easy, or we can do this hard.
- adb shell su root setprop persist.sys.boot.reason reboot,its_just_so_hard
- ( exit ${save_ret} ) # because one can not just do ?=${save_ret}
- else
- report_bootstat_logs reboot,its_just_so_hard # report what we have so far
- # user build mitigation
- adb shell reboot its_just_so_hard
- wait_for_screen
- ( exit ${save_ret} ) # because one can not just do ?=${save_ret}
- EXPECT_PROPERTY sys.boot.reason reboot,its_just_so_hard
- fi
- # Ensure persist.sys.boot.reason now valid, failure here acts as a signal
- # that we could choke up following tests. For example test_properties.
- EXPECT_PROPERTY persist.sys.boot.reason reboot,its_just_so_hard ${flag}
+ EXPECT_PROPERTY sys.boot.reason.last reboot,its_just_so_hard
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs reboot,its_just_so_hard
}
@@ -1049,7 +1056,8 @@
# Check values
EXPECT_PROPERTY ro.boot.bootreason "${bootloader_expected}"
EXPECT_PROPERTY sys.boot.reason "${sys_expected}"
- EXPECT_PROPERTY persist.sys.boot.reason "${last_expected}"
+ EXPECT_PROPERTY sys.boot.reason.last "${last_expected}"
+ EXPECT_PROPERTY persist.sys.boot.reason ""
report_bootstat_logs "${sys_expected}"
}
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 32cc0cd..7ec57ec 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -43,7 +43,6 @@
#include <android/log.h>
#include <cutils/android_reboot.h>
#include <cutils/properties.h>
-#include <log/logcat.h>
#include <metricslogger/metrics_logger.h>
#include "boot_event_record_store.h"
@@ -735,6 +734,7 @@
const char system_reboot_reason_property[] = "sys.boot.reason";
const char last_reboot_reason_property[] = LAST_REBOOT_REASON_PROPERTY;
+const char last_last_reboot_reason_property[] = "sys.boot.reason.last";
const char bootloader_reboot_reason_property[] = "ro.boot.bootreason";
// Scrub, Sanitize, Standardize and Enhance the boot reason string supplied.
@@ -869,86 +869,7 @@
}
}
- // The following battery test should migrate to a default system health HAL
-
- // Let us not worry if the reboot command was issued, for the cases of
- // reboot -p, reboot <no reason>, reboot cold, reboot warm and reboot hard.
- // Same for bootloader and ro.boot.bootreasons of this set, but a dead
- // battery could conceivably lead to these, so worthy of override.
- if (isBluntRebootReason(ret)) {
- // Heuristic to determine if shutdown possibly because of a dead battery?
- // Really a hail-mary pass to find it in last klog content ...
- static const int battery_dead_threshold = 2; // percent
- static const char battery[] = "healthd: battery l=";
- const pstoreConsole console(content);
- size_t pos = console.rfind(battery); // last one
- std::string digits;
- if (pos != std::string::npos) {
- digits = content.substr(pos + strlen(battery), strlen("100 "));
- // correct common errors
- correctForBitError(digits, "100 ");
- if (digits[0] == '!') digits[0] = '1';
- if (digits[1] == '!') digits[1] = '1';
- }
- const char* endptr = digits.c_str();
- unsigned level = 0;
- while (::isdigit(*endptr)) {
- level *= 10;
- level += *endptr++ - '0';
- // make sure no leading zeros, except zero itself, and range check.
- if ((level == 0) || (level > 100)) break;
- }
- // example bit error rate issues for 10%
- // 'l=10 ' no bits in error
- // 'l=00 ' single bit error (fails above)
- // 'l=1 ' single bit error
- // 'l=0 ' double bit error
- // There are others, not typically critical because of 2%
- // battery_dead_threshold. KISS check, make sure second
- // character after digit sequence is not a space.
- if ((level <= 100) && (endptr != digits.c_str()) && (endptr[0] == ' ') && (endptr[1] != ' ')) {
- LOG(INFO) << "Battery level at shutdown " << level << "%";
- if (level <= battery_dead_threshold) {
- ret = "shutdown,battery";
- }
- } else { // Most likely
- digits = ""; // reset digits
-
- // Content buffer no longer will have console data. Beware if more
- // checks added below, that depend on parsing console content.
- content = "";
-
- LOG(DEBUG) << "Can not find last low battery in last console messages";
- android_logcat_context ctx = create_android_logcat();
- FILE* fp = android_logcat_popen(&ctx, "logcat -b kernel -v brief -d");
- if (fp != nullptr) {
- android::base::ReadFdToString(fileno(fp), &content);
- }
- android_logcat_pclose(&ctx, fp);
- static const char logcat_battery[] = "W/healthd ( 0): battery l=";
-
- pos = content.find(logcat_battery); // The first one it finds.
- if (pos != std::string::npos) {
- digits = content.substr(pos + strlen(logcat_battery), strlen("100 "));
- }
- endptr = digits.c_str();
- level = 0;
- while (::isdigit(*endptr)) {
- level *= 10;
- level += *endptr++ - '0';
- // make sure no leading zeros, except zero itself, and range check.
- if ((level == 0) || (level > 100)) break;
- }
- if ((level <= 100) && (endptr != digits.c_str()) && (*endptr == ' ')) {
- LOG(INFO) << "Battery level at startup " << level << "%";
- if (level <= battery_dead_threshold) {
- ret = "shutdown,battery";
- }
- } else {
- LOG(DEBUG) << "Can not find first battery level in dmesg or logcat";
- }
- }
- }
+ // TODO: use the HAL to get battery level (http://b/77725702).
// Is there a controlled shutdown hint in last_reboot_reason_property?
if (isBluntRebootReason(ret)) {
@@ -985,10 +906,6 @@
}
LOG(INFO) << "Canonical boot reason: " << ret;
- if (isKernelRebootReason(ret) && (GetProperty(last_reboot_reason_property) != "")) {
- // Rewrite as it must be old news, kernel reasons trump user space.
- SetProperty(last_reboot_reason_property, ret);
- }
return ret;
}
@@ -1118,6 +1035,15 @@
const std::string system_boot_reason(BootReasonStrToReason(bootloader_boot_reason));
// Record the scrubbed system_boot_reason to the property
SetProperty(system_reboot_reason_property, system_boot_reason);
+ // Shift last_reboot_reason_property to last_last_reboot_reason_property
+ std::string last_boot_reason(GetProperty(last_reboot_reason_property));
+ if (last_boot_reason.empty() || isKernelRebootReason(system_boot_reason)) {
+ last_boot_reason = system_boot_reason;
+ } else {
+ transformReason(last_boot_reason);
+ }
+ SetProperty(last_last_reboot_reason_property, last_boot_reason);
+ SetProperty(last_reboot_reason_property, "");
}
// Records several metrics related to the time it takes to boot the device,
diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp
index b016e23..360ea95 100644
--- a/debuggerd/debuggerd.cpp
+++ b/debuggerd/debuggerd.cpp
@@ -20,6 +20,7 @@
#include <string.h>
#include <limits>
+#include <string_view>
#include <thread>
#include <android-base/file.h>
@@ -33,9 +34,10 @@
using android::base::unique_fd;
static void usage(int exit_code) {
- fprintf(stderr, "usage: debuggerd [-b] PID\n");
+ fprintf(stderr, "usage: debuggerd [-bj] PID\n");
fprintf(stderr, "\n");
fprintf(stderr, "-b, --backtrace just a backtrace rather than a full tombstone\n");
+ fprintf(stderr, "-j collect java traces\n");
_exit(exit_code);
}
@@ -58,8 +60,19 @@
int main(int argc, char* argv[]) {
if (argc <= 1) usage(0);
if (argc > 3) usage(1);
- if (argc == 3 && strcmp(argv[1], "-b") != 0 && strcmp(argv[1], "--backtrace") != 0) usage(1);
- bool backtrace_only = argc == 3;
+
+ DebuggerdDumpType dump_type = kDebuggerdTombstone;
+
+ if (argc == 3) {
+ std::string_view flag = argv[1];
+ if (flag == "-b" || flag == "--backtrace") {
+ dump_type = kDebuggerdNativeBacktrace;
+ } else if (flag == "-j") {
+ dump_type = kDebuggerdJavaBacktrace;
+ } else {
+ usage(1);
+ }
+ }
pid_t pid;
if (!android::base::ParseInt(argv[argc - 1], &pid, 1, std::numeric_limits<pid_t>::max())) {
@@ -90,8 +103,7 @@
}
std::thread redirect_thread = spawn_redirect_thread(std::move(piperead));
- if (!debuggerd_trigger_dump(pid, backtrace_only ? kDebuggerdNativeBacktrace : kDebuggerdTombstone,
- 0, std::move(pipewrite))) {
+ if (!debuggerd_trigger_dump(pid, dump_type, 0, std::move(pipewrite))) {
redirect_thread.join();
errx(1, "failed to dump process %d", pid);
}
diff --git a/init/host_import_parser.cpp b/init/host_import_parser.cpp
index faf6fc1..93e363f 100644
--- a/init/host_import_parser.cpp
+++ b/init/host_import_parser.cpp
@@ -23,22 +23,17 @@
namespace android {
namespace init {
-Result<Success> HostImportParser::ParseSection(std::vector<std::string>&& args,
- const std::string& filename, int line) {
+Result<Success> HostImportParser::ParseSection(std::vector<std::string>&& args, const std::string&,
+ int) {
if (args.size() != 2) {
return Error() << "single argument needed for import\n";
}
- auto import_path = args[1];
+ return Success();
+}
- if (StartsWith(import_path, "/system") || StartsWith(import_path, "/product") ||
- StartsWith(import_path, "/odm") || StartsWith(import_path, "/vendor")) {
- import_path = out_dir_ + "/" + import_path;
- } else {
- import_path = out_dir_ + "/root/" + import_path;
- }
-
- return ImportParser::ParseSection({"import", import_path}, filename, line);
+Result<Success> HostImportParser::ParseLineSection(std::vector<std::string>&&, int) {
+ return Error() << "Unexpected line found after import statement";
}
} // namespace init
diff --git a/init/host_import_parser.h b/init/host_import_parser.h
index e2980b2..52b8891 100644
--- a/init/host_import_parser.h
+++ b/init/host_import_parser.h
@@ -19,21 +19,16 @@
#include <string>
#include <vector>
-#include "import_parser.h"
#include "parser.h"
namespace android {
namespace init {
-class HostImportParser : public ImportParser {
+class HostImportParser : public SectionParser {
public:
- HostImportParser(const std::string& out_dir, Parser* parser)
- : ImportParser(parser), out_dir_(out_dir) {}
- Result<Success> ParseSection(std::vector<std::string>&& args, const std::string& filename,
- int line) override;
-
- private:
- std::string out_dir_;
+ HostImportParser() {}
+ Result<Success> ParseSection(std::vector<std::string>&& args, const std::string&, int) override;
+ Result<Success> ParseLineSection(std::vector<std::string>&&, int) override;
};
} // namespace init
diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp
index d6884af..7e93b44 100644
--- a/init/host_init_verifier.cpp
+++ b/init/host_init_verifier.cpp
@@ -17,6 +17,7 @@
#include <errno.h>
#include <pwd.h>
#include <stdio.h>
+#include <stdlib.h>
#include <iostream>
#include <string>
@@ -45,11 +46,11 @@
using android::base::ReadFileToString;
using android::base::Split;
-static std::string out_dir;
+static std::string passwd_file;
static std::vector<std::pair<std::string, int>> GetVendorPasswd() {
std::string passwd;
- if (!ReadFileToString(out_dir + "/vendor/etc/passwd", &passwd)) {
+ if (!ReadFileToString(passwd_file, &passwd)) {
return {};
}
@@ -102,6 +103,14 @@
}
}
+ unsigned int oem_uid;
+ if (sscanf(login, "oem_%u", &oem_uid) == 1) {
+ snprintf(static_name, sizeof(static_name), "%s", login);
+ static_passwd.pw_uid = oem_uid;
+ static_passwd.pw_gid = oem_uid;
+ return &static_passwd;
+ }
+
errno = ENOENT;
return nullptr;
}
@@ -118,20 +127,14 @@
int main(int argc, char** argv) {
android::base::InitLogging(argv, &android::base::StdioLogger);
android::base::SetMinimumLogSeverity(android::base::ERROR);
- if (argc != 3) {
- LOG(ERROR) << "Usage: " << argv[0] << " <out directory> <properties>";
- return -1;
+
+ if (argc != 2 && argc != 3) {
+ LOG(ERROR) << "Usage: " << argv[0] << " <init rc file> [passwd file]";
+ return EXIT_FAILURE;
}
- out_dir = argv[1];
-
- auto properties = Split(argv[2], ",");
- for (const auto& property : properties) {
- auto split_property = Split(property, "=");
- if (split_property.size() != 2) {
- continue;
- }
- property_set(split_property[0], split_property[1]);
+ if (argc == 3) {
+ passwd_file = argv[2];
}
const BuiltinFunctionMap function_map;
@@ -141,22 +144,23 @@
Parser parser;
parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sl, nullptr));
parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr));
- parser.AddSectionParser("import", std::make_unique<HostImportParser>(out_dir, &parser));
+ parser.AddSectionParser("import", std::make_unique<HostImportParser>());
- if (!parser.ParseConfig(argv[1] + "/root/init.rc"s)) {
- LOG(ERROR) << "Failed to find root init.rc script";
- return -1;
+ if (!parser.ParseConfig(argv[1])) {
+ LOG(ERROR) << "Failed to open init rc script '" << argv[1] << "'";
+ return EXIT_FAILURE;
}
if (parser.parse_error_count() > 0) {
- LOG(ERROR) << "Init script parsing failed with " << parser.parse_error_count() << " errors";
- return -1;
+ LOG(ERROR) << "Failed to parse init script '" << argv[1] << "' with "
+ << parser.parse_error_count() << " errors";
+ return EXIT_FAILURE;
}
- return 0;
+ return EXIT_SUCCESS;
}
} // namespace init
} // namespace android
int main(int argc, char** argv) {
- android::init::main(argc, argv);
+ return android::init::main(argc, argv);
}
diff --git a/init/uevent_listener.cpp b/init/uevent_listener.cpp
index 81486e1..24b14c4 100644
--- a/init/uevent_listener.cpp
+++ b/init/uevent_listener.cpp
@@ -23,11 +23,7 @@
#include <memory>
-#include <android-base/chrono_utils.h>
-#include <android-base/file.h>
#include <android-base/logging.h>
-#include <android-base/scopeguard.h>
-#include <android-base/stringprintf.h>
#include <cutils/uevent.h>
namespace android {
@@ -134,19 +130,9 @@
int fd = openat(dfd, "uevent", O_WRONLY);
if (fd >= 0) {
- android::base::Timer t;
write(fd, "add\n", 4);
- const std::string fd_path = android::base::StringPrintf("/proc/self/fd/%d", fd);
- std::string uevent_file_path;
- android::base::Readlink(fd_path, &uevent_file_path);
close(fd);
- auto guard = android::base::make_scope_guard([&t, &uevent_file_path]() {
- if (t.duration() > 50ms) {
- LOG(WARNING) << "ReadUevent took " << t << " on '" << uevent_file_path << "'";
- }
- });
-
Uevent uevent;
while (ReadUevent(&uevent)) {
if (callback(uevent) == ListenerAction::kStop) return ListenerAction::kStop;
diff --git a/libsync/include/ndk/sync.h b/libsync/include/ndk/sync.h
index a786d3e..49f01e1 100644
--- a/libsync/include/ndk/sync.h
+++ b/libsync/include/ndk/sync.h
@@ -32,8 +32,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= __ANDROID_API_O__
-
/* Fences indicate the status of an asynchronous task. They are initially
* in unsignaled state (0), and make a one-time transition to either signaled
* (1) or error (< 0) state. A sync file is a collection of one or more fences;
@@ -63,14 +61,14 @@
* The original fences remain valid, and the caller is responsible for closing
* them.
*/
-int32_t sync_merge(const char *name, int32_t fd1, int32_t fd2);
+int32_t sync_merge(const char* name, int32_t fd1, int32_t fd2) __INTRODUCED_IN(26);
/**
* Retrieve detailed information about a sync file and its fences.
*
* The returned sync_file_info must be freed by calling sync_file_info_free().
*/
-struct sync_file_info *sync_file_info(int32_t fd);
+struct sync_file_info* sync_file_info(int32_t fd) __INTRODUCED_IN(26);
/**
* Get the array of fence infos from the sync file's info.
@@ -88,9 +86,7 @@
}
/** Free a struct sync_file_info structure */
-void sync_file_info_free(struct sync_file_info *info);
-
-#endif // __ANDROID_API__ >= __ANDROID_API_O__
+void sync_file_info_free(struct sync_file_info* info) __INTRODUCED_IN(26);
__END_DECLS
diff --git a/logcat/.clang-format b/logcat/.clang-format
deleted file mode 100644
index 393c309..0000000
--- a/logcat/.clang-format
+++ /dev/null
@@ -1,11 +0,0 @@
-BasedOnStyle: Google
-AllowShortFunctionsOnASingleLine: false
-
-CommentPragmas: NOLINT:.*
-DerivePointerAlignment: false
-IndentWidth: 4
-PointerAlignment: Left
-TabWidth: 4
-PenaltyExcessCharacter: 32
-
-Cpp11BracedListStyle: false
diff --git a/logcat/Android.bp b/logcat/Android.bp
index 01beb53..b0563a6 100644
--- a/logcat/Android.bp
+++ b/logcat/Android.bp
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2006-2017 The Android Open Source Project
+// Copyright (C) 2006 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.
@@ -31,25 +31,13 @@
logtags: ["event.logtags"],
}
-cc_library {
- name: "liblogcat",
-
- defaults: ["logcat_defaults"],
- srcs: [
- "logcat.cpp",
- "getopt_long.cpp",
- "logcat_system.cpp",
- ],
- export_include_dirs: ["include"],
-}
-
cc_binary {
name: "logcat",
defaults: ["logcat_defaults"],
- shared_libs: ["liblogcat"],
srcs: [
"logcat_main.cpp",
+ "logcat.cpp",
],
}
@@ -57,9 +45,9 @@
name: "logcatd",
defaults: ["logcat_defaults"],
- shared_libs: ["liblogcat"],
srcs: [
"logcatd_main.cpp",
+ "logcat.cpp",
],
}
diff --git a/logcat/getopt_long.cpp b/logcat/getopt_long.cpp
deleted file mode 100644
index da99906..0000000
--- a/logcat/getopt_long.cpp
+++ /dev/null
@@ -1,401 +0,0 @@
-/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */
-/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
-
-/*
- * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Sponsored in part by the Defense Advanced Research Projects
- * Agency (DARPA) and Air Force Research Laboratory, Air Force
- * Materiel Command, USAF, under agreement number F39502-99-1-0512.
- */
-/*-
- * Copyright (c) 2000 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Dieter Baron and Thomas Klausner.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/cdefs.h>
-
-#include <log/getopt.h>
-
-#define PRINT_ERROR ((context->opterr) && (*options != ':'))
-
-#define FLAG_PERMUTE 0x01 // permute non-options to the end of argv
-#define FLAG_ALLARGS 0x02 // treat non-options as args to option "-1"
-
-// return values
-#define BADCH (int)'?'
-#define BADARG ((*options == ':') ? (int)':' : (int)'?')
-#define INORDER (int)1
-
-#define D_PREFIX 0
-#define DD_PREFIX 1
-#define W_PREFIX 2
-
-// Compute the greatest common divisor of a and b.
-static int gcd(int a, int b) {
- int c = a % b;
- while (c) {
- a = b;
- b = c;
- c = a % b;
- }
- return b;
-}
-
-// Exchange the block from nonopt_start to nonopt_end with the block from
-// nonopt_end to opt_end (keeping the same order of arguments in each block).
-// Returns optind - (nonopt_end - nonopt_start) for convenience.
-static int permute_args(getopt_context* context, char* const* nargv) {
- // compute lengths of blocks and number and size of cycles
- int nnonopts = context->nonopt_end - context->nonopt_start;
- int nopts = context->optind - context->nonopt_end;
- int ncycle = gcd(nnonopts, nopts);
- int cyclelen = (context->optind - context->nonopt_start) / ncycle;
-
- for (int i = 0; i < ncycle; i++) {
- int cstart = context->nonopt_end + i;
- int pos = cstart;
- for (int j = 0; j < cyclelen; j++) {
- if (pos >= context->nonopt_end) {
- pos -= nnonopts;
- } else {
- pos += nopts;
- }
- char* swap = nargv[pos];
- const_cast<char**>(nargv)[pos] = nargv[cstart];
- const_cast<char**>(nargv)[cstart] = swap;
- }
- }
- return context->optind - (context->nonopt_end - context->nonopt_start);
-}
-
-// parse_long_options_r --
-// Parse long options in argc/argv argument vector.
-// Returns -1 if short_too is set and the option does not match long_options.
-static int parse_long_options_r(char* const* nargv, const char* options,
- const struct option* long_options, int* idx,
- bool short_too, struct getopt_context* context) {
- const char* current_argv = context->place;
- const char* current_dash;
- switch (context->dash_prefix) {
- case D_PREFIX:
- current_dash = "-";
- break;
- case DD_PREFIX:
- current_dash = "--";
- break;
- case W_PREFIX:
- current_dash = "-W ";
- break;
- default:
- current_dash = "";
- break;
- }
- context->optind++;
-
- const char* has_equal;
- size_t current_argv_len;
- if (!!(has_equal = strchr(current_argv, '='))) {
- // argument found (--option=arg)
- current_argv_len = has_equal - current_argv;
- has_equal++;
- } else {
- current_argv_len = strlen(current_argv);
- }
-
- int match = -1;
- bool exact_match = false;
- bool second_partial_match = false;
- for (int i = 0; long_options[i].name; i++) {
- // find matching long option
- if (strncmp(current_argv, long_options[i].name, current_argv_len)) {
- continue;
- }
-
- if (strlen(long_options[i].name) == current_argv_len) {
- // exact match
- match = i;
- exact_match = true;
- break;
- }
- // If this is a known short option, don't allow
- // a partial match of a single character.
- if (short_too && current_argv_len == 1) continue;
-
- if (match == -1) { // first partial match
- match = i;
- } else if (long_options[i].has_arg != long_options[match].has_arg ||
- long_options[i].flag != long_options[match].flag ||
- long_options[i].val != long_options[match].val) {
- second_partial_match = true;
- }
- }
- if (!exact_match && second_partial_match) {
- // ambiguous abbreviation
- if (PRINT_ERROR) {
- fprintf(context->optstderr ?: stderr,
- "option `%s%.*s' is ambiguous", current_dash,
- (int)current_argv_len, current_argv);
- }
- context->optopt = 0;
- return BADCH;
- }
- if (match != -1) { // option found
- if (long_options[match].has_arg == no_argument && has_equal) {
- if (PRINT_ERROR) {
- fprintf(context->optstderr ?: stderr,
- "option `%s%.*s' doesn't allow an argument",
- current_dash, (int)current_argv_len, current_argv);
- }
- // XXX: GNU sets optopt to val regardless of flag
- context->optopt =
- long_options[match].flag ? 0 : long_options[match].val;
- return BADCH;
- }
- if (long_options[match].has_arg == required_argument ||
- long_options[match].has_arg == optional_argument) {
- if (has_equal) {
- context->optarg = has_equal;
- } else if (long_options[match].has_arg == required_argument) {
- // optional argument doesn't use next nargv
- context->optarg = nargv[context->optind++];
- }
- }
- if ((long_options[match].has_arg == required_argument) &&
- !context->optarg) {
- // Missing argument; leading ':' indicates no error
- // should be generated.
- if (PRINT_ERROR) {
- fprintf(context->optstderr ?: stderr,
- "option `%s%s' requires an argument", current_dash,
- current_argv);
- }
- // XXX: GNU sets optopt to val regardless of flag
- context->optopt =
- long_options[match].flag ? 0 : long_options[match].val;
- context->optind--;
- return BADARG;
- }
- } else { // unknown option
- if (short_too) {
- context->optind--;
- return -1;
- }
- if (PRINT_ERROR) {
- fprintf(context->optstderr ?: stderr, "unrecognized option `%s%s'",
- current_dash, current_argv);
- }
- context->optopt = 0;
- return BADCH;
- }
- if (idx) *idx = match;
- if (long_options[match].flag) {
- *long_options[match].flag = long_options[match].val;
- return 0;
- }
- return long_options[match].val;
-}
-
-// getopt_long_r --
-// Parse argc/argv argument vector.
-int getopt_long_r(int nargc, char* const* nargv, const char* options,
- const struct option* long_options, int* idx,
- struct getopt_context* context) {
- if (!options) return -1;
-
- // XXX Some GNU programs (like cvs) set optind to 0 instead of
- // XXX using optreset. Work around this braindamage.
- if (!context->optind) context->optind = context->optreset = 1;
-
- // Disable GNU extensions if options string begins with a '+'.
- int flags = FLAG_PERMUTE;
- if (*options == '-') {
- flags |= FLAG_ALLARGS;
- } else if (*options == '+') {
- flags &= ~FLAG_PERMUTE;
- }
- if (*options == '+' || *options == '-') options++;
-
- context->optarg = nullptr;
- if (context->optreset) context->nonopt_start = context->nonopt_end = -1;
-start:
- if (context->optreset || !*context->place) { // update scanning pointer
- context->optreset = 0;
- if (context->optind >= nargc) { // end of argument vector
- context->place = EMSG;
- if (context->nonopt_end != -1) {
- // do permutation, if we have to
- context->optind = permute_args(context, nargv);
- } else if (context->nonopt_start != -1) {
- // If we skipped non-options, set optind to the first of them.
- context->optind = context->nonopt_start;
- }
- context->nonopt_start = context->nonopt_end = -1;
- return -1;
- }
- if (*(context->place = nargv[context->optind]) != '-' ||
- context->place[1] == '\0') {
- context->place = EMSG; // found non-option
- if (flags & FLAG_ALLARGS) {
- // GNU extension: return non-option as argument to option 1
- context->optarg = nargv[context->optind++];
- return INORDER;
- }
- if (!(flags & FLAG_PERMUTE)) {
- // If no permutation wanted, stop parsing at first non-option.
- return -1;
- }
- // do permutation
- if (context->nonopt_start == -1) {
- context->nonopt_start = context->optind;
- } else if (context->nonopt_end != -1) {
- context->nonopt_start = permute_args(context, nargv);
- context->nonopt_end = -1;
- }
- context->optind++;
- // process next argument
- goto start;
- }
- if (context->nonopt_start != -1 && context->nonopt_end == -1) {
- context->nonopt_end = context->optind;
- }
-
- // If we have "-" do nothing, if "--" we are done.
- if (context->place[1] != '\0' && *++(context->place) == '-' &&
- context->place[1] == '\0') {
- context->optind++;
- context->place = EMSG;
- // We found an option (--), so if we skipped
- // non-options, we have to permute.
- if (context->nonopt_end != -1) {
- context->optind = permute_args(context, nargv);
- }
- context->nonopt_start = context->nonopt_end = -1;
- return -1;
- }
- }
-
- int optchar;
- // Check long options if:
- // 1) we were passed some
- // 2) the arg is not just "-"
- // 3) either the arg starts with -- we are getopt_long_only()
- if (long_options && context->place != nargv[context->optind] &&
- (*context->place == '-')) {
- bool short_too = false;
- context->dash_prefix = D_PREFIX;
- if (*context->place == '-') {
- context->place++; // --foo long option
- context->dash_prefix = DD_PREFIX;
- } else if (*context->place != ':' && strchr(options, *context->place)) {
- short_too = true; // could be short option too
- }
-
- optchar = parse_long_options_r(nargv, options, long_options, idx,
- short_too, context);
- if (optchar != -1) {
- context->place = EMSG;
- return optchar;
- }
- }
-
- const char* oli; // option letter list index
- if ((optchar = (int)*(context->place)++) == (int)':' ||
- (optchar == (int)'-' && *context->place != '\0') ||
- !(oli = strchr(options, optchar))) {
- // If the user specified "-" and '-' isn't listed in
- // options, return -1 (non-option) as per POSIX.
- // Otherwise, it is an unknown option character (or ':').
- if (optchar == (int)'-' && *context->place == '\0') return -1;
- if (!*context->place) context->optind++;
- if (PRINT_ERROR) {
- fprintf(context->optstderr ?: stderr, "invalid option -- %c",
- optchar);
- }
- context->optopt = optchar;
- return BADCH;
- }
-
- static const char recargchar[] = "option requires an argument -- %c";
- if (long_options && optchar == 'W' && oli[1] == ';') {
- // -W long-option
- if (*context->place) { // no space
- ; // NOTHING
- } else if (++(context->optind) >= nargc) { // no arg
- context->place = EMSG;
- if (PRINT_ERROR) {
- fprintf(context->optstderr ?: stderr, recargchar, optchar);
- }
- context->optopt = optchar;
- return BADARG;
- } else { // white space
- context->place = nargv[context->optind];
- }
- context->dash_prefix = W_PREFIX;
- optchar = parse_long_options_r(nargv, options, long_options, idx, false,
- context);
- context->place = EMSG;
- return optchar;
- }
- if (*++oli != ':') { // doesn't take argument
- if (!*context->place) context->optind++;
- } else { // takes (optional) argument
- context->optarg = nullptr;
- if (*context->place) { // no white space
- context->optarg = context->place;
- } else if (oli[1] != ':') { // arg not optional
- if (++(context->optind) >= nargc) { // no arg
- context->place = EMSG;
- if (PRINT_ERROR) {
- fprintf(context->optstderr ?: stderr, recargchar, optchar);
- }
- context->optopt = optchar;
- return BADARG;
- }
- context->optarg = nargv[context->optind];
- }
- context->place = EMSG;
- context->optind++;
- }
- // dump back option letter
- return optchar;
-}
diff --git a/logcat/include/log/getopt.h b/logcat/include/log/getopt.h
deleted file mode 100644
index 0da2b10..0000000
--- a/logcat/include/log/getopt.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#ifndef _LOG_GETOPT_H_
-#define _LOG_GETOPT_H_
-
-#ifndef __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE
-#ifndef __ANDROID_API__
-#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1
-#elif __ANDROID_API__ > 24 /* > Nougat */
-#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1
-#else
-#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 0
-#endif
-#endif
-
-#if __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE
-
-#include <getopt.h>
-#include <sys/cdefs.h>
-
-struct getopt_context {
- int opterr;
- int optind;
- int optopt;
- int optreset;
- const char* optarg;
- FILE* optstderr; /* NULL defaults to stderr */
- /* private */
- const char* place;
- int nonopt_start;
- int nonopt_end;
- int dash_prefix;
- /* expansion space */
- int __extra__;
- void* __stuff__;
-};
-
-#define EMSG ""
-#define NO_PREFIX (-1)
-
-#define INIT_GETOPT_CONTEXT(context) \
- context = { 1, 1, '?', 0, NULL, NULL, EMSG, -1, -1, NO_PREFIX, 0, NULL }
-
-__BEGIN_DECLS
-int getopt_long_r(int nargc, char* const* nargv, const char* options,
- const struct option* long_options, int* idx,
- struct getopt_context* context);
-
-__END_DECLS
-
-#endif /* __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE */
-
-#endif /* !_LOG_GETOPT_H_ */
diff --git a/logcat/include/log/logcat.h b/logcat/include/log/logcat.h
deleted file mode 100644
index 009672c..0000000
--- a/logcat/include/log/logcat.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2005-2017 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.
- */
-
-#ifndef _LIBS_LOGCAT_H /* header boilerplate */
-#define _LIBS_LOGCAT_H
-
-#include <stdio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE
-#ifndef __ANDROID_API__
-#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1
-#elif __ANDROID_API__ > 24 /* > Nougat */
-#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1
-#else
-#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 0
-#endif
-#endif
-
-#if __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE
-
-/* For managing an in-process logcat function, rather than forking/execing
- *
- * It also serves as the basis for the logcat command.
- *
- * The following C API allows a logcat instance to be created, run
- * to completion, and then release all the associated resources.
- */
-
-/*
- * The opaque context
- */
-#ifndef __android_logcat_context_defined /* typedef boilerplate */
-#define __android_logcat_context_defined
-typedef struct android_logcat_context_internal* android_logcat_context;
-#endif
-
-/* Creates a context associated with this logcat instance
- *
- * Returns a pointer to the context, or a NULL on error.
- */
-android_logcat_context create_android_logcat();
-
-/* Collects and outputs the logcat data to output and error file descriptors
- *
- * Will block, performed in-thread and in-process
- *
- * The output file descriptor variable, if greater than or equal to 0, is
- * where the output (ie: stdout) will be sent. The file descriptor is closed
- * on android_logcat_destroy which terminates the instance, or when an -f flag
- * (output redirect to a file) is present in the command. The error file
- * descriptor variable, if greater than or equal to 0, is where the error
- * stream (ie: stderr) will be sent, also closed on android_logcat_destroy.
- * The error file descriptor can be set to equal to the output file descriptor,
- * which will mix output and error stream content, and will defer closure of
- * the file descriptor on -f flag redirection. Negative values for the file
- * descriptors will use stdout and stderr FILE references respectively
- * internally, and will not close the references as noted above.
- *
- * Return value is 0 for success, non-zero for errors.
- */
-int android_logcat_run_command(android_logcat_context ctx, int output, int error,
- int argc, char* const* argv, char* const* envp);
-
-/* Will not block, performed in-process
- *
- * Starts a thread, opens a pipe, returns reading end fd, saves off argv.
- * The command supports 2>&1 (mix content) and 2>/dev/null (drop content) for
- * scripted error (stderr) redirection.
- */
-int android_logcat_run_command_thread(android_logcat_context ctx, int argc,
- char* const* argv, char* const* envp);
-int android_logcat_run_command_thread_running(android_logcat_context ctx);
-
-/* Finished with context
- *
- * Kill the command thread ASAP (if any), and free up all associated resources.
- *
- * Return value is the result of the android_logcat_run_command, or
- * non-zero for any errors.
- */
-int android_logcat_destroy(android_logcat_context* ctx);
-
-/* derived helpers */
-
-/*
- * In-process thread that acts like somewhat like libc-like system and popen
- * respectively. Can not handle shell scripting, only pure calls to the
- * logcat operations. The android_logcat_system is a wrapper for the
- * create_android_logcat, android_logcat_run_command and android_logcat_destroy
- * API above. The android_logcat_popen is a wrapper for the
- * android_logcat_run_command_thread API above. The android_logcat_pclose is
- * a wrapper for a reasonable wait until output has subsided for command
- * completion, fclose on the FILE pointer and the android_logcat_destroy API.
- */
-int android_logcat_system(const char* command);
-FILE* android_logcat_popen(android_logcat_context* ctx, const char* command);
-int android_logcat_pclose(android_logcat_context* ctx, FILE* output);
-
-#endif /* __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _LIBS_LOGCAT_H */
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index ff85f54..0f56337 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -14,12 +14,15 @@
* limitations under the License.
*/
+#include "logcat.h"
+
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
#include <math.h>
#include <pthread.h>
#include <sched.h>
@@ -47,8 +50,6 @@
#include <cutils/sched_policy.h>
#include <cutils/sockets.h>
#include <log/event_tag_map.h>
-#include <log/getopt.h>
-#include <log/logcat.h>
#include <log/logprint.h>
#include <private/android_logger.h>
#include <system/thread_defs.h>
@@ -854,14 +855,8 @@
// net for stability dealing with possible mistaken inputs.
static const char delimiters[] = ",:; \t\n\r\f";
- struct getopt_context optctx;
- INIT_GETOPT_CONTEXT(optctx);
- optctx.opterr = !!context->error;
- optctx.optstderr = context->error;
-
- for (;;) {
- int ret;
-
+ optind = 0;
+ while (true) {
int option_index = 0;
// list of long-argument only strings for later comparison
static const char pid_str[] = "pid";
@@ -902,19 +897,18 @@
};
// clang-format on
- ret = getopt_long_r(argc, argv, ":cdDhLt:T:gG:sQf:r:n:v:b:BSpP:m:e:",
- long_options, &option_index, &optctx);
- if (ret < 0) break;
+ int c = getopt_long(argc, argv, ":cdDhLt:T:gG:sQf:r:n:v:b:BSpP:m:e:", long_options,
+ &option_index);
+ if (c == -1) break;
- switch (ret) {
+ switch (c) {
case 0:
// only long options
if (long_options[option_index].name == pid_str) {
// ToDo: determine runtime PID_MAX?
- if (!getSizeTArg(optctx.optarg, &pid, 1)) {
+ if (!getSizeTArg(optarg, &pid, 1)) {
logcat_panic(context, HELP_TRUE, "%s %s out of range\n",
- long_options[option_index].name,
- optctx.optarg);
+ long_options[option_index].name, optarg);
goto exit;
}
break;
@@ -924,11 +918,9 @@
ANDROID_LOG_NONBLOCK;
// ToDo: implement API that supports setting a wrap timeout
size_t dummy = ANDROID_LOG_WRAP_DEFAULT_TIMEOUT;
- if (optctx.optarg &&
- !getSizeTArg(optctx.optarg, &dummy, 1)) {
+ if (optarg && !getSizeTArg(optarg, &dummy, 1)) {
logcat_panic(context, HELP_TRUE, "%s %s out of range\n",
- long_options[option_index].name,
- optctx.optarg);
+ long_options[option_index].name, optarg);
goto exit;
}
if ((dummy != ANDROID_LOG_WRAP_DEFAULT_TIMEOUT) &&
@@ -949,8 +941,7 @@
break;
}
if (long_options[option_index].name == id_str) {
- setId = (optctx.optarg && optctx.optarg[0]) ? optctx.optarg
- : nullptr;
+ setId = (optarg && optarg[0]) ? optarg : nullptr;
}
break;
@@ -978,32 +969,27 @@
mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
// FALLTHRU
case 'T':
- if (strspn(optctx.optarg, "0123456789") !=
- strlen(optctx.optarg)) {
- char* cp = parseTime(tail_time, optctx.optarg);
+ if (strspn(optarg, "0123456789") != strlen(optarg)) {
+ char* cp = parseTime(tail_time, optarg);
if (!cp) {
- logcat_panic(context, HELP_FALSE,
- "-%c \"%s\" not in time format\n", ret,
- optctx.optarg);
+ logcat_panic(context, HELP_FALSE, "-%c \"%s\" not in time format\n", c,
+ optarg);
goto exit;
}
if (*cp) {
- char c = *cp;
+ char ch = *cp;
*cp = '\0';
if (context->error) {
- fprintf(
- context->error,
- "WARNING: -%c \"%s\"\"%c%s\" time truncated\n",
- ret, optctx.optarg, c, cp + 1);
+ fprintf(context->error, "WARNING: -%c \"%s\"\"%c%s\" time truncated\n",
+ c, optarg, ch, cp + 1);
}
- *cp = c;
+ *cp = ch;
}
} else {
- if (!getSizeTArg(optctx.optarg, &tail_lines, 1)) {
+ if (!getSizeTArg(optarg, &tail_lines, 1)) {
if (context->error) {
- fprintf(context->error,
- "WARNING: -%c %s invalid, setting to 1\n",
- ret, optctx.optarg);
+ fprintf(context->error, "WARNING: -%c %s invalid, setting to 1\n", c,
+ optarg);
}
tail_lines = 1;
}
@@ -1015,21 +1001,19 @@
break;
case 'e':
- context->regex = new pcrecpp::RE(optctx.optarg);
+ context->regex = new pcrecpp::RE(optarg);
break;
case 'm': {
- if (!getSizeTArg(optctx.optarg, &context->maxCount)) {
+ if (!getSizeTArg(optarg, &context->maxCount)) {
logcat_panic(context, HELP_FALSE,
- "-%c \"%s\" isn't an "
- "integer greater than zero\n",
- ret, optctx.optarg);
+ "-%c \"%s\" isn't an integer greater than zero\n", c, optarg);
goto exit;
}
} break;
case 'g':
- if (!optctx.optarg) {
+ if (!optarg) {
getLogSize = true;
break;
}
@@ -1037,8 +1021,8 @@
case 'G': {
char* cp;
- if (strtoll(optctx.optarg, &cp, 0) > 0) {
- setLogSize = strtoll(optctx.optarg, &cp, 0);
+ if (strtoll(optarg, &cp, 0) > 0) {
+ setLogSize = strtoll(optarg, &cp, 0);
} else {
setLogSize = 0;
}
@@ -1071,19 +1055,18 @@
} break;
case 'p':
- if (!optctx.optarg) {
+ if (!optarg) {
getPruneList = true;
break;
}
// FALLTHRU
case 'P':
- setPruneList = optctx.optarg;
+ setPruneList = optarg;
break;
case 'b': {
- std::unique_ptr<char, void (*)(void*)> buffers(
- strdup(optctx.optarg), free);
+ std::unique_ptr<char, void (*)(void*)> buffers(strdup(optarg), free);
char* arg = buffers.get();
unsigned idMask = 0;
char* sv = nullptr; // protect against -ENOMEM above
@@ -1147,40 +1130,33 @@
case 'f':
if ((tail_time == log_time::EPOCH) && !tail_lines) {
- tail_time = lastLogTime(optctx.optarg);
+ tail_time = lastLogTime(optarg);
}
// redirect output to a file
- context->outputFileName = optctx.optarg;
+ context->outputFileName = optarg;
break;
case 'r':
- if (!getSizeTArg(optctx.optarg, &context->logRotateSizeKBytes,
- 1)) {
- logcat_panic(context, HELP_TRUE,
- "Invalid parameter \"%s\" to -r\n",
- optctx.optarg);
+ if (!getSizeTArg(optarg, &context->logRotateSizeKBytes, 1)) {
+ logcat_panic(context, HELP_TRUE, "Invalid parameter \"%s\" to -r\n", optarg);
goto exit;
}
break;
case 'n':
- if (!getSizeTArg(optctx.optarg, &context->maxRotatedLogs, 1)) {
- logcat_panic(context, HELP_TRUE,
- "Invalid parameter \"%s\" to -n\n",
- optctx.optarg);
+ if (!getSizeTArg(optarg, &context->maxRotatedLogs, 1)) {
+ logcat_panic(context, HELP_TRUE, "Invalid parameter \"%s\" to -n\n", optarg);
goto exit;
}
break;
case 'v': {
- if (!strcmp(optctx.optarg, "help") ||
- !strcmp(optctx.optarg, "--help")) {
+ if (!strcmp(optarg, "help") || !strcmp(optarg, "--help")) {
show_format_help(context);
context->retval = EXIT_SUCCESS;
goto exit;
}
- std::unique_ptr<char, void (*)(void*)> formats(
- strdup(optctx.optarg), free);
+ std::unique_ptr<char, void (*)(void*)> formats(strdup(optarg), free);
char* arg = formats.get();
char* sv = nullptr; // protect against -ENOMEM above
while (!!(arg = strtok_r(arg, delimiters, &sv))) {
@@ -1300,8 +1276,7 @@
break;
case ':':
- logcat_panic(context, HELP_TRUE,
- "Option -%c needs an argument\n", optctx.optopt);
+ logcat_panic(context, HELP_TRUE, "Option -%c needs an argument\n", optopt);
goto exit;
case 'h':
@@ -1310,8 +1285,7 @@
goto exit;
default:
- logcat_panic(context, HELP_TRUE, "Unrecognized Option %c\n",
- optctx.optopt);
+ logcat_panic(context, HELP_TRUE, "Unrecognized Option %c\n", optopt);
goto exit;
}
}
@@ -1400,7 +1374,7 @@
"Invalid filter expression in logcat args\n");
goto exit;
}
- } else if (argc == optctx.optind) {
+ } else if (argc == optind) {
// Add from environment variable
const char* env_tags_orig = android::getenv(context, "ANDROID_LOG_TAGS");
@@ -1416,7 +1390,7 @@
}
} else {
// Add from commandline
- for (int i = optctx.optind ; i < argc ; i++) {
+ for (int i = optind ; i < argc ; i++) {
// skip stderr redirections of _all_ kinds
if ((argv[i][0] == '2') && (argv[i][1] == '>')) continue;
// skip stdout redirections of _all_ kinds
@@ -1707,105 +1681,6 @@
return __logcat(context);
}
-// starts a thread, opens a pipe, returns reading end.
-int android_logcat_run_command_thread(android_logcat_context ctx,
- int argc, char* const* argv,
- char* const* envp) {
- android_logcat_context_internal* context = ctx;
-
- int save_errno = EBUSY;
- if ((context->fds[0] >= 0) || (context->fds[1] >= 0)) goto exit;
-
- if (pipe(context->fds) < 0) {
- save_errno = errno;
- goto exit;
- }
-
- pthread_attr_t attr;
- if (pthread_attr_init(&attr)) {
- save_errno = errno;
- goto close_exit;
- }
-
- struct sched_param param;
- memset(¶m, 0, sizeof(param));
- pthread_attr_setschedparam(&attr, ¶m);
- pthread_attr_setschedpolicy(&attr, SCHED_BATCH);
- if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) {
- save_errno = errno;
- goto pthread_attr_exit;
- }
-
- context->stop = false;
- context->thread_stopped = false;
- context->output_fd = context->fds[1];
- // save off arguments so they remain while thread is active.
- for (int i = 0; i < argc; ++i) {
- context->args.push_back(std::string(argv[i]));
- }
- // save off environment so they remain while thread is active.
- if (envp) for (size_t i = 0; envp[i]; ++i) {
- context->envs.push_back(std::string(envp[i]));
- }
-
- for (auto& str : context->args) {
- context->argv_hold.push_back(str.c_str());
- }
- context->argv_hold.push_back(nullptr);
- for (auto& str : context->envs) {
- context->envp_hold.push_back(str.c_str());
- }
- context->envp_hold.push_back(nullptr);
-
- context->argc = context->argv_hold.size() - 1;
- context->argv = (char* const*)&context->argv_hold[0];
- context->envp = (char* const*)&context->envp_hold[0];
-
-#ifdef DEBUG
- fprintf(stderr, "argv[%d] = {", context->argc);
- for (auto str : context->argv_hold) {
- fprintf(stderr, " \"%s\"", str ?: "nullptr");
- }
- fprintf(stderr, " }\n");
- fflush(stderr);
-#endif
- context->retval = EXIT_SUCCESS;
- if (pthread_create(&context->thr, &attr,
- (void*(*)(void*))__logcat, context)) {
- save_errno = errno;
- goto argv_exit;
- }
- pthread_attr_destroy(&attr);
-
- return context->fds[0];
-
-argv_exit:
- context->argv_hold.clear();
- context->args.clear();
- context->envp_hold.clear();
- context->envs.clear();
-pthread_attr_exit:
- pthread_attr_destroy(&attr);
-close_exit:
- close(context->fds[0]);
- context->fds[0] = -1;
- close(context->fds[1]);
- context->fds[1] = -1;
-exit:
- errno = save_errno;
- context->stop = true;
- context->thread_stopped = true;
- context->retval = EXIT_FAILURE;
- return -1;
-}
-
-// test if the thread is still doing 'stuff'
-int android_logcat_run_command_thread_running(android_logcat_context ctx) {
- android_logcat_context_internal* context = ctx;
-
- return context->thread_stopped == false;
-}
-
// Finished with context
int android_logcat_destroy(android_logcat_context* ctx) {
android_logcat_context_internal* context = *ctx;
diff --git a/logcat/logcat.h b/logcat/logcat.h
new file mode 100644
index 0000000..85ed7da
--- /dev/null
+++ b/logcat/logcat.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2005-2017 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 <stdio.h>
+
+/*
+ * The opaque context
+ */
+typedef struct android_logcat_context_internal* android_logcat_context;
+
+/* Creates a context associated with this logcat instance
+ *
+ * Returns a pointer to the context, or a NULL on error.
+ */
+android_logcat_context create_android_logcat();
+
+/* Collects and outputs the logcat data to output and error file descriptors
+ *
+ * Will block, performed in-thread and in-process
+ *
+ * The output file descriptor variable, if greater than or equal to 0, is
+ * where the output (ie: stdout) will be sent. The file descriptor is closed
+ * on android_logcat_destroy which terminates the instance, or when an -f flag
+ * (output redirect to a file) is present in the command. The error file
+ * descriptor variable, if greater than or equal to 0, is where the error
+ * stream (ie: stderr) will be sent, also closed on android_logcat_destroy.
+ * The error file descriptor can be set to equal to the output file descriptor,
+ * which will mix output and error stream content, and will defer closure of
+ * the file descriptor on -f flag redirection. Negative values for the file
+ * descriptors will use stdout and stderr FILE references respectively
+ * internally, and will not close the references as noted above.
+ *
+ * Return value is 0 for success, non-zero for errors.
+ */
+int android_logcat_run_command(android_logcat_context ctx, int output, int error, int argc,
+ char* const* argv, char* const* envp);
+
+/* Finished with context
+ *
+ * Kill the command thread ASAP (if any), and free up all associated resources.
+ *
+ * Return value is the result of the android_logcat_run_command, or
+ * non-zero for any errors.
+ */
+int android_logcat_destroy(android_logcat_context* ctx);
diff --git a/logcat/logcat_main.cpp b/logcat/logcat_main.cpp
index 9477e79..ecfa2ba 100644
--- a/logcat/logcat_main.cpp
+++ b/logcat/logcat_main.cpp
@@ -17,7 +17,7 @@
#include <signal.h>
#include <stdlib.h>
-#include <log/logcat.h>
+#include "logcat.h"
int main(int argc, char** argv, char** envp) {
android_logcat_context ctx = create_android_logcat();
diff --git a/logcat/logcat_system.cpp b/logcat/logcat_system.cpp
deleted file mode 100644
index 6dfd110..0000000
--- a/logcat/logcat_system.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2017 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 <ctype.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <string>
-#include <vector>
-
-#include <log/logcat.h>
-
-static std::string unquote(const char*& cp, const char*& delim) {
- if ((*cp == '\'') || (*cp == '"')) {
- // KISS: Simple quotes. Do not handle the case
- // of concatenation like "blah"foo'bar'
- char quote = *cp++;
- delim = strchr(cp, quote);
- if (!delim) delim = cp + strlen(cp);
- std::string str(cp, delim);
- if (*delim) ++delim;
- return str;
- }
- delim = strpbrk(cp, " \t\f\r\n");
- if (!delim) delim = cp + strlen(cp);
- return std::string(cp, delim);
-}
-
-static bool __android_logcat_parse(const char* command,
- std::vector<std::string>& args,
- std::vector<std::string>& envs) {
- for (const char *delim, *cp = command; cp && *cp; cp = delim) {
- while (isspace(*cp)) ++cp;
- if ((args.size() == 0) && (*cp != '=') && !isdigit(*cp)) {
- const char* env = cp;
- while (isalnum(*cp) || (*cp == '_')) ++cp;
- if (cp && (*cp == '=')) {
- std::string str(env, ++cp);
- str += unquote(cp, delim);
- envs.push_back(str);
- continue;
- }
- cp = env;
- }
- args.push_back(unquote(cp, delim));
- if ((args.size() == 1) && (args[0] != "logcat") &&
- (args[0] != "/system/bin/logcat")) {
- return false;
- }
- }
- return args.size() != 0;
-}
-
-FILE* android_logcat_popen(android_logcat_context* ctx, const char* command) {
- *ctx = NULL;
-
- std::vector<std::string> args;
- std::vector<std::string> envs;
- if (!__android_logcat_parse(command, args, envs)) return NULL;
-
- std::vector<const char*> argv;
- for (auto& str : args) {
- argv.push_back(str.c_str());
- }
- argv.push_back(NULL);
-
- std::vector<const char*> envp;
- for (auto& str : envs) {
- envp.push_back(str.c_str());
- }
- envp.push_back(NULL);
-
- *ctx = create_android_logcat();
- if (!*ctx) return NULL;
-
- int fd = android_logcat_run_command_thread(
- *ctx, argv.size() - 1, (char* const*)&argv[0], (char* const*)&envp[0]);
- argv.clear();
- args.clear();
- envp.clear();
- envs.clear();
- if (fd < 0) {
- android_logcat_destroy(ctx);
- return NULL;
- }
-
- int duped = dup(fd);
- FILE* retval = fdopen(duped, "reb");
- if (!retval) {
- close(duped);
- android_logcat_destroy(ctx);
- }
- return retval;
-}
-
-int android_logcat_pclose(android_logcat_context* ctx, FILE* output) {
- if (*ctx) {
- static const useconds_t wait_sample = 20000;
- // Wait two seconds maximum
- for (size_t retry = ((2 * 1000000) + wait_sample - 1) / wait_sample;
- android_logcat_run_command_thread_running(*ctx) && retry; --retry) {
- usleep(wait_sample);
- }
- }
-
- if (output) fclose(output);
- return android_logcat_destroy(ctx);
-}
-
-int android_logcat_system(const char* command) {
- std::vector<std::string> args;
- std::vector<std::string> envs;
- if (!__android_logcat_parse(command, args, envs)) return -1;
-
- std::vector<const char*> argv;
- for (auto& str : args) {
- argv.push_back(str.c_str());
- }
- argv.push_back(NULL);
-
- std::vector<const char*> envp;
- for (auto& str : envs) {
- envp.push_back(str.c_str());
- }
- envp.push_back(NULL);
-
- android_logcat_context ctx = create_android_logcat();
- if (!ctx) return -1;
- /* Command return value */
- int retval = android_logcat_run_command(ctx, -1, -1, argv.size() - 1,
- (char* const*)&argv[0],
- (char* const*)&envp[0]);
- /* destroy return value */
- int ret = android_logcat_destroy(&ctx);
- /* Paranoia merging any discrepancies between the two return values */
- if (!ret) ret = retval;
- return ret;
-}
diff --git a/logcat/logcatd_main.cpp b/logcat/logcatd_main.cpp
index 9109eb1..c131846 100644
--- a/logcat/logcatd_main.cpp
+++ b/logcat/logcatd_main.cpp
@@ -21,7 +21,7 @@
#include <string>
#include <vector>
-#include <log/logcat.h>
+#include "logcat.h"
int main(int argc, char** argv, char** envp) {
android_logcat_context ctx = create_android_logcat();
diff --git a/logcat/tests/Android.mk b/logcat/tests/Android.mk
index defd3c4..66f6724 100644
--- a/logcat/tests/Android.mk
+++ b/logcat/tests/Android.mk
@@ -32,7 +32,6 @@
benchmark_src_files := \
logcat_benchmark.cpp \
- exec_benchmark.cpp \
# Build benchmarks for the device. Run with:
# adb shell /data/nativetest/logcat-benchmarks/logcat-benchmarks
@@ -41,7 +40,7 @@
LOCAL_MODULE_TAGS := $(test_tags)
LOCAL_CFLAGS += $(test_c_flags)
LOCAL_SRC_FILES := $(benchmark_src_files)
-LOCAL_SHARED_LIBRARIES := libbase liblogcat
+LOCAL_SHARED_LIBRARIES := libbase
include $(BUILD_NATIVE_BENCHMARK)
# -----------------------------------------------------------------------------
@@ -51,7 +50,6 @@
test_src_files := \
logcat_test.cpp \
logcatd_test.cpp \
- liblogcat_test.cpp \
# Build tests for the device (with .so). Run with:
# adb shell /data/nativetest/logcat-unit-tests/logcat-unit-tests
@@ -59,6 +57,6 @@
LOCAL_MODULE := $(test_module_prefix)unit-tests
LOCAL_MODULE_TAGS := $(test_tags)
LOCAL_CFLAGS += $(test_c_flags)
-LOCAL_SHARED_LIBRARIES := liblog libbase liblogcat
+LOCAL_SHARED_LIBRARIES := liblog libbase
LOCAL_SRC_FILES := $(test_src_files)
include $(BUILD_NATIVE_TEST)
diff --git a/logcat/tests/exec_benchmark.cpp b/logcat/tests/exec_benchmark.cpp
deleted file mode 100644
index c30a5f5..0000000
--- a/logcat/tests/exec_benchmark.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2017 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 <stdio.h>
-
-#include <android-base/file.h>
-#include <benchmark/benchmark.h>
-#include <log/logcat.h>
-
-// Dump the statistics and report results
-
-static void logcat_popen_libc(benchmark::State& state, const char* cmd) {
- while (state.KeepRunning()) {
- FILE* fp = popen(cmd, "r");
- std::string ret;
- android::base::ReadFdToString(fileno(fp), &ret);
- pclose(fp);
- }
-}
-
-static void BM_logcat_stat_popen_libc(benchmark::State& state) {
- logcat_popen_libc(state, "logcat -b all -S");
-}
-BENCHMARK(BM_logcat_stat_popen_libc);
-
-static void logcat_popen_liblogcat(benchmark::State& state, const char* cmd) {
- while (state.KeepRunning()) {
- android_logcat_context ctx;
- FILE* fp = android_logcat_popen(&ctx, cmd);
- std::string ret;
- android::base::ReadFdToString(fileno(fp), &ret);
- android_logcat_pclose(&ctx, fp);
- }
-}
-
-static void BM_logcat_stat_popen_liblogcat(benchmark::State& state) {
- logcat_popen_liblogcat(state, "logcat -b all -S");
-}
-BENCHMARK(BM_logcat_stat_popen_liblogcat);
-
-static void logcat_system_libc(benchmark::State& state, const char* cmd) {
- while (state.KeepRunning()) {
- system(cmd);
- }
-}
-
-static void BM_logcat_stat_system_libc(benchmark::State& state) {
- logcat_system_libc(state, "logcat -b all -S >/dev/null 2>/dev/null");
-}
-BENCHMARK(BM_logcat_stat_system_libc);
-
-static void logcat_system_liblogcat(benchmark::State& state, const char* cmd) {
- while (state.KeepRunning()) {
- android_logcat_system(cmd);
- }
-}
-
-static void BM_logcat_stat_system_liblogcat(benchmark::State& state) {
- logcat_system_liblogcat(state, "logcat -b all -S >/dev/null 2>/dev/null");
-}
-BENCHMARK(BM_logcat_stat_system_liblogcat);
-
-// Dump the logs and report results
-
-static void BM_logcat_dump_popen_libc(benchmark::State& state) {
- logcat_popen_libc(state, "logcat -b all -d");
-}
-BENCHMARK(BM_logcat_dump_popen_libc);
-
-static void BM_logcat_dump_popen_liblogcat(benchmark::State& state) {
- logcat_popen_liblogcat(state, "logcat -b all -d");
-}
-BENCHMARK(BM_logcat_dump_popen_liblogcat);
-
-static void BM_logcat_dump_system_libc(benchmark::State& state) {
- logcat_system_libc(state, "logcat -b all -d >/dev/null 2>/dev/null");
-}
-BENCHMARK(BM_logcat_dump_system_libc);
-
-static void BM_logcat_dump_system_liblogcat(benchmark::State& state) {
- logcat_system_liblogcat(state, "logcat -b all -d >/dev/null 2>/dev/null");
-}
-BENCHMARK(BM_logcat_dump_system_liblogcat);
diff --git a/logcat/tests/liblogcat_test.cpp b/logcat/tests/liblogcat_test.cpp
deleted file mode 100644
index c8a00da..0000000
--- a/logcat/tests/liblogcat_test.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2017 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 <log/logcat.h>
-
-#define logcat_define(context) android_logcat_context context
-#define logcat_popen(context, command) android_logcat_popen(&(context), command)
-#define logcat_pclose(context, fp) android_logcat_pclose(&(context), fp)
-#define logcat_system(command) android_logcat_system(command)
-#define logcat liblogcat
-
-#include "logcat_test.cpp"
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index 786fb14..cc1632a 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -37,12 +37,6 @@
#include <log/log.h>
#include <log/log_event_list.h>
-#ifndef logcat_popen
-#define logcat_define(context)
-#define logcat_popen(context, command) popen((command), "r")
-#define logcat_pclose(context, fp) pclose(fp)
-#define logcat_system(command) system(command)
-#endif
#ifndef logcat_executable
#define USING_LOGCAT_EXECUTABLE_DEFAULT
#define logcat_executable "logcat"
@@ -78,7 +72,6 @@
TEST(logcat, buckets) {
FILE* fp;
- logcat_define(ctx);
#undef LOG_TAG
#define LOG_TAG "inject.buckets"
@@ -90,10 +83,9 @@
__android_log_bswrite(0, logcat_executable ".inject.buckets");
rest();
- ASSERT_TRUE(NULL !=
- (fp = logcat_popen(
- ctx, logcat_executable
- " -b radio -b events -b system -b main -d 2>/dev/null")));
+ ASSERT_TRUE(NULL != (fp = popen(logcat_executable
+ " -b radio -b events -b system -b main -d 2>/dev/null",
+ "r")));
char buffer[BIG_BUFFER];
@@ -111,7 +103,7 @@
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
EXPECT_EQ(ids, 15);
@@ -120,7 +112,6 @@
TEST(logcat, event_tag_filter) {
FILE* fp;
- logcat_define(ctx);
#undef LOG_TAG
#define LOG_TAG "inject.filter"
@@ -135,7 +126,7 @@
logcat_executable
" -b radio -b system -b main --pid=%d -d -s inject.filter 2>/dev/null",
getpid());
- ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, command.c_str())));
+ ASSERT_TRUE(NULL != (fp = popen(command.c_str(), "r")));
char buffer[BIG_BUFFER];
@@ -145,7 +136,7 @@
if (strncmp(begin, buffer, sizeof(begin) - 1)) ++count;
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
// logcat, liblogcat and logcatd test instances result in the progression
// of 3, 6 and 9 for our counts as each round is performed.
@@ -191,7 +182,6 @@
do {
FILE* fp;
- logcat_define(ctx);
char needle[32];
time_t now;
@@ -205,9 +195,8 @@
#endif
strftime(needle, sizeof(needle), "[ %Y-", ptm);
- ASSERT_TRUE(NULL != (fp = logcat_popen(
- ctx, logcat_executable
- " -v long -v year -b all -t 3 2>/dev/null")));
+ ASSERT_TRUE(NULL !=
+ (fp = popen(logcat_executable " -v long -v year -b all -t 3 2>/dev/null", "r")));
char buffer[BIG_BUFFER];
@@ -218,7 +207,7 @@
++count;
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
} while ((count < 3) && --tries && inject(3 - count));
@@ -268,12 +257,10 @@
do {
FILE* fp;
- logcat_define(ctx);
- ASSERT_TRUE(NULL !=
- (fp = logcat_popen(ctx, logcat_executable
- " -v long -v America/Los_Angeles "
- "-b all -t 3 2>/dev/null")));
+ ASSERT_TRUE(NULL != (fp = popen(logcat_executable
+ " -v long -v America/Los_Angeles -b all -t 3 2>/dev/null",
+ "r")));
char buffer[BIG_BUFFER];
@@ -287,7 +274,7 @@
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
} while ((count < 3) && --tries && inject(3 - count));
@@ -296,11 +283,11 @@
TEST(logcat, ntz) {
FILE* fp;
- logcat_define(ctx);
- ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, logcat_executable
- " -v long -v America/Los_Angeles -v "
- "zone -b all -t 3 2>/dev/null")));
+ ASSERT_TRUE(NULL !=
+ (fp = popen(logcat_executable
+ " -v long -v America/Los_Angeles -v zone -b all -t 3 2>/dev/null",
+ "r")));
char buffer[BIG_BUFFER];
@@ -312,7 +299,7 @@
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
ASSERT_EQ(0, count);
}
@@ -330,8 +317,7 @@
"ANDROID_PRINTF_LOG=long logcat -b all -t %d 2>/dev/null", num);
FILE* fp;
- logcat_define(ctx);
- ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
+ ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
count = 0;
@@ -339,7 +325,7 @@
++count;
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
} while ((count < num) && --tries && inject(num - count));
@@ -377,8 +363,7 @@
do {
snprintf(buffer, sizeof(buffer), "%s -t 10 2>&1", cmd);
- logcat_define(ctx);
- ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
+ ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
count = 0;
while ((input = fgetLongTime(buffer, sizeof(buffer), fp))) {
@@ -391,7 +376,7 @@
free(last_timestamp);
last_timestamp = strdup(input);
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
} while ((count < 10) && --tries && inject(10 - count));
@@ -401,8 +386,7 @@
EXPECT_TRUE(second_timestamp != NULL);
snprintf(buffer, sizeof(buffer), "%s -t '%s' 2>&1", cmd, first_timestamp);
- logcat_define(ctx);
- ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
+ ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
int second_count = 0;
int last_timestamp_count = -1;
@@ -442,7 +426,7 @@
last_timestamp_count = second_count;
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
EXPECT_TRUE(found);
if (!found) {
@@ -483,10 +467,8 @@
ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
FILE* fp;
- logcat_define(ctx);
ASSERT_TRUE(NULL !=
- (fp = logcat_popen(ctx, logcat_executable
- " -v brief -b events -t 100 2>/dev/null")));
+ (fp = popen(logcat_executable " -v brief -b events -t 100 2>/dev/null", "r")));
char buffer[BIG_BUFFER];
@@ -507,7 +489,7 @@
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
ASSERT_EQ(1, count);
}
@@ -521,12 +503,9 @@
FILE* fp[256]; // does this count as a multitude!
memset(fp, 0, sizeof(fp));
- logcat_define(ctx[sizeof(fp) / sizeof(fp[0])]);
size_t num = 0;
do {
- EXPECT_TRUE(NULL !=
- (fp[num] = logcat_popen(ctx[num], logcat_executable
- " -v brief -b events -t 100")));
+ EXPECT_TRUE(NULL != (fp[num] = popen(logcat_executable " -v brief -b events -t 100", "r")));
if (!fp[num]) {
fprintf(stderr,
"WARNING: limiting to %zu simultaneous logcat operations\n",
@@ -556,7 +535,7 @@
}
}
- logcat_pclose(ctx[idx], fp[idx]);
+ pclose(fp[idx]);
}
ASSERT_EQ(num, count);
@@ -564,10 +543,9 @@
static int get_groups(const char* cmd) {
FILE* fp;
- logcat_define(ctx);
// NB: crash log only available in user space
- EXPECT_TRUE(NULL != (fp = logcat_popen(ctx, cmd)));
+ EXPECT_TRUE(NULL != (fp = popen(cmd, "r")));
if (fp == NULL) {
return 0;
@@ -631,7 +609,7 @@
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
return count;
}
@@ -815,7 +793,7 @@
snprintf(command, sizeof(command), comm, buf);
int ret;
- EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
+ EXPECT_FALSE(IsFalse(ret = system(command), command));
if (!ret) {
snprintf(command, sizeof(command), "ls -s %s 2>/dev/null", buf);
@@ -861,7 +839,7 @@
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir);
int ret;
- EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
+ EXPECT_FALSE(IsFalse(ret = system(command), command));
if (!ret) {
snprintf(command, sizeof(command), "ls %s 2>/dev/null", tmp_out_dir);
@@ -920,7 +898,7 @@
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
int ret;
- EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
+ EXPECT_FALSE(IsFalse(ret = system(command), command));
if (ret) {
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
EXPECT_FALSE(IsFalse(system(command), command));
@@ -969,7 +947,7 @@
// re-run the command, it should only add a few lines more content if it
// continues where it left off.
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
- EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
+ EXPECT_FALSE(IsFalse(ret = system(command), command));
if (ret) {
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
EXPECT_FALSE(IsFalse(system(command), command));
@@ -1052,7 +1030,7 @@
tmp_out_dir, log_filename, num_val);
int ret;
- EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
+ EXPECT_FALSE(IsFalse(ret = system(command), command));
if (ret) {
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
EXPECT_FALSE(IsFalse(system(command), command));
@@ -1082,7 +1060,7 @@
strcat(command, clear_cmd);
int ret;
- EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
+ EXPECT_FALSE(IsFalse(ret = system(command), command));
if (ret) {
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
EXPECT_FALSE(system(command));
@@ -1120,7 +1098,7 @@
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
- int ret = logcat_system(command);
+ int ret = system(command);
if (ret) {
fprintf(stderr, "system(\"%s\")=%d", command, ret);
return -1;
@@ -1194,7 +1172,7 @@
" -b all -d"
" -f /das/nein/gerfingerpoken/logcat/log.txt"
" -n 256 -r 1024";
- EXPECT_FALSE(IsFalse(0 == logcat_system(command), command));
+ EXPECT_FALSE(IsFalse(0 == system(command), command));
}
#ifndef logcat
@@ -1329,10 +1307,7 @@
#endif
static bool get_white_black(char** list) {
- FILE* fp;
- logcat_define(ctx);
-
- fp = logcat_popen(ctx, logcat_executable " -p 2>/dev/null");
+ FILE* fp = popen(logcat_executable " -p 2>/dev/null", "r");
if (fp == NULL) {
fprintf(stderr, "ERROR: logcat -p 2>/dev/null\n");
return false;
@@ -1360,19 +1335,15 @@
asprintf(list, "%s", buf);
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
return *list != NULL;
}
static bool set_white_black(const char* list) {
- FILE* fp;
- logcat_define(ctx);
-
char buffer[BIG_BUFFER];
-
snprintf(buffer, sizeof(buffer), logcat_executable " -P '%s' 2>&1",
list ? list : "");
- fp = logcat_popen(ctx, buffer);
+ FILE* fp = popen(buffer, "r");
if (fp == NULL) {
fprintf(stderr, "ERROR: %s\n", buffer);
return false;
@@ -1391,10 +1362,10 @@
continue;
}
fprintf(stderr, "%s\n", buf);
- logcat_pclose(ctx, fp);
+ pclose(fp);
return false;
}
- return logcat_pclose(ctx, fp) == 0;
+ return pclose(fp) == 0;
}
TEST(logcat, white_black_adjust) {
@@ -1429,7 +1400,6 @@
TEST(logcat, regex) {
FILE* fp;
- logcat_define(ctx);
int count = 0;
char buffer[BIG_BUFFER];
@@ -1450,7 +1420,7 @@
// Let the logs settle
rest();
- ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
+ ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
while (fgets(buffer, sizeof(buffer), fp)) {
if (!strncmp(begin, buffer, sizeof(begin) - 1)) {
@@ -1462,14 +1432,13 @@
count++;
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
ASSERT_EQ(2, count);
}
TEST(logcat, maxcount) {
FILE* fp;
- logcat_define(ctx);
int count = 0;
char buffer[BIG_BUFFER];
@@ -1488,7 +1457,7 @@
rest();
- ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
+ ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
while (fgets(buffer, sizeof(buffer), fp)) {
if (!strncmp(begin, buffer, sizeof(begin) - 1)) {
@@ -1498,7 +1467,7 @@
count++;
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
ASSERT_EQ(3, count);
}
@@ -1510,13 +1479,7 @@
;
static bool End_to_End(const char* tag, const char* fmt, ...) {
- logcat_define(ctx);
- FILE* fp = logcat_popen(ctx, logcat_executable
- " -v brief"
- " -b events"
- " -v descriptive"
- " -t 100"
- " 2>/dev/null");
+ FILE* fp = popen(logcat_executable " -v brief -b events -v descriptive -t 100 2>/dev/null", "r");
if (!fp) {
fprintf(stderr, "End_to_End: popen failed");
return false;
@@ -1551,7 +1514,7 @@
}
}
- logcat_pclose(ctx, fp);
+ pclose(fp);
if ((count == 0) && (lastMatch.length() > 0)) {
// Help us pinpoint where things went wrong ...
@@ -1741,13 +1704,12 @@
}
static bool reportedSecurity(const char* command) {
- logcat_define(ctx);
- FILE* fp = logcat_popen(ctx, command);
+ FILE* fp = popen(command, "r");
if (!fp) return true;
std::string ret;
bool val = android::base::ReadFdToString(fileno(fp), &ret);
- logcat_pclose(ctx, fp);
+ pclose(fp);
if (!val) return true;
return std::string::npos != ret.find("'security'");
@@ -1762,13 +1724,12 @@
}
static size_t commandOutputSize(const char* command) {
- logcat_define(ctx);
- FILE* fp = logcat_popen(ctx, command);
+ FILE* fp = popen(command, "r");
if (!fp) return 0;
std::string ret;
if (!android::base::ReadFdToString(fileno(fp), &ret)) return 0;
- if (logcat_pclose(ctx, fp) != 0) return 0;
+ if (pclose(fp) != 0) return 0;
return ret.size();
}
diff --git a/mkbootimg/OWNERS b/mkbootimg/OWNERS
index 39448cf..3a00860 100644
--- a/mkbootimg/OWNERS
+++ b/mkbootimg/OWNERS
@@ -1 +1,2 @@
+hridya@google.com
tbao@google.com
diff --git a/rootdir/etc/ld.config.txt b/rootdir/etc/ld.config.txt
index a0b1996..eebad2b 100644
--- a/rootdir/etc/ld.config.txt
+++ b/rootdir/etc/ld.config.txt
@@ -52,6 +52,7 @@
namespace.default.permitted.paths += /system/${LIB}/extractors
namespace.default.permitted.paths += /system/${LIB}/hw
namespace.default.permitted.paths += /product/${LIB}
+namespace.default.permitted.paths += /system/product/${LIB}
# These are where odex files are located. libart has to be able to dlopen the files
namespace.default.permitted.paths += /system/framework
namespace.default.permitted.paths += /system/app
@@ -66,6 +67,9 @@
namespace.default.permitted.paths += /product/framework
namespace.default.permitted.paths += /product/app
namespace.default.permitted.paths += /product/priv-app
+namespace.default.permitted.paths += /system/product/framework
+namespace.default.permitted.paths += /system/product/app
+namespace.default.permitted.paths += /system/product/priv-app
namespace.default.permitted.paths += /data
namespace.default.permitted.paths += /mnt/expand
@@ -92,6 +96,10 @@
namespace.default.asan.permitted.paths += /product/framework
namespace.default.asan.permitted.paths += /product/app
namespace.default.asan.permitted.paths += /product/priv-app
+namespace.default.asan.permitted.paths += /system/product/${LIB}
+namespace.default.asan.permitted.paths += /system/product/framework
+namespace.default.asan.permitted.paths += /system/product/app
+namespace.default.asan.permitted.paths += /system/product/priv-app
namespace.default.asan.permitted.paths += /mnt/expand
###############################################################################