git: 9front

Download patch

ref: a33545d83c124af3e97bd95acff1a22906891801
parent: 99fdbe3ace470804442c4f7415d8d115df95fd5f
author: qwx <qwx@sciops.net>
date: Sun Nov 3 09:58:56 EST 2024

pstree: remove unnecessary globbing and environment pollution (thanks cgnarne, cinap_lenrek)

--- a/rc/bin/pstree
+++ b/rc/bin/pstree
@@ -1,9 +1,7 @@
 #!/bin/rc
-p=0
-if(! ~ $#* 0)
-	p=$1
-cd /proc || exit
-ls -d [0-9]* | sort -n | awk -v 'this='^$p '
+if(~ $#* 0)
+	*=0
+cd /proc && ls | sort -n | awk -v 'this='^$1 '
 function cat(f,	v){
 	getline v < f
 	close(f)
@@ -12,7 +10,7 @@
 BEGIN{
 	OFS="\t"
 }
-{
+/^[0-9]+/ {
 	s = cat($1"/args")
 	if(s == ""){
 		s = cat($1"/status")
@@ -41,7 +39,7 @@
 END{
 	for(i=1; i<=length(pid); i++){
 		p = pid[i]
-		if(!(ppid[p] in proc) && ppid[p] != 0)
+		if(p && !(ppid[p] in proc) && ppid[p] != 0)
 			child[0,++nchild[0]] = p
 	}
 	out(this, "", "", 0)
--