[explorer/init] Linux is a mess...
This commit is contained in:
parent
de1a421b68
commit
4fe2dcba89
1 changed files with 39 additions and 5 deletions
|
@ -25,14 +25,48 @@
|
||||||
|
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
if command -v pgrep >/dev/null
|
if test -d /proc/1/
|
||||||
then
|
then
|
||||||
# BusyBox's version of ps does not support some options.
|
comm_name=$(cat /proc/1/comm)
|
||||||
# On Linux systems, we prefer pgrep to get the name of PID1.
|
|
||||||
(pgrep -P0 -l | awk '/^1[ \t]/ {print $2;}') || true
|
|
||||||
else
|
else
|
||||||
ps -o comm= -p 1 2>/dev/null || cat /proc/1/comm
|
# BusyBox's versions of ps and pgrep do not support some options
|
||||||
|
# depending on which compile-time options have been used.
|
||||||
|
# Both pgrep and ps are tried to get the command name
|
||||||
|
comm_name=$(
|
||||||
|
pgrep -P0 -l 2>/dev/null | awk '/^1[ \t]/ { print $2 }'
|
||||||
|
|| ps -o comm= -p 1 2>/dev/null)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
case $comm_name
|
||||||
|
in
|
||||||
|
systemd)
|
||||||
|
echo systemd
|
||||||
|
;;
|
||||||
|
init)
|
||||||
|
# It could be anything...
|
||||||
|
|
||||||
|
if test -h /proc/1/exe
|
||||||
|
then
|
||||||
|
init_exe=/proc/1/exe
|
||||||
|
else
|
||||||
|
init_exe=$(command -v "$comm_name")
|
||||||
|
fi
|
||||||
|
|
||||||
|
test -x "$comm_exe" || exit 1
|
||||||
|
|
||||||
|
case $("$comm_exe" --version | head -n 1)
|
||||||
|
in
|
||||||
|
*SysV*)
|
||||||
|
echo init
|
||||||
|
;;
|
||||||
|
*upstart*)
|
||||||
|
echo upstart
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo ""
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
esac
|
||||||
;;
|
;;
|
||||||
FreeBSD|OpenBSD)
|
FreeBSD|OpenBSD)
|
||||||
ps -o comm= -p 1 2>/dev/null || true
|
ps -o comm= -p 1 2>/dev/null || true
|
||||||
|
|
Loading…
Reference in a new issue