From 418b9be50018303cde79b423d4701b7fd86ddbdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Jul 2014 15:05:37 +0200 Subject: firstboot: add new component to query basic system settings on first boot, or when creating OS images offline A new tool "systemd-firstboot" can be used either interactively on boot, where it will query basic locale, timezone, hostname, root password information and set it. Or it can be used non-interactively from the command line when prepareing disk images for booting. When used non-inertactively the tool can either copy settings from the host, or take settings on the command line. $ systemd-firstboot --root=/path/to/my/new/root --copy-locale --copy-root-password --hostname=waldi The tool will be automatically invoked (interactively) now on first boot if /etc is found unpopulated. This also creates the infrastructure for generators to be notified via an environment variable whether they are running on the first boot, or not. --- src/core/execute.c | 2 +- src/core/main.c | 1 + src/core/manager.c | 12 +++++++++++- src/core/manager.h | 1 + src/core/shutdown.c | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/execute.c b/src/core/execute.c index 88d094e8cc..6e76bd5b50 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -571,7 +571,7 @@ static int ask_for_confirmation(char *response, char **argv) { if (!line) return -ENOMEM; - r = ask(response, "yns", "Execute %s? [Yes, No, Skip] ", line); + r = ask_char(response, "yns", "Execute %s? [Yes, No, Skip] ", line); restore_confirm_stdio(&saved_stdin, &saved_stdout); diff --git a/src/core/main.c b/src/core/main.c index a732c6945a..e1fc3f3718 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1648,6 +1648,7 @@ int main(int argc, char *argv[]) { m->initrd_timestamp = initrd_timestamp; m->security_start_timestamp = security_start_timestamp; m->security_finish_timestamp = security_finish_timestamp; + m->is_first_boot = empty_etc; manager_set_default_rlimits(m, arg_default_rlimit); manager_environment_add(m, NULL, arg_default_environment); diff --git a/src/core/manager.c b/src/core/manager.c index 0cb2044325..9d078c0af7 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2476,6 +2476,9 @@ void manager_check_finished(Manager *m) { /* Turn off confirm spawn now */ m->confirm_spawn = false; + /* This is no longer the first boot */ + m->is_first_boot = false; + if (dual_timestamp_is_set(&m->finish_timestamp)) return; @@ -2628,6 +2631,7 @@ void manager_run_generators(Manager *m) { _cleanup_closedir_ DIR *d = NULL; const char *generator_path; const char *argv[5]; + const char *env[2]; int r; assert(m); @@ -2661,8 +2665,14 @@ void manager_run_generators(Manager *m) { argv[3] = m->generator_unit_path_late; argv[4] = NULL; + if (m->is_first_boot) { + env[0] = (char*) "SYSTEMD_FIRST_BOOT=1"; + env[1] = NULL; + } else + env[0] = NULL; + RUN_WITH_UMASK(0022) - execute_directory(generator_path, d, DEFAULT_TIMEOUT_USEC, (char**) argv); + execute_directory(generator_path, d, DEFAULT_TIMEOUT_USEC, (char**) argv, (char**) env); finish: trim_generator_dir(m, &m->generator_unit_path); diff --git a/src/core/manager.h b/src/core/manager.h index f2c1b0d227..eff639d1b6 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -243,6 +243,7 @@ struct Manager { bool default_cpu_accounting; bool default_memory_accounting; bool default_blockio_accounting; + bool is_first_boot; usec_t default_timer_accuracy_usec; diff --git a/src/core/shutdown.c b/src/core/shutdown.c index fde3ce9c27..e7771c968e 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -375,7 +375,7 @@ int main(int argc, char *argv[]) { arguments[0] = NULL; arguments[1] = arg_verb; arguments[2] = NULL; - execute_directory(SYSTEM_SHUTDOWN_PATH, NULL, DEFAULT_TIMEOUT_USEC, arguments); + execute_directory(SYSTEM_SHUTDOWN_PATH, NULL, DEFAULT_TIMEOUT_USEC, arguments, NULL); if (!in_container && !in_initrd() && access("/run/initramfs/shutdown", X_OK) == 0) { -- cgit v1.2.3-54-g00ecf