From: Lennart Poettering Date: Tue, 4 Apr 2023 10:21:00 +0000 (+0200) Subject: service: minor modernizations X-Git-Tag: v254-rc1~815 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=51339a9aebc4f8e8f14f684ab8d3ca3eed9cf7d9;p=thirdparty%2Fsystemd.git service: minor modernizations --- 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); }