[systemd-devel] [PATCHv2 1/2] tmpfiles: only execute chmod()/chown() when needed
lennart at poettering.net
Mon Aug 18 09:29:08 PDT 2014
On Sun, 17.08.14 09:45, Michael Olbrich (m.olbrich at pengutronix.de) wrote:
> This avoids errors like this, when the paths are already there with the
> correct permissions and owner:
> chmod(/var/spool) failed: Read-only file system
> The original code checked for 'stat() >= 0'. Any reason for that? My
> man-page says 'On success, zero is returned'.
Well, I usually check for "< 0" on failure and ">= 0" on success. It's
usually how things are done, on libc, and on our own code (our code just
gets one step further and returns -errno on error...
But yeah, it's not much of a difference, both works, but I think it's
slightly clearer to just check for negativity/non-negativity, since
usually positive values indicate non-errors, and negative ones errors,
even if in this case one can check for less.
Or to turn this around: if stat() would someday return 1 instead of 0,
for some reason, then I'd assume that this wouldn#t indicate an error,
but just some other form of success...
Lennart Poettering, Red Hat
More information about the systemd-devel