debug-generator: don't eat up error if we can't write drop-in

While at it, prepend the drop-in text with
our usual "Automatically generated by ...".
This commit is contained in:
Mike Yuan 2024-05-08 18:13:29 +08:00
parent 2997df9777
commit a3816ea427
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3

View file

@ -141,22 +141,25 @@ static int generate_wants_symlinks(void) {
return r;
}
static void install_debug_shell_dropin(void) {
static int install_debug_shell_dropin(void) {
const char *tty = arg_debug_tty ?: arg_default_debug_tty;
int r;
if (!tty || path_equal(tty, skip_dev_prefix(DEBUGTTY)))
return;
return 0;
r = write_drop_in_format(arg_dest, "debug-shell.service", 50, "tty",
"[Unit]\n"
"Description=Early root shell on /dev/%s FOR DEBUGGING ONLY\n"
"ConditionPathExists=\n"
"[Service]\n"
"TTYPath=/dev/%s",
tty, tty);
"# Automatically generated by systemd-debug-generator\n\n"
"[Unit]\n"
"Description=Early root shell on /dev/%s FOR DEBUGGING ONLY\n"
"ConditionPathExists=\n"
"\n[Service]\n"
"TTYPath=/dev/%s\n",
tty, tty);
if (r < 0)
log_warning_errno(r, "Failed to write drop-in for debug-shell.service, ignoring: %m");
return log_warning_errno(r, "Failed to write drop-in for debug-shell.service: %m");
return 1;
}
static int process_unit_credentials(const char *credentials_dir) {
@ -226,7 +229,7 @@ static int process_unit_credentials(const char *credentials_dir) {
static int run(const char *dest, const char *dest_early, const char *dest_late) {
const char *credentials_dir;
int r = 0;
int r;
assert_se(arg_dest = dest_early);
@ -238,7 +241,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
if (strv_extend(&arg_wants, "debug-shell.service") < 0)
return log_oom();
install_debug_shell_dropin();
RET_GATHER(r, install_debug_shell_dropin());
}
if (get_credentials_dir(&credentials_dir) >= 0)