Discussion:
Unclear behavior of tmpfiles.d "f" type
Add Reply
Eli Schwartz
2018-01-15 20:34:48 UTC
Reply
Permalink
Raw Message
Over in Arch Linux, I am trying to move some packages over from using
post-install scripts to using tpmfiles.d/sysusers.d for any applicable
behavior. Occasionally, default files need to be created with the
contents of some specifier, for example %H.

I don't think /usr/share/factory is appropriate for this, but it
shouldn't be overwritten with "F" type either. So "f" seems most
appropriate.

But re-running systemd-tmpfiles repeatedly appends the argument to the
file, which doesn't seem right. I cannot offhand think of a situation
where I would want that utility, anyways.

The manpage unclear on the intended behavior, so I'm not even sure if
this is a bug. "Create a file if it does not exist yet. If the argument
parameter is given, it will be written to the file." I wouldn't describe
the current behavior as "written", but rather "appended". And there
appears to be no way to do what I want.

OTOH, it also updates the file owner/mode for existing files, which
seems to be in theme for this appending behavior, but which is also
undocumented behavior. Contrast this with the "d" type, which explicitly
states "The mode and ownership will be adjusted if specified and the
directory already exists."

So either the behavior or the documentation seems to be flawed here. I
guess since "f" consistently behaves like "F" except without the initial
truncation, it is probably the documentation that is flawed, in which
case I think "write" should be replaced with "append", or the
description for "F" should thematically match "D" by stating "Similar to
f, but in addition if the file exists it will be truncated before
checking for and writing any argument parameter".

Also, how do I use a specifier in an argument here? Should I use "F"
mode to write a file to /usr/share/factory and then on the next line use
"C" to copy it over? That's not very simple IMHO.
--
Eli Schwartz
Bug Wrangler and Trusted User
Lennart Poettering
2018-01-24 10:16:46 UTC
Reply
Permalink
Raw Message
Post by Eli Schwartz
Over in Arch Linux, I am trying to move some packages over from using
post-install scripts to using tpmfiles.d/sysusers.d for any applicable
behavior. Occasionally, default files need to be created with the
contents of some specifier, for example %H.
I don't think /usr/share/factory is appropriate for this, but it
shouldn't be overwritten with "F" type either. So "f" seems most
appropriate.
But re-running systemd-tmpfiles repeatedly appends the argument to the
file, which doesn't seem right. I cannot offhand think of a situation
where I would want that utility, anyways.
Yes, I agree. I think the current O_APPEND behaviour indeed does not
make much sense, and O_EXIST would make more sense and actually be
in line with what the documentation suggests.

I have thus prepared a PR that fixes this and makes it work like you
want:

https://github.com/systemd/systemd/pull/7983

It's a change of behaviour, but i think one we can get away with as
the old behaviour really didn#t make much sense and didnt match what
the documentation suggested.
Post by Eli Schwartz
Also, how do I use a specifier in an argument here? Should I use "F"
mode to write a file to /usr/share/factory and then on the next line use
"C" to copy it over? That's not very simple IMHO.
let's fix tmpfiles with the aforementioned PR first. And then my
answer is: use "f", as you originally wanted to.

Thanks for pointing this out,

Lennart
--
Lennart Poettering, Red Hat
Eli Schwartz
2018-01-25 01:35:17 UTC
Reply
Permalink
Raw Message
Post by Lennart Poettering
Yes, I agree. I think the current O_APPEND behaviour indeed does not
make much sense, and O_EXIST would make more sense and actually be
in line with what the documentation suggests.
I have thus prepared a PR that fixes this and makes it work like you
https://github.com/systemd/systemd/pull/7983
It's a change of behaviour, but i think one we can get away with as
the old behaviour really didn#t make much sense and didnt match what
the documentation suggested.
Thanks!
--
Eli Schwartz
Bug Wrangler and Trusted User
Loading...