Debian Codegraph @

src/factory-reset/factory-reset-generator.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "factory-reset.h"
4 #include "generator.h"
5 #include "log.h"
6 #include "special.h"
7
8 /* This generator pulls factory-reset-now.target into the initial transaction the kernel command line's
9 * systemd.factor_reset= variable, or the FactoryResetRequest EFI variable say so. */
10
11 static int run(const char *dest, const char *dest_early, const char *dest_late) {
12 assert(dest_early);
13
14 FactoryResetMode f = factory_reset_mode();
15 if (f < 0)
16 return log_error_errno(f, "Failed to determine factory reset mode: %m");
17 if (f != FACTORY_RESET_ON) {
18 log_debug("Not in factory reset mode, skipping.");
19 return 0;
20 }
21
22 log_debug("Detected factory reset mode, pulling in factory-reset-now.target.");
23
24 /* We pull this in from basic.target so that it ends up in all "regular" boot ups, but not in
25 * rescue.target or even emergency.target. */
26 return generator_add_symlink(dest_early, SPECIAL_BASIC_TARGET, "wants", "factory-reset-now.target");
27 }
28
29 DEFINE_MAIN_GENERATOR_FUNCTION(run);