Skip to contentSkip to conversation

systemd: Do not install anything in /var/log

PATCH Superseded Peter Kjellerstedt 3 participants 4 messages Oct 27, 2021

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 systemd: Do not install anything in /var/log

/var/log is typically a symbolic link to inside /var/volatile, which is expected to be empty.

---
 meta/recipes-core/systemd/systemd_249.5.bb | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
meta/recipes-core/systemd/systemd_249.5.bb +4 -7
index d87f54bf16..f2e6a79d6c 100644
@@ -270,13 +270,10 @@ do_install() {
 		install -Dm 0755 ${S}/src/systemctl/systemd-sysv-install.SKELETON ${D}${systemd_system_unitdir}d-sysv-install
 	fi
 
-	chown root:systemd-journal ${D}/${localstatedir}/log/journal
-
-	# Delete journal README, as log can be symlinked inside volatile.
-	rm -f ${D}/${localstatedir}/log/README
-
-	# journal-remote creates this at start
-	rm -rf ${D}/${localstatedir}/log/journal/remote
+	# /var/log is typically a symbolic link to inside /var/volatile, which
+	# is expected to be empty. This remove /var/log/README and
+	# /var/log/journal/.
+	rm -rf ${D}${localstatedir}/log
 
 	install -d ${D}${systemd_system_unitdir}/graphical.target.wants
 	install -d ${D}${systemd_system_unitdir}/multi-user.target.wants
#1 lore raw

PATCH 2/2 insane.bbclass: Add a check for directories that are expected to be empty

The empty-dirs QA check verifies that all directories specified in QA_EMPTY_DIRS are empty. It is possible to specify why a directory is expected to be empty by defining QA_EMPTY_DIRS_RECOMMENDATION:<path>, which will then be included in the error message if the directory is not empty. If it is not specified for a directory, then "but it is expected to be empty" will be used.

---
 meta/classes/insane.bbclass  | 33 ++++++++++++++++++++++++++++++++-
 meta/conf/documentation.conf |  2 ++
 2 files changed, 34 insertions(+), 1 deletion(-)
meta/classes/insane.bbclass +32 -1
index 1e2f1b768a..1675adf6ac 100644
@@ -37,7 +37,7 @@ ERROR_QA ?= "dev-so debug-deps dev-deps debug-files arch pkgconfig la \
             configure-gettext perllocalpod shebang-size \
             already-stripped installed-vs-shipped ldflags compile-host-path \
             install-host-path pn-overrides unknown-configure-option \
-            useless-rpaths rpaths staticdev \
+            useless-rpaths rpaths staticdev empty-dirs \
             "
 # Add usrmerge QA check based on distro feature
 ERROR_QA:append = "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', ' usrmerge', '', d)}"
@@ -50,6 +50,21 @@ ALL_QA = "${WARN_QA} ${ERROR_QA}"
 
 UNKNOWN_CONFIGURE_WHITELIST ?= "--enable-nls --disable-nls --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot --disable-static"
 
+# This is a list of directories that are expected to be empty.
+QA_EMPTY_DIRS ?= " \
+    /dev/pts \
+    /media \
+    /proc \
+    /run \
+    /tmp \
+    ${localstatedir}/run \
+    ${localstatedir}/volatile \
+"
+# It is possible to specify why a directory is expected to be empty by defining
+# QA_EMPTY_DIRS_RECOMMENDATION:<path>, which will then be included in the error
+# message if the directory is not empty. If it is not specified for a directory,
+# then "but it is expected to be empty" will be used.
+
 def package_qa_clean_path(path, d, pkg=None):
     """
     Remove redundant paths from the path for display.  If pkg isn't set then
@@ -885,6 +900,22 @@ def package_qa_check_unlisted_pkg_lics(package, d, messages):
                            "listed in LICENSE" % (package, ' '.join(unlisted)))
     return False
 
+QAPKGTEST[empty-dirs] = "package_qa_check_empty_dirs"
+def package_qa_check_empty_dirs(pkg, d, messages):
+    """
+    Check for the existence of files in directories that are expected to be
+    empty.
+    """
+
+    pkgd = oe.path.join(d.getVar('PKGDEST'), pkg)
+    for dir in (d.getVar('QA_EMPTY_DIRS') or "").split():
+        empty_dir = oe.path.join(pkgd, dir)
+        if os.path.exists(empty_dir) and os.listdir(empty_dir):
+            recommendation = (d.getVar('QA_EMPTY_DIRS_RECOMMENDATION:' + dir) or
+                              "but it is expected to be empty")
+            msg = "%s installs files in %s, %s" % (pkg, dir, recommendation)
+            oe.qa.add_message(messages, "empty-dirs", msg)
+
 def package_qa_check_encoding(keys, encode, d):
     def check_encoding(key, enc):
         sane = True
meta/conf/documentation.conf +2 -0
index 80ad8e10d5..45cd01374a 100644
@@ -345,6 +345,8 @@ PYPI_SRC_URI[doc] = "The URI to use to fetch from pypi, default uses pythonhoste
 
 #Q
 
+QA_EMPTY_DIRS[doc] = "A list of directories that are expected to be empty."
+QA_EMPTY_DIRS_RECOMMENDATION[doc] = "This specifies a recommendation for a directory why it must be empty, which will be included in the error message if the directory is not empty."
 QMAKE_PROFILES[doc] = "Specifies your own subset of .pro files to be built for use with qmake."
 
 #R
#2 lore raw

Re: [OE-core] [PATCH 2/2] insane.bbclass: Add a check for directories that are expected to be empty

Thanks for the patch, that looks like a better approach to me than the previously suggested

Quoted 27 lines · Peter Kjellerstedt

The empty-dirs QA check verifies that all directories specified in QA_EMPTY_DIRS are empty. It is possible to specify why a directory is expected to be empty by defining QA_EMPTY_DIRS_RECOMMENDATION:<path>, which will then be included in the error message if the directory is not empty. If it is not specified for a directory, then "but it is expected to be empty" will be used.

---
  meta/classes/insane.bbclass  | 33 ++++++++++++++++++++++++++++++++-
  meta/conf/documentation.conf |  2 ++
  2 files changed, 34 insertions(+), 1 deletion(-)
meta/classes/insane.bbclass +1 -1
index 1e2f1b768a..1675adf6ac 100644
@@ -37,7 +37,7 @@ ERROR_QA ?= "dev-so debug-deps dev-deps debug-files arch pkgconfig la \
              configure-gettext perllocalpod shebang-size \
              already-stripped installed-vs-shipped ldflags compile-host-path \
              install-host-path pn-overrides unknown-configure-option \
-            useless-rpaths rpaths staticdev \
+            useless-rpaths rpaths staticdev empty-dirs \
              "
  # Add usrmerge QA check based on distro feature
  ERROR_QA:append = "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', ' usrmerge', '', d)}"

meta/classes/insane.bbclass ALL_QA = "${WARN_QA} ${ERROR_QA}" · line 55

Quoted 6 lines
meta/classes/insane.bbclass +3 -0
@@ -50,6 +50,21 @@ ALL_QA = "${WARN_QA} ${ERROR_QA}"
 
  UNKNOWN_CONFIGURE_WHITELIST ?= "--enable-nls --disable-nls --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot --disable-static"
 
+# This is a list of directories that are expected to be empty.
+QA_EMPTY_DIRS ?= " \
+    /dev/pts \

Not sure why just /dev/pts should be empty, IMHO all of /dev shouldn't be prepopulated at build time

Quoted 62 lines
meta/classes/insane.bbclass +28 -0
+    /media \
+    /proc \
+    /run \
+    /tmp \
+    ${localstatedir}/run \
+    ${localstatedir}/volatile \
+"
+# It is possible to specify why a directory is expected to be empty by defining
+# QA_EMPTY_DIRS_RECOMMENDATION:<path>, which will then be included in the error
+# message if the directory is not empty. If it is not specified for a directory,
+# then "but it is expected to be empty" will be used.
+
  def package_qa_clean_path(path, d, pkg=None):
      """
      Remove redundant paths from the path for display.  If pkg isn't set then
@@ -885,6 +900,22 @@ def package_qa_check_unlisted_pkg_lics(package, d, messages):
                             "listed in LICENSE" % (package, ' '.join(unlisted)))
      return False
 
+QAPKGTEST[empty-dirs] = "package_qa_check_empty_dirs"
+def package_qa_check_empty_dirs(pkg, d, messages):
+    """
+    Check for the existence of files in directories that are expected to be
+    empty.
+    """
+
+    pkgd = oe.path.join(d.getVar('PKGDEST'), pkg)
+    for dir in (d.getVar('QA_EMPTY_DIRS') or "").split():
+        empty_dir = oe.path.join(pkgd, dir)
+        if os.path.exists(empty_dir) and os.listdir(empty_dir):
+            recommendation = (d.getVar('QA_EMPTY_DIRS_RECOMMENDATION:' + dir) or
+                              "but it is expected to be empty")
+            msg = "%s installs files in %s, %s" % (pkg, dir, recommendation)
+            oe.qa.add_message(messages, "empty-dirs", msg)
+
  def package_qa_check_encoding(keys, encode, d):
      def check_encoding(key, enc):
          sane = True
meta/conf/documentation.conf +2 -1
index 80ad8e10d5..45cd01374a 100644
@@ -345,6 +345,8 @@ PYPI_SRC_URI[doc] = "The URI to use to fetch from pypi, default uses pythonhoste
 
  #Q
 
+QA_EMPTY_DIRS[doc] = "A list of directories that are expected to be empty."
+QA_EMPTY_DIRS_RECOMMENDATION[doc] = "This specifies a recommendation for a directory why it must be empty, which will be included in the error message if the directory is not empty."
  QMAKE_PROFILES[doc] = "Specifies your own subset of .pro files to be built for use with qmake."
 
  #R
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#157556): https://lists.openembedded.org/g/openembedded-core/message/157556
Mute This Topic: https://lists.openembedded.org/mt/86632212/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw
In reply to Peter Kjellerstedt
Quoted 14 lines · Peter Kjellerstedt

/var/log is typically a symbolic link to inside /var/volatile, which is expected to be empty.

---
 meta/recipes-core/systemd/systemd_249.5.bb | 11 ++++-------

 1 file changed, 4 insertions(+), 7 deletions(-)
meta/recipes-core/systemd/systemd_249.5.bb +0 -0
index d87f54bf16..f2e6a79d6c 100644
@@ -270,13 +270,10 @@ do_install() {
Quoted 5 lines

                install -Dm 0755 ${S}/src/systemctl/systemd-sysv- install.SKELETON ${D}${systemd_system_unitdir}d-sysv-install fi

-       chown root:systemd-journal ${D}/${localstatedir}/log/journal

Having /var/log/journal exist (on systems that don't symbolically link /var/log inside /var/volatile) by default will cause systemd to persistently log data. I suspect removing this is going to negatively impact some users.

Quoted 29 lines

-
-       # Delete journal README, as log can be symlinked inside volatile.
-       rm -f ${D}/${localstatedir}/log/README
-
-       # journal-remote creates this at start
-       rm -rf ${D}/${localstatedir}/log/journal/remote +       # /var/log is typically a symbolic link to inside /var/volatile, which
+       # is expected to be empty. This remove /var/log/README and +       # /var/log/journal/.
+       rm -rf ${D}${localstatedir}/log

        install -d ${D}${systemd_system_unitdir}/graphical.target.wants install -d ${D}${systemd_system_unitdir}/multi- user.target.wants

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#157555):
https://lists.openembedded.org/g/openembedded-core/message/157555
Mute This Topic: https://lists.openembedded.org/mt/86632211/6512429
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-