]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
manager: remove transient unit directory during startup
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 4 Apr 2023 10:05:16 +0000 (12:05 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 4 Apr 2023 14:33:20 +0000 (22:33 +0800)
I was testing transient units and user@.service crashed. I restarted it, and
tried to create a transient unit. It failed because
/run/user/1000/systemd/transient/ remained after the previous aborted run:
  Failed to start transient service unit: Unit run-u0.service was already loaded or has a fragment file.

Remove the directory during initial startup so we don't get confused by our own
files.

src/core/manager.c

index dcc10266ac69d28de516491a2a6cc12ba1126fc6..47a502df7fb4592d6fe7950d09c23c679db816de 100644 (file)
@@ -1861,6 +1861,10 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds, const char *roo
                 /* This block is (optionally) done with the reloading counter bumped */
                 _unused_ _cleanup_(manager_reloading_stopp) Manager *reloading = NULL;
 
+                /* Make sure we don't have a left-over from a previous run */
+                if (!serialization)
+                        (void) rm_rf(m->lookup_paths.transient, 0);
+
                 /* If we will deserialize make sure that during enumeration this is already known, so we increase the
                  * counter here already */
                 if (serialization)