summaryrefslogtreecommitdiffstats
path: root/init/init.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2017-08-22 15:41:03 -0700
committerTom Cherry <tomcherry@google.com>2017-08-23 10:09:21 -0700
commit6de21f11125941ea1b94fdeec754bacea3916fd5 (patch)
treec230a45f1202300f86ff3551e852612a3519ad73 /init/init.cpp
parent7f16cad877571ce8ef0808dcdb81234d61b771ca (diff)
downloadsystem_core-6de21f11125941ea1b94fdeec754bacea3916fd5.tar.gz
system_core-6de21f11125941ea1b94fdeec754bacea3916fd5.tar.bz2
system_core-6de21f11125941ea1b94fdeec754bacea3916fd5.zip
init: cleanup environment handling
Init keep its own copy of the environment that it uses for execve when starting services. This is unnecessary however as libc already has functions that mutate the environment and the environment that init uses is clean for starting services. This change removes init's copy of the environment and uses the libc functions instead. This also makes small clean-up to the way the Service class stores service specific environment variables. Test: boot bullhead Change-Id: I7c98a0b7aac9fa8f195ae33bd6a7515bb56faf78
Diffstat (limited to 'init/init.cpp')
-rw-r--r--init/init.cpp38
1 files changed, 2 insertions, 36 deletions
diff --git a/init/init.cpp b/init/init.cpp
index d0afac11d..e1bd3a2cb 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -71,8 +71,6 @@ static char qemu[32];
std::string default_console = "/dev/console";
-const char *ENV[32];
-
static int epoll_fd = -1;
static std::unique_ptr<Timer> waiting_for_prop(nullptr);
@@ -126,38 +124,6 @@ void register_epoll_handler(int fd, void (*fn)()) {
}
}
-/* add_environment - add "key=value" to the current environment */
-int add_environment(const char *key, const char *val)
-{
- size_t n;
- size_t key_len = strlen(key);
-
- /* The last environment entry is reserved to terminate the list */
- for (n = 0; n < (arraysize(ENV) - 1); n++) {
-
- /* Delete any existing entry for this key */
- if (ENV[n] != NULL) {
- size_t entry_key_len = strcspn(ENV[n], "=");
- if ((entry_key_len == key_len) && (strncmp(ENV[n], key, entry_key_len) == 0)) {
- free((char*)ENV[n]);
- ENV[n] = NULL;
- }
- }
-
- /* Add entry if a free slot is available */
- if (ENV[n] == NULL) {
- char* entry;
- asprintf(&entry, "%s=%s", key, val);
- ENV[n] = entry;
- return 0;
- }
- }
-
- LOG(ERROR) << "No env. room to store: '" << key << "':'" << val << "'";
-
- return -1;
-}
-
bool start_waiting_for_property(const char *name, const char *value)
{
if (waiting_for_prop) {
@@ -429,8 +395,6 @@ int main(int argc, char** argv) {
install_reboot_signal_handlers();
}
- add_environment("PATH", _PATH_DEFPATH);
-
bool is_first_stage = (getenv("INIT_SECOND_STAGE") == nullptr);
if (is_first_stage) {
@@ -439,6 +403,8 @@ int main(int argc, char** argv) {
// Clear the umask.
umask(0);
+ clearenv();
+ setenv("PATH", _PATH_DEFPATH, 1);
// Get the basic filesystem setup we need put together in the initramdisk
// on / and then we'll let the rc file figure out the rest.
mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");