]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
service: minor modernizations
authorLennart Poettering <lennart@poettering.net>
Tue, 4 Apr 2023 10:21:00 +0000 (12:21 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 4 Apr 2023 14:34:18 +0000 (22:34 +0800)
src/core/service.c

index bebcf5cb5f98535d91ee4e5142e9d86e0f68c78e..da75540c3178457eebae9159fc538f82cfc982ff 100644 (file)
@@ -3445,30 +3445,30 @@ fail:
 }
 
 static int service_demand_pid_file(Service *s) {
-        PathSpec *ps;
+        _cleanup_free_ PathSpec *ps = NULL;
 
         assert(s->pid_file);
         assert(!s->pid_file_pathspec);
 
-        ps = new0(PathSpec, 1);
+        ps = new(PathSpec, 1);
         if (!ps)
                 return -ENOMEM;
 
-        ps->unit = UNIT(s);
-        ps->path = strdup(s->pid_file);
-        if (!ps->path) {
-                free(ps);
+        *ps = (PathSpec) {
+                .unit = UNIT(s),
+                .path = strdup(s->pid_file),
+                /* PATH_CHANGED would not be enough. There are daemons (sendmail) that keep their PID file
+                 * open all the time. */
+                .type = PATH_MODIFIED,
+                .inotify_fd = -EBADF,
+        };
+
+        if (!ps->path)
                 return -ENOMEM;
-        }
 
         path_simplify(ps->path);
 
-        /* PATH_CHANGED would not be enough. There are daemons (sendmail) that
-         * keep their PID file open all the time. */
-        ps->type = PATH_MODIFIED;
-        ps->inotify_fd = -EBADF;
-
-        s->pid_file_pathspec = ps;
+        s->pid_file_pathspec = TAKE_PTR(ps);
 
         return service_watch_pid_file(s);
 }