Commit 7bb2fef0e2 attempted to fix
the "missing NUL-terminator in VERSION" issue by replacing the "%s"
conversion specifier with "%*s". However, this fix itself was wrong,
as "%*s" specifies the field width, i.e. _minimum_ number of characters
to print. The proper solution is to use "%.*s", which specifies the
precision, i.e. the _maximum_ number of printed characters.
The "%s" conversion specifier expects a NUL-terminated string.
However, the VERSION variable does not contain a NUL-terminator,
so formatting it using "%s" may lead to printing whatever happens
to be in memory next to VERSION.
Using "%*s" allows to specify how many characters to print,
thus making sure we don't go off the array.
There's no reason the dumb-init process should hold on to a reference
to the original cwd (but of course the child must be spawned with that
cwd). One example where that can be problematic:
# Terminal 1
$ mkdir -p /tmp/d/e
$ sudo mount --make-shared -t tmpfs tmpfs /tmp/d/e
# Terminal 2
$ docker run -v /tmp/d:/tmp/d:rshared --rm -ti --workdir /tmp/d/e some-image-with-dumb-init bash
root@922ef180b49a:/tmp/d/e# cd ..
root@922ef180b49a:/tmp/d# ls -l /proc/*/cwd
lrwxrwxrwx 1 root root 0 Oct 1 11:25 /proc/1/cwd -> /tmp/d/e
lrwxrwxrwx 1 root root 0 Oct 1 11:25 /proc/6/cwd -> /tmp/d
lrwxrwxrwx 1 root root 0 Oct 1 11:25 /proc/self/cwd -> /tmp/d
lrwxrwxrwx 1 root root 0 Oct 1 11:25 /proc/thread-self/cwd -> /tmp/d
# Terminal 1
$ sudo umount /tmp/d/e
umount: /tmp/d/e: target is busy.
i.e., the application inside the container has already let go of its
reference, but the host is not able to unmount /tmp/d/e because the
container's pid 1 still has one.
As for a test case, the 'docker run --workdir' could be emulated by
something like
sh -c "cd /tmp/d/e; exec $PWD/dumb-init bash -i"
but one would still need root to do the mount and umount.
The original sleep time is too short, the tests failed on
architectures like mips*, armhf. I think it's because the
python interpreter can't start in 0.1s.
After increasing the sleep time, it passed on most architectures
which Debian supports.
The result can be found at:
https://buildd.debian.org/status/logs.php?pkg=dumb-init
(compare the build result of 1.2.2-1.1 and 1.2.2-1)
Signed-off-by: Shengjing Zhu <zhsj@debian.org>