1
1
/*
2
- ** ATOP - System & Process Monitor
3
- **
2
+ ** ATOP - System & Process Monitor
3
+ **
4
4
** The program 'atop' offers the possibility to view the activity of
5
5
** the system on system-level as well as process-/thread-level.
6
- **
6
+ **
7
7
** This source-file contains functions to read the process-administration
8
8
** of every running process from kernel-space and extract the required
9
9
** activity-counters.
@@ -118,10 +118,13 @@ photoproc(struct tstat *tasklist, int maxtask)
118
118
{
119
119
char line [128 ];
120
120
121
- if (fgets (line , sizeof line , fp ))
121
+ while (fgets (line , sizeof line , fp ))
122
122
{
123
123
if (memcmp (line , "0::" , 3 ) == 0 ) // equal?
124
+ {
124
125
supportflags |= CGROUPV2 ;
126
+ break ;
127
+ }
125
128
}
126
129
127
130
fclose (fp );
@@ -144,20 +147,20 @@ photoproc(struct tstat *tasklist, int maxtask)
144
147
*/
145
148
regainrootprivs ();
146
149
147
- /*
148
- ** if kernel module is not active on this system,
150
+ /*
151
+ ** if kernel module is not active on this system,
149
152
** netatop-bpf will try tp run;
150
153
*/
151
154
if (!(supportflags & NETATOPD )) {
152
155
netatop_bpf_probe ();
153
156
}
154
- /*
155
- ** if netatop-bpf is not active on this system,
157
+ /*
158
+ ** if netatop-bpf is not active on this system,
156
159
** kernel module will try to run;
157
160
*/
158
161
if (!(supportflags & NETATOPBPF )) {
159
162
netatop_probe ();
160
- }
163
+ }
161
164
162
165
/*
163
166
** if netatop-bpf is active on this system, skip call
@@ -245,7 +248,7 @@ photoproc(struct tstat *tasklist, int maxtask)
245
248
*/
246
249
if (getwchan )
247
250
procwchan (curtask );
248
-
251
+
249
252
if (supportflags & NETATOPBPF ) {
250
253
struct taskcount * tc = g_hash_table_lookup (ghash_net , & (curtask -> gen .tgid ));
251
254
if (tc ) {
@@ -288,7 +291,7 @@ photoproc(struct tstat *tasklist, int maxtask)
288
291
*/
289
292
curtask -> cpu .rundelay = 0 ;
290
293
curtask -> cpu .blkdelay = 0 ;
291
-
294
+
292
295
/*
293
296
** nvcsw and nivcsw on process level only
294
297
** concerns the delays of the main thread;
@@ -305,15 +308,15 @@ photoproc(struct tstat *tasklist, int maxtask)
305
308
unsigned long cur_nth = 0 ;
306
309
307
310
dirtask = opendir ("." );
308
-
311
+
309
312
/*
310
313
** due to race condition, opendir() might
311
314
** have failed (leave task and process-level
312
315
** directories)
313
316
*/
314
- if ( dirtask == NULL )
317
+ if ( dirtask == NULL )
315
318
{
316
- if (chdir ("../.." ) == -1 );
319
+ if (chdir ("../.." ) == -1 );
317
320
continue ;
318
321
}
319
322
@@ -333,7 +336,7 @@ photoproc(struct tstat *tasklist, int maxtask)
333
336
if ( chdir (".." ) == -1 );
334
337
continue ;
335
338
}
336
-
339
+
337
340
if ( !procstatus (curthr ) )
338
341
{
339
342
if ( chdir (".." ) == -1 );
@@ -442,7 +445,7 @@ counttasks(void)
442
445
char origdir [1024 ];
443
446
444
447
/*
445
- ** determine total number of threads
448
+ ** determine total number of threads
446
449
*/
447
450
if ( (fp = fopen ("/proc/loadavg" , "r" )) != NULL )
448
451
{
@@ -461,7 +464,7 @@ counttasks(void)
461
464
462
465
463
466
/*
464
- ** add total number of processes
467
+ ** add total number of processes
465
468
*/
466
469
if ( getcwd (origdir , sizeof origdir ) == NULL )
467
470
mcleanstop (53 , "cannot determine cwd\n" );
@@ -983,7 +986,7 @@ procschedstat(struct tstat *curtask)
983
986
static char * schedstatfile = "schedstat" ;
984
987
985
988
/*
986
- ** open the schedstat file
989
+ ** open the schedstat file
987
990
*/
988
991
if ( (fp = fopen (schedstatfile , "r" )) )
989
992
{
@@ -1057,38 +1060,42 @@ proccgroupv2(struct tstat *curtask)
1057
1060
1058
1061
/*
1059
1062
** open the cgroup file of the current process and
1060
- ** read one line that should start with '0::' for cgroup v2
1063
+ ** read the line that starts with '0::' for cgroup v2
1061
1064
*/
1065
+ curtask -> gen .cgpath [0 ] = '\0' ;
1066
+
1062
1067
if ( (fp = fopen ("cgroup" , "r" )) )
1063
1068
{
1064
- if (fgets (line , sizeof line , fp ))
1069
+ while (fgets (line , sizeof line , fp ))
1065
1070
{
1066
- if ( memcmp (line , "0::" , 3 ) ) // unequal ?
1071
+ if ( memcmp (line , "0::" , 3 ) == 0 ) // equal ?
1067
1072
{
1068
- fclose (fp );
1069
- curtask -> gen .cgpath [0 ] = '\0' ;
1070
- return 0 ; // no cgroupv2 support
1073
+ line [ strlen (line )- 1 ] = '\0' ; // remove newline
1074
+
1075
+ relpath = line + 3 ;
1076
+
1077
+ strncpy (curtask -> gen .cgpath , relpath ,
1078
+ sizeof curtask -> gen .cgpath );
1079
+
1080
+ curtask -> gen .cgpath [sizeof curtask -> gen .cgpath - 1 ] = '\0' ;
1081
+
1082
+ break ;
1071
1083
}
1072
1084
}
1073
- fclose (fp );
1074
1085
1075
- line [ strlen (line )- 1 ] = '\0' ; // remove newline
1076
-
1077
- relpath = line + 3 ;
1086
+ fclose (fp );
1078
1087
1079
- strncpy (curtask -> gen .cgpath , relpath ,
1080
- sizeof curtask -> gen .cgpath );
1081
- curtask -> gen .cgpath [sizeof curtask -> gen .cgpath - 1 ] = '\0' ;
1088
+ if (curtask -> gen .cgpath [0 ] == '\0' )
1089
+ return 0 ; // no cgroupv2 support
1082
1090
}
1083
1091
else // open failed; no permission
1084
1092
{
1085
- curtask -> gen .cgpath [0 ] = '\0' ;
1086
1093
return 2 ;
1087
1094
}
1088
1095
1089
1096
/*
1090
1097
** cgroup v2 pathname of this process is known;
1091
- ** prepare absolute pathname of cgroup
1098
+ ** prepare absolute pathname of cgroup
1092
1099
*/
1093
1100
pathlen = snprintf (abspath , sizeof abspath , "%s%s/" ,
1094
1101
CGROUPROOT , relpath );
@@ -1293,7 +1300,7 @@ fillcgroupv2(struct cgroupv2vals *pvals, char *abspath, char *extpath,
1293
1300
**
1294
1301
** return value: number of entries in retvals filled
1295
1302
*/
1296
- int
1303
+ int
1297
1304
readcgroupv2 (char * abspath , char * extpath , char * fname , int restlen ,
1298
1305
long retvals [])
1299
1306
{
@@ -1343,7 +1350,7 @@ readcgroupv2(char *abspath, char *extpath, char *fname, int restlen,
1343
1350
*/
1344
1351
static struct cgroupv2vals *
1345
1352
findhashcgroupv2 (char * relpath , int * phash )
1346
- {
1353
+ {
1347
1354
struct cgroupv2vals * p ;
1348
1355
char * s ;
1349
1356
int hash = 0 ;
0 commit comments