]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
debug-generator: don't eat up error if we can't write drop-in
authorMike Yuan <me@yhndnzj.com>
Wed, 8 May 2024 10:13:29 +0000 (18:13 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 8 May 2024 10:43:50 +0000 (18:43 +0800)
While at it, prepend the drop-in text with
our usual "Automatically generated by ...".

src/debug-generator/debug-generator.c

index 5a18068e261f590a7d2b7423a5c618bfa6b91caa..eeefed0eefb26874e9817b815c51babcf998ad8d 100644 (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)