]> code.ossystems Code Review - openembedded-core.git/commitdiff
image/image_types.bbclass: fix fatal error during cpio debugfs creation
authorAndré Draszik <adraszik@tycoint.com>
Fri, 10 Jun 2016 15:11:38 +0000 (16:11 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 12 Jun 2016 22:46:45 +0000 (23:46 +0100)
If /init is just a symlink to /sbin/init, debugfs creation
fails with the following error:

ERROR: Error: The image creation script '<...>/debugfs.create_image.cpio' returned 1:
touch: cannot touch '<...>/cpio_append/init': Permission denied
WARNING: exit code 1 from a shell command.

ERROR: Function failed: do_rootfs

The reason is that IMAGE_CMD_cpio() is run twice on the same
WORKDIR. The first run creates a symlink in WORKDIR/cpio_append/init
to point to /sbin/init, while the 2nd run then tries to 'touch'
that link, which will fail, of course since /sbin/init is not
usually writable by non-root users.

Fix this by providing knowledge to the IMAGE_CMD_xxx() scripts
with regards to the fact that they are being executed in the
context of debugfs creation. The IMAGE_CMD_cpio() can now be
intelligent in the sense that it can avoid all additional symlink
handling during the debugfs run. The symlinks do not need to
be part of the debugfs, so we can skip that part altogether
in that case.

Signed-off-by: André Draszik <adraszik@tycoint.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/classes/image.bbclass
meta/classes/image_types.bbclass

index 9f4c83ffc64c6082431ba8bddee9b8d629a3a2ed..65ce6bb5244920aaf3fc71ea763877dc01a8d2a6 100644 (file)
@@ -287,6 +287,7 @@ def setup_debugfs_variables(d):
     d.appendVar('IMAGE_ROOTFS', '-dbg')
     d.appendVar('IMAGE_LINK_NAME', '-dbg')
     d.appendVar('IMAGE_NAME','-dbg')
+    d.setVar('IMAGE_BUILDING_DEBUGFS', 'true')
     debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS', True)
     if debugfs_image_fstypes:
         d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes)
index ea45809a39dd674ce392f30b6c934ce05a833a56..72e8ed34d5af31b0b2fac5bc50459197209a2073 100644 (file)
@@ -101,13 +101,20 @@ IMAGE_CMD_tar = "${IMAGE_CMD_TAR} -cvf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}${IMAGE_
 do_image_cpio[cleandirs] += "${WORKDIR}/cpio_append"
 IMAGE_CMD_cpio () {
        (cd ${IMAGE_ROOTFS} && find . | cpio -o -H newc >${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cpio)
-       if [ ! -L ${IMAGE_ROOTFS}/init -a ! -e ${IMAGE_ROOTFS}/init ]; then
-               if [ -L ${IMAGE_ROOTFS}/sbin/init -o -e ${IMAGE_ROOTFS}/sbin/init ]; then
-                       ln -sf /sbin/init ${WORKDIR}/cpio_append/init
-               else
-                       touch ${WORKDIR}/cpio_append/init
+       # We only need the /init symlink if we're building the real
+       # image. The -dbg image doesn't need it! By being clever
+       # about this we also avoid 'touch' below failing, as it
+       # might be trying to touch /sbin/init on the host since both
+       # the normal and the -dbg image share the same WORKDIR
+       if [ "${IMAGE_BUILDING_DEBUGFS}" != "true" ]; then
+               if [ ! -L ${IMAGE_ROOTFS}/init ] && [ ! -e ${IMAGE_ROOTFS}/init ]; then
+                       if [ -L ${IMAGE_ROOTFS}/sbin/init ] || [ -e ${IMAGE_ROOTFS}/sbin/init ]; then
+                               ln -sf /sbin/init ${WORKDIR}/cpio_append/init
+                       else
+                               touch ${WORKDIR}/cpio_append/init
+                       fi
+                       (cd  ${WORKDIR}/cpio_append && echo ./init | cpio -oA -H newc -F ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cpio)
                fi
-               (cd  ${WORKDIR}/cpio_append && echo ./init | cpio -oA -H newc -F ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cpio)
        fi
 }