top: tweak forest view protections for forking anomaly
A recent commit eliminated the potential for a storage
violation with forest view mode. It occurred when some
program (erroneously?) created a lengthy forking loop.
However, the associated commit message was misleading.
The message implied that an unexpected order following
a sort on start_time was the cause of storage overruns
and a 'char' used to track nesting level only distorts
the display when it goes negative. Actually, the truth
is really just the opposite. Any start_time sort quirk
causes no harm while that 'char' can yield corruption.
Should some child end up sorted ahead of its parent by
way of an extremely unlikely shared start_time the end
result is such a child will be displayed unnested just
like init or kthreadd along with all its own children.
However, if nesting levels exceeded 255 (and became 0)
a massive array overrun could be triggered when such a
task and *all* its children were added to an array for
the second time. Exactly how much storage was violated
depended on the number of children that zeroed process
had spawned (hinted at via either SIGSEGV or SIGABRT).
The earlier commit limited nested levels to 100 so the
root cause of the storage violation was already fixed.
The potential for distorted nesting levels due to sort
on start_time would seem to remain. But it's extremely
unlikely that 2 tasks would share the same start_time.
Even so, a new #define has been introduced which makes
top impervious to the order of tasks such that a qsort
is no longer necessary (providing an init/systemd task
exists & was harvested as the first task by readproc).
It can be utilized if distorted nesting ever becomes a
real issue. But since there is a 5-10% performance hit
with that, we'll continue using start_time as default.
References(s):
commit ce70017eb1
Signed-off-by: Jim Warner <james.warner@comcast.net>
			
			
This commit is contained in:
		
				
					committed by
					
						
						Jaromir Capik
					
				
			
			
				
	
			
			
			
						parent
						
							ce70017eb1
						
					
				
				
					commit
					da06b8fa59
				
			@@ -59,6 +59,7 @@
 | 
			
		||||
//#define STRINGCASENO            /* case insenstive compare/locate versions */
 | 
			
		||||
//#define TERMIOS_ONLY            /* just limp along with native input only  */
 | 
			
		||||
//#define TREE_NORESET            /* sort keys do NOT force forest view OFF  */
 | 
			
		||||
//#define TREE_SCANALL            /* rescan array w/ forest view, avoid sort */
 | 
			
		||||
//#define USE_X_COLHDR            /* emphasize header vs. whole col, for 'x' */
 | 
			
		||||
//#define VALIDATE_NLS            /* validate the integrity of all nls tbls  */
 | 
			
		||||
 | 
			
		||||
@@ -781,7 +782,9 @@ typedef struct WIN_t {
 | 
			
		||||
//atic void          keys_xtra (int ch);
 | 
			
		||||
/*------  Forest View support  -------------------------------------------*/
 | 
			
		||||
//atic void          forest_adds (const int self, int level);
 | 
			
		||||
#ifndef TREE_SCANALL
 | 
			
		||||
//atic int           forest_based (const proc_t **x, const proc_t **y);
 | 
			
		||||
#endif
 | 
			
		||||
//atic void          forest_create (WIN_t *q);
 | 
			
		||||
//atic inline const char *forest_display (const WIN_t *q, const proc_t *p);
 | 
			
		||||
/*------  Main Screen routines  ------------------------------------------*/
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user