From 51339a9aebc4f8e8f14f684ab8d3ca3eed9cf7d9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 4 Apr 2023 12:21:00 +0200 Subject: [PATCH] service: minor modernizations --- src/core/service.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index bebcf5cb5f9..da75540c317 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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); } -- 2.47.3