Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 40acb37

Browse files
author
Tom Cherry
committed
Move watchdogd out of init
We're moving past a world where static executables are needed, including watchdogd, so treat this like any other executable and place it in /system/bin. Bug: 73660730 Test: watchdogd still runs Change-Id: I1f7508fd55dce6e9ee72a6ab7a085011a76c0053
1 parent 081b710 commit 40acb37

File tree

16 files changed

+52
-73
lines changed

16 files changed

+52
-73
lines changed

init/Android.bp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ cc_library_static {
127127
"ueventd.cpp",
128128
"ueventd_parser.cpp",
129129
"util.cpp",
130-
"watchdogd.cpp",
131130
],
132131
whole_static_libs: ["libcap"],
133132
header_libs: ["bootimg_headers"],
@@ -157,7 +156,6 @@ cc_binary {
157156
srcs: ["main.cpp"],
158157
symlinks: [
159158
"sbin/ueventd",
160-
"sbin/watchdogd",
161159
],
162160
}
163161
*/

init/Android.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ LOCAL_REQUIRED_MODULES := \
9898
# Create symlinks.
9999
LOCAL_POST_INSTALL_CMD := $(hide) mkdir -p $(TARGET_ROOT_OUT)/sbin; \
100100
ln -sf ../init $(TARGET_ROOT_OUT)/sbin/ueventd; \
101-
ln -sf ../init $(TARGET_ROOT_OUT)/sbin/watchdogd
102101

103102
LOCAL_SANITIZE := signed-integer-overflow
104103
include $(BUILD_EXECUTABLE)

init/devices.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "util.h"
3535

3636
#ifdef _INIT_INIT_H
37-
#error "Do not include init.h in files used by ueventd or watchdogd; it will expose init's globals"
37+
#error "Do not include init.h in files used by ueventd; it will expose init's globals"
3838
#endif
3939

4040
using android::base::Basename;

init/host_init_stubs.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ uint32_t HandlePropertySet(const std::string&, const std::string&, const std::st
4141
}
4242

4343
// selinux.h
44-
bool SelinuxHasVendorInit() {
45-
return true;
44+
int SelinuxGetVendorAndroidVersion() {
45+
return 10000;
4646
}
47-
4847
void SelabelInitialize() {}
4948

5049
bool SelabelLookupFileContext(const std::string& key, int type, std::string* result) {

init/host_init_stubs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
#include <string>
2525

26+
// android/api-level.h
27+
#define __ANDROID_API_P__ 28
28+
2629
// sys/system_properties.h
2730
#define PROP_VALUE_MAX 92
2831

@@ -41,7 +44,7 @@ uint32_t HandlePropertySet(const std::string& name, const std::string& value,
4144
const std::string& source_context, const ucred& cr, std::string* error);
4245

4346
// selinux.h
44-
bool SelinuxHasVendorInit();
47+
int SelinuxGetVendorAndroidVersion();
4548
void SelabelInitialize();
4649
bool SelabelLookupFileContext(const std::string& key, int type, std::string* result);
4750

init/init.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
#include "sigchld_handler.h"
5959
#include "ueventd.h"
6060
#include "util.h"
61-
#include "watchdogd.h"
6261

6362
using namespace std::chrono_literals;
6463
using namespace std::string_literals;
@@ -617,10 +616,6 @@ int main(int argc, char** argv) {
617616
return ueventd_main(argc, argv);
618617
}
619618

620-
if (!strcmp(basename(argv[0]), "watchdogd")) {
621-
return watchdogd_main(argc, argv);
622-
}
623-
624619
if (argc > 1 && !strcmp(argv[1], "subcontext")) {
625620
android::base::InitLogging(argv, &android::base::KernelLogger);
626621
const BuiltinFunctionMap function_map;

init/init.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
namespace android {
3232
namespace init {
3333

34-
// Note: These globals are *only* valid in init, so they should not be used in ueventd,
35-
// watchdogd, or any files that may be included in those, such as devices.cpp and util.cpp.
34+
// Note: These globals are *only* valid in init, so they should not be used in ueventd
35+
// or any files that may be included in ueventd, such as devices.cpp and util.cpp.
3636
// TODO: Have an Init class and remove all globals.
3737
extern std::string default_console;
3838
extern std::vector<std::string> late_import_paths;

init/property_service.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "property_service.h"
1818

19+
#include <android/api-level.h>
1920
#include <ctype.h>
2021
#include <errno.h>
2122
#include <fcntl.h>
@@ -576,7 +577,7 @@ static void LoadProperties(char* data, const char* filter, const char* filename)
576577
size_t flen = 0;
577578

578579
const char* context = kInitContext.c_str();
579-
if (SelinuxHasVendorInit()) {
580+
if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_P__) {
580581
for (const auto& [path_prefix, secontext] : paths_and_secontexts) {
581582
if (StartsWith(filename, path_prefix)) {
582583
context = secontext;

init/selinux.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
#include "selinux.h"
4949

50+
#include <android/api-level.h>
5051
#include <fcntl.h>
5152
#include <stdlib.h>
5253
#include <sys/wait.h>
@@ -470,29 +471,27 @@ void SelinuxSetupKernelLogging() {
470471
selinux_set_callback(SELINUX_CB_LOG, cb);
471472
}
472473

473-
// This function checks whether the sepolicy supports vendor init.
474-
bool SelinuxHasVendorInit() {
474+
// This function returns the Android version with which the vendor SEPolicy was compiled.
475+
// It is used for version checks such as whether or not vendor_init should be used
476+
int SelinuxGetVendorAndroidVersion() {
475477
if (!IsSplitPolicyDevice()) {
476-
// If this device does not split sepolicy files, vendor_init will be available in the latest
477-
// monolithic sepolicy file.
478-
return true;
478+
// If this device does not split sepolicy files, it's not a Treble device and therefore,
479+
// we assume it's always on the latest platform.
480+
return __ANDROID_API_FUTURE__;
479481
}
480482

481483
std::string version;
482484
if (!GetVendorMappingVersion(&version)) {
483-
// Return true as the default if we failed to load the vendor sepolicy version.
484-
return true;
485+
LOG(FATAL) << "Could not read vendor SELinux version";
485486
}
486487

487488
int major_version;
488489
std::string major_version_str(version, 0, version.find('.'));
489490
if (!ParseInt(major_version_str, &major_version)) {
490-
PLOG(ERROR) << "Failed to parse the vendor sepolicy major version " << major_version_str;
491-
// Return true as the default if we failed to parse the major version.
492-
return true;
491+
PLOG(FATAL) << "Failed to parse the vendor sepolicy major version " << major_version_str;
493492
}
494493

495-
return major_version >= 28;
494+
return major_version;
496495
}
497496

498497
// selinux_android_file_context_handle() takes on the order of 10+ms to run, so we want to cache

init/selinux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void SelinuxInitialize();
2727
void SelinuxRestoreContext();
2828

2929
void SelinuxSetupKernelLogging();
30-
bool SelinuxHasVendorInit();
30+
int SelinuxGetVendorAndroidVersion();
3131

3232
void SelabelInitialize();
3333
bool SelabelLookupFileContext(const std::string& key, int type, std::string* result);

0 commit comments

Comments
 (0)