From e210200b4cfcd5dea4e60746955468a14abf2661 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 18 Dec 2014 13:00:01 -0800 Subject: [PATCH] stage1: integrate /diagexec wrapper into rkt run Use /diagexec for launching the container's apps to assist understanding execution interpreter problems. No substantial overhead is introduced in the normal/success case, diagnostics are only attempted when execv() of the target fails. Examples of the assistance provided: ~# bin/rkt run imgs/nobash.aci # bash script without /bin/bash Error: Unable to open "/bin/bash": No such file or directory Sending SIGTERM to remaining processes... Sending SIGKILL to remaining processes... Unmounting file systems. Unmounting /proc/sys/kernel/random/boot_id. All filesystems unmounted. Halting system. ~# bin/rkt run imgs/noexec.aci # file with no execute bits Error: "/noexec.sh" is not executable Sending SIGTERM to remaining processes... Sending SIGKILL to remaining processes... Unmounting file systems. Unmounting /proc/sys/kernel/random/boot_id. All filesystems unmounted. Halting system. ~# bin/rkt run imgs/noldlinux.aci # ELF program without interp Error: Unable to open "/lib64/ld-linux-x86-64.so.2": No such file or directory Sending SIGTERM to remaining processes... Sending SIGKILL to remaining processes... Unmounting file systems. Unmounting /proc/sys/kernel/random/boot_id. All filesystems unmounted. Halting system. ~# bin/rkt run imgs/noldlinuxbash.aci # script with bash without ELF interp Error: Unable to open "/lib64/ld-linux-x86-64.so.2": No such file or directory Sending SIGTERM to remaining processes... Sending SIGKILL to remaining processes... Unmounting file systems. Unmounting /proc/sys/kernel/random/boot_id. All filesystems unmounted. Halting system. Fixes #286 --- stage1/init/container.go | 6 +++--- stage1/rootfs/aggregate/aggregate.sh | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/stage1/init/container.go b/stage1/init/container.go index 3d3969e..2c9cc16 100644 --- a/stage1/init/container.go +++ b/stage1/init/container.go @@ -83,7 +83,8 @@ func LoadContainer(root string) (*Container, error) { func (c *Container) appToSystemd(am *schema.ImageManifest, id types.Hash) error { name := am.Name.String() app := am.App - execStart := strings.Join(app.Exec, " ") + execWrap := []string{"/diagexec", rktpath.RelAppRootfsPath(id)} + execStart := strings.Join(append(execWrap, app.Exec...), " ") opts := []*unit.UnitOption{ &unit.UnitOption{"Unit", "Description", name}, &unit.UnitOption{"Unit", "DefaultDependencies", "false"}, @@ -91,7 +92,6 @@ func (c *Container) appToSystemd(am *schema.ImageManifest, id types.Hash) error &unit.UnitOption{"Unit", "OnFailure", "reaper.service"}, &unit.UnitOption{"Unit", "Wants", "exit-watcher.service"}, &unit.UnitOption{"Service", "Restart", "no"}, - &unit.UnitOption{"Service", "RootDirectory", rktpath.RelAppRootfsPath(id)}, &unit.UnitOption{"Service", "ExecStart", execStart}, &unit.UnitOption{"Service", "User", app.User}, &unit.UnitOption{"Service", "Group", app.Group}, @@ -107,7 +107,7 @@ func (c *Container) appToSystemd(am *schema.ImageManifest, id types.Hash) error default: return fmt.Errorf("unrecognized eventHandler: %v", eh.Name) } - exec := strings.Join(eh.Exec, " ") + exec := strings.Join(append(execWrap, eh.Exec...), " ") opts = append(opts, &unit.UnitOption{"Service", typ, exec}) } diff --git a/stage1/rootfs/aggregate/aggregate.sh b/stage1/rootfs/aggregate/aggregate.sh index ef39b29..b3db458 100755 --- a/stage1/rootfs/aggregate/aggregate.sh +++ b/stage1/rootfs/aggregate/aggregate.sh @@ -21,6 +21,7 @@ install -m 0644 units/reaper.service "$RD/usr/lib/systemd/system" install -m 0644 units/sockets.target "$RD/usr/lib/systemd/system" install -m 0755 scripts/reaper.sh "$RD" install -m 0755 ../shim/shim.so "$RD" +install -m 0755 ../diagexec/diagexec "$RD" ln -s shim.so "$RD/fakesdboot.so" install -d "$RD/etc"