From ce11e97f013485bdedd834b960c88a1452701648 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Tue, 6 Feb 2024 00:15:33 +0800 Subject: [PATCH 1/3] kernfs: Use a separate devpts filesystem for chroot environment IIRC we switched from separate devpts to bind mount, and matched the UID of tester with the host UID owning the TTY, to satisify the Bash test suite. But now we are always using UID 101 for tester and expect to spawn a PTY for Bash test suite (so when building LFS in a TTY owned by the root user of the host tester won't be UID 0). Thus we can switch back to a separate devpts mount which is cleaner and safer. And we are already using a separate devpts mount in Chapter 11. --- chapter07/kernfs.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/chapter07/kernfs.xml b/chapter07/kernfs.xml index 575044106..067a614f4 100644 --- a/chapter07/kernfs.xml +++ b/chapter07/kernfs.xml @@ -63,11 +63,14 @@ Now mount the remaining virtual kernel file systems: -mount -v --bind /dev/pts $LFS/dev/pts + + +mount -vt devpts devpts -o gid=5,mode=0620 $LFS/dev/pts mount -vt proc proc $LFS/proc mount -vt sysfs sysfs $LFS/sys mount -vt tmpfs tmpfs $LFS/run - + In some host systems, /dev/shm is a symbolic link to a directory, typically /run/shm. From 1fde756b121ffcba522f252475418714240358c7 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Tue, 6 Feb 2024 01:00:53 +0800 Subject: [PATCH 2/3] expect: Add (back) a simple test for PTY We used to run "expect -c 'spawn ls'" for this in Binutils, but then we thought expect test suite was enough as such a simple PTY test. However expect test can fail due to some different reason, so add back a simple test using Python pty module before building expect. Now we no longer need to consider expect test critical (IIRC there was a report saying one expect test failed for unknown reason but all other things OK). --- chapter08/expect.xml | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/chapter08/expect.xml b/chapter08/expect.xml index 810bc55a2..5c21e390f 100644 --- a/chapter08/expect.xml +++ b/chapter08/expect.xml @@ -48,6 +48,25 @@ Installation of Expect + Expect needs PTYs to work. Verify that the PTYs are working + properly inside the chroot environment by performing a simple + test: + +python3 -c 'from pty import spawn; spawn(["echo", "ok"])' + + This command should output ok. + If, instead, the output includes OSError: out of pty + devices, then the environment is not set up for proper + PTY operation. You need to exit from the chroot environment, read + again, and ensure the + devpts file system (and + other virtual kernel file systems) mounted correctly. Then reenter + the chroot environment following . + This issue needs to be resolved before continuing, or the test suites + requring Expect (for example the test suites of Bash, Binutils, GCC, + GDBM, and of course Expect itself) will fail catastrophically, and other + subtle breakages may also happen. + Prepare Expect for compilation: ./configure --prefix=/usr \ @@ -82,27 +101,10 @@ make - - The test suite for Expect is considered critical. - Do not skip it under any circumstances. - - To test the results, issue: make test - If any test fails with the message - The system has no more ptys. Ask your system - administrator to create more, it indicates - you've not mounted the - devpts file system - correctly. You need to exit from the chroot environment, read - again, and ensure the - devpts file system (and - other virtual kernel file systems) mounted correctly. Then reenter - the chroot environment following . - This issue needs to be resolved before continuing. - Install the package: make install From 4816dc69f596e962ecb050fdfea3704e65514a47 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Tue, 6 Feb 2024 03:44:38 +0800 Subject: [PATCH 3/3] bash: Really pass through the return code We want expect to return the return code of "make test" (stored in $value), but $value is expanded too early to nothing by Bash. Quote EOF so Bash won't expand $xxx. --- chapter08/bash.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter08/bash.xml b/chapter08/bash.xml index 4b5b47e62..1490e7791 100644 --- a/chapter08/bash.xml +++ b/chapter08/bash.xml @@ -83,7 +83,7 @@ Expect and run the tests as the tester user: -su -s /usr/bin/expect tester << EOF +su -s /usr/bin/expect tester << "EOF" set timeout -1 spawn make tests expect eof