Make sure not to do an infinite loop

This commit is contained in:
GaugeK committed 2020-08-25 12:45:18 +10:00
1 parent 8b3af10779
commit 81d4666525
1 file changed
+5
+5
View File
@@ -36,8 +36,13 @@ if [ -e /proc/$$/comm ]; then
eq "$line" "PPid*" && ppid=${line##*:?} && break
done < "/proc/${ppid:-$PPID}/status"
# Make sure not to do an infinite loop
[ "$pppid" = "$ppid" ] && break
pppid="$ppid"
# get name of binary
read -r name < "/proc/$ppid/comm"
case $name in
*sh|"${0##*/}") ;; # skip shells
*[Ll]ogin*|*init*) break;; # exit when the top is reached