initrd/oinit: chdir to the new root before chroot to it
authorAaron LI <aly@aaronly.me>
Mon, 12 Mar 2018 04:10:39 +0000 (12:10 +0800)
committerSascha Wildner <saw@online.de>
Mon, 12 Mar 2018 07:23:06 +0000 (08:23 +0100)
commite112f3ff35c1e493d85b52014ad2bbdf7c9a9c39
tree919be21bc012c4028016489eb804e17fda471209
parentedf97230c34f43fa86b2725b3e6fd1daef309ea9
initrd/oinit: chdir to the new root before chroot to it

chroot(2) doesn't change the working directory of the current process,
therefore a single chroot(2) to a new root (during the early boot with
encrypted root) causes getcwd(3) fail, which further causes problems for
some rc scripts.

For example:
Without this fix, and by placing a 'echo "PWD=`pwd`"' to the beginning
of /etc/rc, the following messages were logged on the console:
Mar 12 10:40:28 dfly kernel: pwd: .: No such file or directory
Mar 12 10:40:28 dfly kernel: PWD=

Another example with "unbound" rc start:
Mar  3 09:28:11 dfly kernel: Obtaining a trust anchor:
Mar  3 09:28:11 dfly kernel: _su: No such file or directory
Mar  3 09:28:11 dfly kernel: _su: Trying to start from "/"
Mar  3 09:28:12 dfly kernel: .
Mar  3 09:28:12 dfly kernel: [1520040492] unbound-checkconf[1138:0] error: cannot getcwd: No such file or directory
Mar  3 09:28:12 dfly kernel: Starting unbound.
Mar  3 09:28:12 dfly kernel: [1520040492] unbound[1139:0] warning: unbound is already running as pid 1139.

uWSGI rc startup also failed to setup correct working directory due to
this problem.
share/initrd/mini_init/oinit.c