firstboot: get rid of firstboot generator again, introduce ConditionFirstBoot= instead

As Zbigniew pointed out a new ConditionFirstBoot= appears like the nicer
way to hook in systemd-firstboot.service on first boots (those with /etc
unpopulated), so let's do this, and get rid of the generator again.
This commit is contained in:
Lennart Poettering
2014-07-07 21:05:09 +02:00
parent 45035609fc
commit e26807239b
17 changed files with 64 additions and 108 deletions
+17
View File
@@ -120,6 +120,20 @@ static bool condition_test_needs_update(Condition *c) {
(usr.st_mtim.tv_sec == other.st_mtim.tv_sec && usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec)) == !c->negate;
}
static bool condition_test_first_boot(Condition *c) {
int r;
assert(c);
assert(c->parameter);
assert(c->type == CONDITION_FIRST_BOOT);
r = parse_boolean(c->parameter);
if (r < 0)
return c->negate;
return ((access("/run/systemd/first-boot", F_OK) >= 0) == !!r) == !c->negate;
}
static bool condition_test(Condition *c) {
assert(c);
@@ -202,6 +216,9 @@ static bool condition_test(Condition *c) {
case CONDITION_NEEDS_UPDATE:
return condition_test_needs_update(c);
case CONDITION_FIRST_BOOT:
return condition_test_first_boot(c);
case CONDITION_NULL:
return !c->negate;
+1
View File
@@ -162,6 +162,7 @@ Unit.ConditionDirectoryNotEmpty, config_parse_unit_condition_path, CONDITION_D
Unit.ConditionFileNotEmpty, config_parse_unit_condition_path, CONDITION_FILE_NOT_EMPTY, 0
Unit.ConditionFileIsExecutable, config_parse_unit_condition_path, CONDITION_FILE_IS_EXECUTABLE, 0
Unit.ConditionNeedsUpdate, config_parse_unit_condition_path, CONDITION_NEEDS_UPDATE, 0
Unit.ConditionFirstBoot, config_parse_unit_condition_path, CONDITION_FIRST_BOOT, 0
Unit.ConditionKernelCommandLine, config_parse_unit_condition_string, CONDITION_KERNEL_COMMAND_LINE, 0
Unit.ConditionArchitecture, config_parse_unit_condition_string, CONDITION_ARCHITECTURE, 0
Unit.ConditionVirtualization, config_parse_unit_condition_string, CONDITION_VIRTUALIZATION, 0
+1 -1
View File
@@ -1648,11 +1648,11 @@ 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);
manager_set_show_status(m, arg_show_status);
manager_set_first_boot(m, empty_etc);
/* Remember whether we should queue the default job */
queue_default_job = !arg_serialization || arg_switched_root;
+16 -9
View File
@@ -2477,7 +2477,7 @@ void manager_check_finished(Manager *m) {
m->confirm_spawn = false;
/* This is no longer the first boot */
m->is_first_boot = false;
manager_set_first_boot(m, false);
if (dual_timestamp_is_set(&m->finish_timestamp))
return;
@@ -2631,7 +2631,6 @@ 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);
@@ -2665,14 +2664,8 @@ 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, (char**) env);
execute_directory(generator_path, d, DEFAULT_TIMEOUT_USEC, (char**) argv);
finish:
trim_generator_dir(m, &m->generator_unit_path);
@@ -2816,6 +2809,20 @@ static bool manager_get_show_status(Manager *m) {
return plymouth_running();
}
void manager_set_first_boot(Manager *m, bool b) {
assert(m);
if (m->running_as != SYSTEMD_SYSTEM)
return;
m->first_boot = b;
if (m->first_boot)
touch("/run/systemd/first-boot");
else
unlink("/run/systemd/first-boot");
}
void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) {
va_list ap;
+3 -1
View File
@@ -228,6 +228,7 @@ struct Manager {
bool dispatching_dbus_queue:1;
bool taint_usr:1;
bool first_boot:1;
ShowStatus show_status;
bool confirm_spawn;
@@ -243,7 +244,6 @@ struct Manager {
bool default_cpu_accounting;
bool default_memory_accounting;
bool default_blockio_accounting;
bool is_first_boot;
usec_t default_timer_accuracy_usec;
@@ -334,6 +334,8 @@ void manager_undo_generators(Manager *m);
void manager_recheck_journal(Manager *m);
void manager_set_show_status(Manager *m, ShowStatus mode);
void manager_set_first_boot(Manager *m, bool b);
void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) _printf_(4,5);
void manager_flip_auto_status(Manager *m, bool enable);
+1 -1
View File
@@ -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, NULL);
execute_directory(SYSTEM_SHUTDOWN_PATH, NULL, DEFAULT_TIMEOUT_USEC, arguments);
if (!in_container && !in_initrd() &&
access("/run/initramfs/shutdown", X_OK) == 0) {