2015-05-19 14:23:59 +02:00
|
|
|
From: Ludwig Nussel <ludwig.nussel@suse.de>
|
|
|
|
Date: Fri, 5 Sep 2014 12:53:40 +0200
|
|
|
|
Subject: [PATCH] add check for tmpfiles created at runtime
|
|
|
|
|
2015-11-26 11:24:13 +01:00
|
|
|
this check parses files in /usr/lib/tmpfiles.d and verifies that
|
|
|
|
entries that create files or directories are actually listed in
|
|
|
|
%files.
|
|
|
|
|
|
|
|
The check also handles the ghost file check as rpmlint shouldn't
|
|
|
|
complain about ghost files handled by the tmpfiles mechanism.
|
2015-05-19 14:23:59 +02:00
|
|
|
---
|
2015-11-26 11:24:13 +01:00
|
|
|
PostCheck.py | 18 ---------
|
|
|
|
TmpFilesCheck.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
2 files changed, 111 insertions(+), 18 deletions(-)
|
2015-05-19 14:23:59 +02:00
|
|
|
create mode 100644 TmpFilesCheck.py
|
|
|
|
|
2015-11-26 11:24:13 +01:00
|
|
|
diff --git a/PostCheck.py b/PostCheck.py
|
|
|
|
index 20b515e..6836359 100644
|
|
|
|
--- a/PostCheck.py
|
|
|
|
+++ b/PostCheck.py
|
|
|
|
@@ -112,20 +112,6 @@ class PostCheck(AbstractCheck.AbstractCheck):
|
|
|
|
self.check_aux(
|
|
|
|
pkg, files, prog[idx], script[idx], tag[2], prereq)
|
|
|
|
|
|
|
|
- ghost_files = pkg.ghostFiles()
|
|
|
|
- if ghost_files:
|
|
|
|
- postin = pkg[rpm.RPMTAG_POSTIN]
|
|
|
|
- prein = pkg[rpm.RPMTAG_PREIN]
|
|
|
|
- for f in ghost_files:
|
|
|
|
- if f in pkg.missingOkFiles():
|
|
|
|
- continue
|
|
|
|
- if not postin and not prein:
|
|
|
|
- printWarning(pkg, 'ghost-files-without-postin')
|
|
|
|
- if (not postin or f not in postin) and \
|
|
|
|
- (not prein or f not in prein):
|
|
|
|
- printWarning(pkg,
|
|
|
|
- 'postin-without-ghost-file-creation', f)
|
|
|
|
-
|
|
|
|
def check_aux(self, pkg, files, prog, script, tag, prereq):
|
|
|
|
if script:
|
|
|
|
if prog:
|
|
|
|
@@ -194,10 +180,6 @@ class PostCheck(AbstractCheck.AbstractCheck):
|
|
|
|
check = PostCheck()
|
|
|
|
|
|
|
|
# Add information about checks
|
|
|
|
-addDetails(
|
|
|
|
-'postin-without-ghost-file-creation',
|
|
|
|
-'''A file tagged as ghost is not created during %prein nor during %postin.''',
|
|
|
|
-)
|
|
|
|
for scriptlet in map(lambda x: '%' + x, RPM_SCRIPTLETS):
|
|
|
|
addDetails(
|
|
|
|
'one-line-command-in-%s' % scriptlet,
|
2015-05-19 14:23:59 +02:00
|
|
|
diff --git a/TmpFilesCheck.py b/TmpFilesCheck.py
|
|
|
|
new file mode 100644
|
2015-11-26 11:24:13 +01:00
|
|
|
index 0000000..d1ef824
|
2015-05-19 14:23:59 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/TmpFilesCheck.py
|
2015-11-26 11:24:13 +01:00
|
|
|
@@ -0,0 +1,111 @@
|
2015-05-19 14:23:59 +02:00
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
|
+#############################################################################
|
|
|
|
+# File : TmpFilesCheck.py
|
|
|
|
+# Package : rpmlint
|
|
|
|
+# Author : Ludwig Nussel
|
|
|
|
+# Created on : Wed Sep 03 10:36 2014
|
|
|
|
+# Purpose : Check systemd created tmpfiles are included in filelist
|
|
|
|
+#############################################################################
|
|
|
|
+
|
|
|
|
+import os
|
|
|
|
+import re
|
|
|
|
+
|
|
|
|
+from Filter import addDetails, printError, printWarning
|
|
|
|
+import AbstractCheck
|
|
|
|
+import Pkg
|
|
|
|
+import stat
|
2015-11-26 11:24:13 +01:00
|
|
|
+import rpm
|
2015-05-19 14:23:59 +02:00
|
|
|
+
|
|
|
|
+class TmpFilesCheck(AbstractCheck.AbstractCheck):
|
|
|
|
+ '''Check systemd created tmpfiles are included in filelist'''
|
|
|
|
+
|
|
|
|
+ def __init__(self):
|
|
|
|
+ AbstractCheck.AbstractCheck.__init__(self, "TmpFilesCheck")
|
|
|
|
+ self._spec_file = None
|
|
|
|
+
|
|
|
|
+ def check(self, pkg):
|
|
|
|
+ if pkg.isSource():
|
|
|
|
+ return
|
|
|
|
+
|
2015-11-26 11:24:13 +01:00
|
|
|
+ # file names handled by systemd-tmpfiles
|
|
|
|
+ tmp_files = set()
|
|
|
|
+ postin = pkg[rpm.RPMTAG_POSTIN]
|
|
|
|
+ prein = pkg[rpm.RPMTAG_PREIN]
|
|
|
|
+
|
2015-05-19 14:23:59 +02:00
|
|
|
+ # see tmpfiles.d(5)
|
|
|
|
+ interesting_types = ('f', 'F', 'w', 'd', 'D', 'p', 'L', 'c', 'b')
|
|
|
|
+
|
|
|
|
+ for fn, pkgfile in pkg.files().items():
|
|
|
|
+ if not fn.startswith('/usr/lib/tmpfiles.d/'):
|
|
|
|
+ continue
|
|
|
|
+ if not stat.S_ISREG(pkgfile.mode):
|
|
|
|
+ printWarning(pkg, "tmpfile-not-regular-file", fn)
|
|
|
|
+ continue
|
2015-11-26 11:24:13 +01:00
|
|
|
+
|
|
|
|
+ pattern = re.compile(r'systemd-tmpfiles --create .*%s'%re.escape(fn))
|
|
|
|
+ if (not postin or not pattern.search(postin)) and \
|
|
|
|
+ (not prein or not pattern.search(prein)):
|
|
|
|
+ printWarning(pkg,
|
|
|
|
+ 'postin-without-tmpfile-creation', fn)
|
|
|
|
+
|
2015-05-19 14:23:59 +02:00
|
|
|
+ for line in open(pkgfile.path):
|
|
|
|
+ # skip comments
|
|
|
|
+ line = line.split('#')[0].split('\n')[0]
|
|
|
|
+ line = line.lstrip()
|
|
|
|
+ if not len(line):
|
|
|
|
+ continue
|
|
|
|
+ line = re.split(r'\s+', line)
|
|
|
|
+ # format is
|
|
|
|
+ #Type Path Mode UID GID Age Argument
|
|
|
|
+ # we only need type and path
|
|
|
|
+ if len(line) < 3:
|
|
|
|
+ continue
|
|
|
|
+ t = line[0]
|
|
|
|
+ p = line[1]
|
|
|
|
+ if t.endswith('!'):
|
|
|
|
+ t = t[:-1]
|
|
|
|
+ if not t in interesting_types:
|
|
|
|
+ continue
|
|
|
|
+
|
2015-11-26 11:24:13 +01:00
|
|
|
+ tmp_files.add(p)
|
|
|
|
+
|
2015-05-19 14:23:59 +02:00
|
|
|
+ if not p in pkg.files():
|
|
|
|
+ printWarning(pkg, "tmpfile-not-in-filelist", p)
|
|
|
|
+ continue
|
|
|
|
+ if not pkg.files()[p].is_ghost:
|
|
|
|
+ printWarning(pkg, "tmpfile-not-ghost", p)
|
|
|
|
+
|
2015-11-26 11:24:13 +01:00
|
|
|
+ # now check remaining ghost files that are not already
|
|
|
|
+ # handled by systemd-tmpfiles
|
|
|
|
+ ghost_files = set(pkg.ghostFiles()) - tmp_files
|
|
|
|
+ if ghost_files:
|
|
|
|
+ for f in ghost_files:
|
|
|
|
+ if f in pkg.missingOkFiles():
|
|
|
|
+ continue
|
|
|
|
+ if not postin and not prein:
|
|
|
|
+ printWarning(pkg, 'ghost-files-without-postin')
|
|
|
|
+ if (not postin or f not in postin) and \
|
|
|
|
+ (not prein or f not in prein):
|
|
|
|
+ printWarning(pkg,
|
|
|
|
+ 'postin-without-ghost-file-creation', f)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
2015-05-19 14:23:59 +02:00
|
|
|
+check = TmpFilesCheck()
|
|
|
|
+
|
|
|
|
+addDetails(
|
2015-11-26 11:24:13 +01:00
|
|
|
+'postin-without-ghost-file-creation',
|
|
|
|
+'''A file tagged as ghost is not created during %prein nor during %postin.''',
|
|
|
|
+'postin-without-tmpfile-creation',
|
|
|
|
+'''Please use the %tmpfiles_create macro in %post for each of your tmpfiles.d files''',
|
2015-05-19 14:23:59 +02:00
|
|
|
+'tmpfile-not-regular-file',
|
|
|
|
+'''files in tmpfiles.d need to be regular files''', # otherwise we won't open it :-)
|
|
|
|
+'tmpfile-not-in-filelist',
|
|
|
|
+'''please add the specified file to your %files section as %ghost so
|
|
|
|
+users can easily query who created the file, it gets uninstalled on
|
|
|
|
+package removal and finally other rpmlint checks see it''',
|
|
|
|
+'tmpfile-not-ghost',
|
|
|
|
+'''the specified file is not marked as %ghost although created at
|
|
|
|
+runtime via tmpfiles mechanism.'''
|
|
|
|
+)
|
|
|
|
+# vim: sw=4 et
|