ostree: Prevent error on unavailable console
Task https://phabricator.apertis.org/T8906
Initramfs script local-bottom/ostree
is calling the ash built-in
command cd -
, which tries to print the target directory to stdout. In
the case the console is still unavailable, this command fails exitting
the ostree script early.
The following strace commands were run inside the initramfs ostree local-bottom script:
strace sh -c "cd / ; cd - >> /dev/null"
[...]
chdir("/") = 0
openat(AT_FDCWD, "/dev/null", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
fcntl(1, F_DUPFD_CLOEXEC, 10) = 10
dup2(3, 1) = 1
close(3) = 0
wait4(-1, 0x7ffc316043cc, WNOHANG, NULL) = -1 ECHILD (No child processes)
chdir("/") = 0
newfstatat(1, "", {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x3), ...}, AT_EMPTY_PATH) = 0
ioctl(1, TCGETS, 0x7ffc31603a90) = -1 ENOTTY (Inappropriate ioctl for device)
write(1, "/\n", 2) = 2
dup2(10, 1) = 1
close(10) = 0
getpid() = 219
exit_group(0) = ?
+++ exited with 0 +++
strace sh -c "cd / ; cd -"
[...]
chdir("/") = 0
wait4(-1, 0x7fff4d5351bc, WNOHANG, NULL) = -1 ECHILD (No child processes)
chdir("/") = 0
newfstatat(1, "", {st_mode=S_IFCHR|0600, st_rdev=makedev(0x5, 0x1), ...}, AT_EMPTY_PATH) = 0
ioctl(1, TCGETS, 0x7fff4d534880) = -1 EIO (Input/output error)
write(1, "/\n", 2) = -1 EIO (Input/output error)
getpid() = 223
exit_group(1) = ?
+++ exited with 1 +++
Note that other calls to the ash built-in cd
command aren't an issue,
as these are not trying to print anything to stdout, so they don't fail.
So let's explicitly set the target directory, instead of calling cd -
.
Another option it's to redirect cd -
output to /dev/null as that's not
really useful for logging/debugging anyway.
Signed-off-by: Ariel D'Alessandro ariel.dalessandro@collabora.com