[systemd-devel] [PATCH] Add avoid_cleanup macro to cancel _cleanup_ of a pointer

Lennart Poettering lennart at poettering.net
Mon Mar 10 08:44:02 PDT 2014


On Sat, 08.03.14 20:33, Josh Triplett (josh at joshtriplett.org) wrote:

> avoid_cleanup also returns a copy of the pointer, making it convenient
> to use at the point where initialization completes, to hand the constructed
> object off somewhere without freeing it.
> 
> Change all NULL assignments tagged with /* avoid cleanup */ to use this
> instead.
> ---
> 
> Seems like a common pattern, and this makes it more self-documenting.
> In particular, the use in systemctl.c's list_timers function now feels
> like a single logical operation of "hand ownership of this object off to
> something else and don't clean it up".

Hmmm, I am all for synctactic sugar, but I don't see the benefit of this
one really... Especially given that that disabling cleanup is done
different for different types... For example, disabling cleanup for an
fd is by assigning -1...

I would see benefit in this if we could maybe make this
type-sensitive... not sure though if C would allow that? I at least
cannot think of a way to do that?

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list