Sweets / hummingbird

Hummingbird init system for Linux based operating systems.
MIT License
247 stars 7 forks source link

While there is a handler case for SIGCHLD, it is never registered with signal #15

Closed 20kdc closed 3 years ago

20kdc commented 3 years ago

See #14 Zombies remain very unreaped, which appears to have caused trouble for a friend of mine using FVWM. I have also confirmed this by constructing an environment using the following (very terrible) script and creating zombies by nesting sh processes and killing them.

This was tested under commit 6ba337adc4aec900e6e2b4df287676378fe5d746.

#!/bin/sh

rm -rf /media/ramdisk/summoner-mount-namespace

SMM=/media/ramdisk/summoner-mount-namespace

mkdir -p $SMM/usr/bin
mkdir -p $SMM/bin
mkdir -p $SMM/usr/sbin
mkdir -p $SMM/sbin
mkdir -p $SMM/usr/lib/hummingbird
mkdir -p $SMM/dev
mkdir -p $SMM/etc
mkdir -p $SMM/proc
mkdir -p $SMM/sys

cp hummingbird $SMM/usr/bin/hummingbird
cp usr/lib/hummingbird/* $SMM/usr/lib/hummingbird/
cp /usr/bin/busybox $SMM/bin/busybox

chmod +x $SMM/usr/lib/hummingbird/*

# This script ever returning indicates "init failed" to hummingbird.
# And we have no real TTYs.
echo "#!/bin/sh" > $SMM/usr/lib/hummingbird/tty
echo "exec sh" >> $SMM/usr/lib/hummingbird/tty

# "pre-heat" environment
unshare -m -R $SMM /bin/busybox --install -s

unshare -m -p -f -R $SMM /usr/bin/hummingbird

To create a zombie:

20kdc@Magnus:/media/20kdc/6d58dae8-1885-49fc-a0c2-ad587ec9e7b9/External2/hummingbird$ sudo ./summoner
mount: mounting remount,rw on / failed: No such file or directory
mount: can't read '/etc/fstab': No such file or directory
swapon: can't open '/etc/fstab': No such file or directory

BusyBox v1.30.1 (Ubuntu 1:1.30.1-4ubuntu6.3) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/ # sh
<omitted...>
/ # sh
<omitted...>
/ # sh
<omitted...>
/ # ps -e
PID   USER     COMMAND
    1 0        /usr/bin/hummingbird
   14 0        /usr/bin/hummingbird
   15 0        sh
   16 0        sh
   17 0        sh
   18 0        sh
   19 0        {ps} sh
/ # kill -KILL 16
/ # Killed
/ # [1]+  Stopped (tty input)        sh
/ # fg
sh

/ # exit
/ # exit

Then from outside the namespace, check top:

  13291 root      20   0    2616   1624   1528 S   0.0   0.0   0:00.00              `- summoner                                                                                                                    
  13307 root      20   0    9124    584    520 S   0.0   0.0   0:00.00                  `- unshare                                                                                                                 
  13308 root      20   0    1084      4      0 S   0.0   0.0   0:00.00                      `- hummingbird                                                                                                         
  13321 root      20   0    1084     48      8 S   0.0   0.0   0:00.00                          `- hummingbird                                                                                                     
  13322 root      20   0    2428      4      0 T   0.0   0.0   0:00.00                              `- sh                                                                                                          
  13324 root      20   0       0      0      0 Z   0.0   0.0   0:00.00                          `- sh 

The entry with a Z here is the zombie. Alternatively, ps -e will show a process as 13595 pts/2 00:00:00 sh <defunct>. (This is from a different run, so a different PID.)

The zombie process will be cleaned up by the outer init when hummingbird terminates.

The zombies can be reaped by adding signal(SIGCHLD, handler); past the other two signal calls in hummingbird.c.

Sweets commented 3 years ago

Should be good as of 017735f, sorry I have brain rot.

Let me know

20kdc commented 3 years ago

Well, a change almost exactly equivalent in text (slight spacing difference) to that commit was already being tested, and the zombie problem is apparently now solved in all the places where init is supposed to be doing the zombie-reaping, so yeah, should be fine also, thank you