Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
ostro-sanity.bbclass: add do_image QA check for dangling symlinks
Browse files Browse the repository at this point in the history
Dangling symlinks have been a problem in particular in swupd-based
images, because it can happen that the actual file that gets pointed
to is only part of a bundle, while the link is part of the os-core.

This new check covers this. It gets applied to all images, whether
they are based on swupd or not, because we also do not want dangling
symlinks in non-swupd images.

Signed-off-by: Patrick Ohly <[email protected]>
  • Loading branch information
pohly committed Apr 7, 2016
1 parent 246f22a commit d6e6fb3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions meta-ostro/classes/ostro-sanity.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,57 @@ python ostro_sanity_check_eventhandler() {
production and development images. See the comments in local.conf.sample
and doc/howtos/building-images.rst.''')
}

# /run, /proc, /var/volatile and /dev only get mounted at runtime.
OSTRO_QA_IMAGE_SYMLINK_WHITELIST = " \
/dev/null \
/proc/mounts \
/run/lock \
/run/resolv.conf \
/var/volatile/log \
/var/volatile/tmp \
"

# Additional image checks.
python ostro_qa_image () {
qa_sane = True

rootfs = d.getVar("IMAGE_ROOTFS", True)

def resolve_links(target, root):
if not target.startswith('/'):
target = os.path.normpath(os.path.join(root, target))
else:
# Absolute links are in fact relative to the rootfs.
# Can't use os.path.join() here, it skips the
# components before absolute paths.
target = os.path.normpath(rootfs + target)
if os.path.islink(target):
root = os.path.dirname(target)
target = os.readlink(target)
target = resolve_links(target, root)
return target

# Check for dangling symlinks. One common reason for them
# in swupd images is update-alternatives where the alternative
# that gets chosen in the mega image then is not installed
# in a sub-image.
#
# Some allowed cases are whitelisted.
whitelist = d.getVar('OSTRO_QA_IMAGE_SYMLINK_WHITELIST', True).split()
for root, dirs, files in os.walk(rootfs):
for entry in files + dirs:
path = os.path.join(root, entry)
if os.path.islink(path):
target = os.readlink(path)
final_target = resolve_links(target, root)
if not os.path.exists(final_target) and not final_target[len(rootfs):] in whitelist:
bb.error("Dangling symlink: %s -> %s -> %s does not resolve to a valid filesystem entry." %
(path, target, final_target))
qa_sane = False

if not qa_sane:
bb.fatal("Fatal QA errors found, failing task.")
}

do_image[postfuncs] += "ostro_qa_image"

0 comments on commit d6e6fb3

Please sign in to comment.