init: disable all userland processes started from init

In order to make the system easier to understand.

These include:

* networking
* klogd and syslogd. TODO what are those for? I could not see anything useful that they do.

Also get rid of the useless S20random thing while we are at it.
This commit is contained in:
Ciro Santilli
2018-03-25 19:01:24 +01:00
parent 2927ed330a
commit 2656202dff
6 changed files with 39 additions and 61 deletions

View File

@@ -846,7 +846,9 @@ But TODO I don't think you can see where you are in the kernel source code and l
Step debug userland processes to understand how they are talking to the kernel.
In guest:
First ensure that <<networking>> is enabled.
Then in guest:
....
/gdbserver.sh /myinsmod.out /hello.ko
@@ -1138,16 +1140,38 @@ Finally, the docs are lying, arguments with dots that come after `-` are still t
./run -e 'init=/init_env_poweroff.sh - /poweroff.out'
....
=== Disable networking
=== Networking
The default BusyBox init scripts enable networking, and there is a 15 second timeout in case your network is down or if your kernel / emulator setup does not support it.
We disable networking by default because it starts an userland process, and we want to keep the number of userland processes to a minimum to make the system more understandable.
We have hacked it up so that you can disable networking with:
To enable it run:
....
./run -f 'lkmc_nonet=y'
/sbin/ifup -a
....
To disable it, run:
....
/sbin/ifdown -a
....
To test it out, try:
....
wget google.com
....
BusyBox' `ping` does not work with hostnames even when networking is working fine:
....
ping google.com
....
TODO why: https://unix.stackexchange.com/questions/124283/busybox-ping-ip-works-but-hostname-nslookup-fails-with-bad-address
To enable networking by default, use the methods documented at <<automatic-startup-commands>>
== KVM
You can make QEMU or gem5 <<gem5-vs-qemu-performance,run faster>> by passing enabling KVM with:
@@ -1864,6 +1888,8 @@ Even mor awesome than `chroot` be to `pivot_root`, but I couldn't get that worki
=== Guest host networking
First ensure that networking is enabled before trying out anything in this section: <<networking>>
==== Host to guest networking
Guest, BusyBox `nc` enabled with `CONFIG_NC=y`:

View File

@@ -1,44 +0,0 @@
#!/bin/sh
# Copied from: package/ifupdown-scripts/S40network at
# 8ce27bb9fee80a406a4199657ef90e3c315e7457
#
# We then just added this line to turn it off at runtime.
#
# We also considered copying the file at build to / and then
# sourcing it from S98 to be a bit DRYer, but it wouldn't work
# very well if some S50 requires networking to work.
#
# This became necessary nitially when aarch64 qemu and gem5
# started using the same Buildroot output directory.
[ -n "$lkmc_nonet" ] && exit 0
#
# Start the network....
#
# Debian ifupdown needs the /run/network lock directory
mkdir -p /run/network
case "$1" in
start)
printf "Starting network: "
/sbin/ifup -a
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
stop)
printf "Stopping network: "
/sbin/ifdown -a
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

View File

@@ -3,16 +3,8 @@ set -ex
/rand_check.out
# Check if network is being replayed.
#
# TODO; requires internet to be up, which is done by inittab.
# We could do this with a /etc/init.d/SXX file,
# but how to both check that into git, and make it optional?
#
# https://superuser.com/questions/635020/how-to-know-current-time-from-internet-from-command-line-in-linux
# Raw IP because was failing with hostname:
# https://unix.stackexchange.com/questions/124283/busybox-ping-ip-works-but-hostname-nslookup-fails-with-bad-address
# https://tf.nist.gov/tf-cgi/servers.cgi
#
#echo | nc 129.6.15.28 13
# busybox's poweroff panics, TODO why. Likely tries to kill shell.

View File

@@ -9,3 +9,10 @@ mkdir -p \
"${target_dir}/mnt/9p" \
"${target_dir}/mnt/out" \
;
# Maybe there is a cleaner way to get rid of those files,
# like disabling some Buildroot packages, but no patience.
rm -rf \
"${target_dir}/etc/init.d/S01logging" \
"${target_dir}/etc/init.d/S20urandom" \
"${target_dir}/etc/init.d/S40network" \
;

3
run
View File

@@ -108,9 +108,6 @@ if "$nographic" && [ "$arch" = x86_64 ]; then
extra_append="$extra_append console=ttyS0"
extra_flags_qemu="$extra_flags_qemu -nographic"
fi
if "$gem5"; then
extra_append_after_dash="${extra_append_after_dash} lkmc_nonet=y"
fi
if [ -n "$extra_append_after_dash" ]; then
extra_append="${extra_append} - ${extra_append_after_dash}"
fi

View File

@@ -23,7 +23,7 @@
add a dash `-` separator, and place the options after the dash.
Intended for custom options understood by our `init` scripts,
most of which are prefixed by `lkmc_`, e.g.:
`./run -f 'lkmc_eval="wget google.com" lkmc_nonet=y'`
`./run -f 'lkmc_eval="wget google.com" lkmc_lala=y'`
Mnenomic: comes after `-e`.
|`-G` | | Pass extra options to the gem5 executable.
Only useful if `-g` is given.