]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: use ASSERT_PTR and strdup_or_null more
authorMike Yuan <me@yhndnzj.com>
Sun, 4 Feb 2024 10:48:31 +0000 (18:48 +0800)
committerMike Yuan <me@yhndnzj.com>
Sun, 4 Feb 2024 16:37:00 +0000 (00:37 +0800)
src/core/unit.c

index 0c48e5fa6068e430797e396c8a8ac2a6b817a423..6dc13bcc9ad3138cca53be73338a8b77819b9fc7 100644 (file)
@@ -4959,8 +4959,7 @@ int unit_setup_exec_runtime(Unit *u) {
         if (*rt)
                 return 0;
 
-        ec = unit_get_exec_context(u);
-        assert(ec);
+        ec = ASSERT_PTR(unit_get_exec_context(u));
 
         r = unit_get_transitive_dependency_set(u, UNIT_ATOM_JOINS_NAMESPACE_OF, &units);
         if (r < 0)
@@ -5319,7 +5318,6 @@ int unit_acquire_invocation_id(Unit *u) {
 }
 
 int unit_set_exec_params(Unit *u, ExecParameters *p) {
-        const char *confirm_spawn;
         int r;
 
         assert(u);
@@ -5332,12 +5330,9 @@ int unit_set_exec_params(Unit *u, ExecParameters *p) {
 
         p->runtime_scope = u->manager->runtime_scope;
 
-        confirm_spawn = manager_get_confirm_spawn(u->manager);
-        if (confirm_spawn) {
-                p->confirm_spawn = strdup(confirm_spawn);
-                if (!p->confirm_spawn)
-                        return -ENOMEM;
-        }
+        r = strdup_or_null(manager_get_confirm_spawn(u->manager), &p->confirm_spawn);
+        if (r < 0)
+                return r;
 
         p->cgroup_supported = u->manager->cgroup_supported;
         p->prefix = u->manager->prefix;