init: clean up logging initialization
Clean up a few mistakes in logging initialization
1) Only init needs to clear stdout/stderr/stdin, so remove this from
ueventd, watchdogd, and subcontext init
2) Only init should reboot due to FATAL errors. This was true even
before this change due to getpid() checks, but there's no reason to
not just use the DefaultAborter for other processes.
3) It's probably a mistake for FATAL logs in init to try to gracefully
shutdown the system, so simply call RebootSystem() here.
4) Lastly, remove log.cpp since it's not actually shared code anymore
Test: build
Change-Id: Ic8c323393dc7ee98ed6bb9691361b51d0d915267
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 0ba5c4a..94f206e 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -59,7 +59,6 @@
#include <android-base/unique_fd.h>
#include <selinux/android.h>
-#include "log.h"
#include "util.h"
using android::base::ParseInt;
@@ -448,10 +447,26 @@
selinux_android_restorecon("/sbin/sload.f2fs", 0);
}
+int SelinuxKlogCallback(int type, const char* fmt, ...) {
+ android::base::LogSeverity severity = android::base::ERROR;
+ if (type == SELINUX_WARNING) {
+ severity = android::base::WARNING;
+ } else if (type == SELINUX_INFO) {
+ severity = android::base::INFO;
+ }
+ char buf[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ android::base::KernelLogger(android::base::MAIN, severity, "selinux", nullptr, 0, buf);
+ return 0;
+}
+
// This function sets up SELinux logging to be written to kmsg, to match init's logging.
void SelinuxSetupKernelLogging() {
selinux_callback cb;
- cb.func_log = selinux_klog_callback;
+ cb.func_log = SelinuxKlogCallback;
selinux_set_callback(SELINUX_CB_LOG, cb);
}