Skip to content

Commit

Permalink
init: move "started at" environment var names to headers
Browse files Browse the repository at this point in the history
Move "FIRST_STAGE_STARTED_AT" to env_first_stage_started_at variable
in first_stage_init.h.  Move "SELINUX_STARTED_AT" to
env_selinux_started_at variable in selinux.h.

Test: build
Bug: 124491153
Bug: 129780532
Change-Id: I512d1835dcee5a3d034ac453b27b0709eed23cff
  • Loading branch information
Mark Salyzyn committed May 8, 2019
1 parent a6e6c7d commit 44505ec
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion init/first_stage_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int FirstStageMain(int argc, char** argv) {

SetInitAvbVersionInRecovery();

setenv("FIRST_STAGE_STARTED_AT", std::to_string(start_time.time_since_epoch().count()).c_str(),
setenv(kEnvFirstStageStartedAt, std::to_string(start_time.time_since_epoch().count()).c_str(),
1);

const char* path = "/system/bin/init";
Expand Down
2 changes: 2 additions & 0 deletions init/first_stage_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ namespace init {

int FirstStageMain(int argc, char** argv);

static constexpr char kEnvFirstStageStartedAt[] = "FIRST_STAGE_STARTED_AT";

} // namespace init
} // namespace android
11 changes: 5 additions & 6 deletions init/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "action_parser.h"
#include "boringssl_self_test.h"
#include "epoll.h"
#include "first_stage_init.h"
#include "first_stage_mount.h"
#include "import_parser.h"
#include "keychords.h"
Expand Down Expand Up @@ -630,20 +631,18 @@ static void UmountDebugRamdisk() {

static void RecordStageBoottimes(const boot_clock::time_point& second_stage_start_time) {
int64_t first_stage_start_time_ns = -1;
static constexpr char first_stage_started_at[] = "FIRST_STAGE_STARTED_AT";
if (auto first_stage_start_time_str = getenv(first_stage_started_at);
if (auto first_stage_start_time_str = getenv(kEnvFirstStageStartedAt);
first_stage_start_time_str) {
property_set("ro.boottime.init", first_stage_start_time_str);
android::base::ParseInt(first_stage_start_time_str, &first_stage_start_time_ns);
}
unsetenv(first_stage_started_at);
unsetenv(kEnvFirstStageStartedAt);

int64_t selinux_start_time_ns = -1;
static constexpr char selinux_started_at[] = "SELINUX_STARTED_AT";
if (auto selinux_start_time_str = getenv(selinux_started_at); selinux_start_time_str) {
if (auto selinux_start_time_str = getenv(kEnvSelinuxStartedAt); selinux_start_time_str) {
android::base::ParseInt(selinux_start_time_str, &selinux_start_time_ns);
}
unsetenv(selinux_started_at);
unsetenv(kEnvSelinuxStartedAt);

if (selinux_start_time_ns == -1) return;
if (first_stage_start_time_ns == -1) return;
Expand Down
2 changes: 1 addition & 1 deletion init/selinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ int SetupSelinux(char** argv) {
PLOG(FATAL) << "restorecon failed of /system/bin/init failed";
}

setenv("SELINUX_STARTED_AT", std::to_string(start_time.time_since_epoch().count()).c_str(), 1);
setenv(kEnvSelinuxStartedAt, std::to_string(start_time.time_since_epoch().count()).c_str(), 1);

const char* path = "/system/bin/init";
const char* args[] = {path, "second_stage", nullptr};
Expand Down
2 changes: 2 additions & 0 deletions init/selinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ bool SelabelLookupFileContextBestMatch(const std::string& key,
const std::vector<std::string>& aliases, int type,
std::string* result);

static constexpr char kEnvSelinuxStartedAt[] = "SELINUX_STARTED_AT";

} // namespace init
} // namespace android

Expand Down

0 comments on commit 44505ec

Please sign in to comment.