#439 update for http://fedoraproject.org/wiki/Packaging:Tmpfiles.d
Closed: Fixed None Opened 9 years ago by zbyszek.

tmpfiles.d packaging guidelines have become a bit stale. I would like to update them to:

  1. more explicitly recommend %_tmpfilesdir usage. Currently it is recommended, but the snippets use explicit paths. Also, there's a discussion of F17 compatibility, which probably can be deleted, making the whole thing simpler.

  2. recommend %post %tmpfiles_create to actually execute the tmpfile snippets on package installation. (Example problem in https://bugzilla.redhat.com/show_bug.cgi?id=1112016.)

Additional motivation for 1. is that packagers install tmpfiles snippets in /etc/tmpfiles.d, which is against the recommendations, but will be easier to avoid if a macro is used. This should help keep /etc empty.

Proposed patch:
{{{
--- /tmp/packaging.orig 2014-06-22 20:28:39.407013665 -0400
+++ /tmp/packaging 2014-06-22 20:34:19.290934208 -0400
@@ -5,9 +5,6 @@

== tmpfiles.d configuration ==

-{{admon/note|%{_tmpfilesdir} not available on F17 and older| The %{_tmpfilesdir} macro was introduced in Fedora 18. For older Fedora releases, use %{_prefix}/lib/tmpfiles.d/.}}
-Asking the tmpfiles.d mechanism to create directories for you just involves dropping a file into %{_tmpfilesdir}.
-
For example, if the package needs a few directories to be created in /run in order for it to run, the packager needs to create a file named %{name}.conf that is installed as %{_tmpfilesdir}/%{name}.conf. The file has one or more lines of the following format:


@@ -39,20 +36,20 @@
[...]

%install
-mkdir -p %{buildroot}%{_prefix}/lib/tmpfiles.d
-install -m 0644 %{SOURCE1} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
+install -Dm 0644 %{SOURCE1} %{buildroot}%{_tmpfilesdir}/%{name}.conf

-# The next two lines may not be needed if the upstream's install script creates them
-mkdir -p %{buildroot}/run
-install -d -m 0755 %{buildroot}/run/%{name}/
+%post
+%tmpfiles_create %{name}.conf
[...]

%files
%dir /run/%{name}/
-%{_prefix}/lib/tmpfiles.d/%{name}.conf
+%{_tmpfilesdir}/%{name}.conf

-Note that %{_prefix}/lib/tmpfiles.d/%{name}.conf is '''not''' marked as a %config file, because it is not supposed to be edited by administrators. They can override your %{name}.conf by placing an identically named file in /etc/tmpfiles.d/, but this should very rarely needed.
+Note that %{_tmpfilesdir}/%{name}.conf is '''not''' marked as a %config file, because it is not supposed to be edited by administrators. They can override your %{name}.conf by placing an identically named file in /etc/tmpfiles.d/, but this should very rarely needed.
+
+Note that %tmpfiles_create is invoked with just the basename, not the full path of %{name}.conf. This allows the override to be used, if one was specified by the administrator.

Files that the program places directly into /run or into its subdirectories may be listed in the %files section as %ghost but you may also omit them entirely as the files will be cleaned up on every reboot.

}}}


Hm, %tmpfiles_create is not available in F19 atm. But it can be easily added. If this change is accepted, I'll do that.

I would argue against the use of a scriptlet to create anything, and opt rather for the packages to own the items. Then, rpm does the initial creation for you, and you get rpm tracking the owned files as a bonus.

Actually, the guidelines already include what I mentioned. (The specific problem with screen was the ill-advised use of %ghost)

Replying to [comment:2 rdieter]:

I would argue against the use of a scriptlet to create anything, and opt rather for the packages to own the items. Then, rpm does the initial creation for you, and you get rpm tracking the owned files as a bonus.

Yeah, this proposal wasn't supposed to be about that, but I got sidetracked while writing it. Sorry. I'll check if there are any calls to tmpfiles --create in %post in exisiting packages, and if necessary submit an update for that separately. So the updated agenda is to:

  1. use %{_tmpfilesdir}
  2. not use %ghost

{{{
--- tmp/packaging.orig
+++ tmp/packaging
@@ -5,9 +5,6 @@ tmpfiles.d is a service in Fedora 15 and later for managing temporary files and

== tmpfiles.d configuration ==

-{{admon/note|%{_tmpfilesdir} not available on F17 and older| The %{_tmpfilesdir} macro was introduced in Fedora 18. For older Fedora releases, use %{_prefix}/lib/tmpfiles.d/.}}
-Asking the tmpfiles.d mechanism to create directories for you just involves dropping a file into %{_tmpfilesdir}.
-
For example, if the package needs a few directories to be created in /run in order for it to run, the packager needs to create a file named %{name}.conf that is installed as %{_tmpfilesdir}/%{name}.conf. The file has one or more lines of the following format:


@@ -39,8 +36,7 @@ Source1: %{name}-tmpfiles.conf
[...]

%install
-mkdir -p %{buildroot}%{_prefix}/lib/tmpfiles.d
-install -m 0644 %{SOURCE1} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
+install -Dm 0644 %{SOURCE1} %{buildroot}%{_tmpfilesdir}/%{name}.conf

# The next two lines may not be needed if the upstream's install script creates them
mkdir -p %{buildroot}/run
@@ -49,12 +45,12 @@ install -d -m 0755 %{buildroot}/run/%{name}/

%files
%dir /run/%{name}/
-%{_prefix}/lib/tmpfiles.d/%{name}.conf
+%{_tmpfilesdir}/%{name}.conf

-Note that %{_prefix}/lib/tmpfiles.d/%{name}.conf is '''not''' marked as a %config file, because it is not supposed to be edited by administrators. They can override your %{name}.conf by placing an identically named file in /etc/tmpfiles.d/, but this should very rarely needed.
+Note that %{_tmpfilesdir}/%{name}.conf is '''not''' marked as a %config file, because it is not supposed to be edited by administrators. They can override your %{name}.conf by placing an identically named file in /etc/tmpfiles.d/, but this should very rarely needed.

-Files that the program places directly into /run or into its subdirectories may be listed in the %files section as %ghost but you may also omit them entirely as the files will be cleaned up on every reboot.
+Files that the program places directly into /run or into its subdirectories should not be listed in the %files section as %ghost, so that they they are available immediately after package installation.

== Why not create the directories with XXXXXX instead? ==
There are multiple ways to try creating the directories but most suffer some disadvantage that tmpfiles.d addresses:
}}}

Okay... new draft:

https://fedoraproject.org/wiki/User:Toshio/Tmpfiles.d_(draft)#Example_spec_file

This fixes the issues brought up at the meeting by using %verify instead of %ghost. We could simplify them by leaving out the omitting for files in subdirectories portion of the guideline. That would have the benefit of letting rpm know about all known-at-package-build-time /run/ files but it would have the drawback of making packagers specify more files with the %verify macro. The example spec would look like this:

{{{
%files
%dir /run/%name/
%verify(not md5 size mtime) /run/%name/*
}}}

I also found that the use of %tmpfiles_create had come up in FPC before: https://fedorahosted.org/fpc/ticket/377 and been rejected. I don't think much has changed here so I think we still want to go with the pattern of making sure that rpm knows about these files instead of creating them via install-time scriptlet.

Draft approved (+1:7, 0:0, -1:0)

Announcement text:

The tmpfiles.d guidelines (https://fedoraproject.org/wiki/Packaging:Tmpfiles.d) have been updated and clarified. Note that this includes new instructions for specifying files created by the tmpfiles.d mechanism in your %files section; %verify is now used instead of %ghost.

Login to comment on this ticket.

Metadata