apps.plugin: allow also pid 0; fixes #3099
Costa Tsaousis (ktsaou) committed
Jan 13, 2018 at 01:51 UTC
239224b501bc46e0743a108e143af18a0b32f1c2
1 file changed
+17
-17
src/apps_plugin.c
+17
-17
@@ -2006,8 +2006,8 @@ static int compar_pid(const void *pid1, const void *pid2) {
2006
#endif
2007
2008
static inline int collect_data_for_pid(pid_t pid, void *ptr) {
2009
- if(unlikely(pid < INIT_PID || pid > pid_max)) {
2010
- error("Invalid pid %d read (expected %d to %d). Ignoring process.", pid, INIT_PID, pid_max);
2009
+ if(unlikely(pid < 0 || pid > pid_max)) {
2010
+ error("Invalid pid %d read (expected %d to %d). Ignoring process.", pid, 0, pid_max);
2011
return 0;
2012
}
2013
@@ -2090,7 +2090,7 @@ static int collect_data_for_all_processes(void) {
2090
#endif
2091
2092
if(all_pids_count) {
2093
-#ifndef __FreeBSD__
2093
+#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
2094
size_t slc = 0;
2095
#endif
2096
for(p = root_of_pids; p ; p = p->next) {
@@ -2107,7 +2107,7 @@ static int collect_data_for_all_processes(void) {
2107
2108
#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
2109
if(unlikely(slc != all_pids_count)) {
2110
- error("Internal error: I was thinking I had %zu processes in my arrays, but it seems there are more.", all_pids_count);
2110
+ error("Internal error: I was thinking I had %zu processes in my arrays, but it seems there are %zu.", all_pids_count, slc);
2111
all_pids_count = slc;
2112
}
2113
@@ -2130,7 +2130,7 @@ static int collect_data_for_all_processes(void) {
2130
}
2131
2132
#ifdef __FreeBSD__
2133
- for (i = INIT_PID; i < procnum - INIT_PID; ++i) {
2133
+ for (i = 0 ; i < procnum ; ++i) {
2134
pid_t pid = procbase[i].ki_pid;
2135
collect_data_for_pid(pid, &procbase[i]);
2136
}
@@ -2258,21 +2258,17 @@ static void apply_apps_groups_targets_inheritance(void) {
2258
if(unlikely(!p->sortlist && !p->children_count))
2259
p->sortlist = sortlist++;
2260
2261
- // if this process does not have any children
2262
- // and is not already merged
2263
- // and has a parent
2264
- // and its parent has children
2265
- // and the target of this process and its parent is the same, or the parent does not have a target
2266
- // and its parent is not init
2267
- // then, mark them as merged.
2261
if(unlikely(
2269
- !p->children_count
2270
- && !p->merged
2271
- && p->parent
2272
- && p->parent->children_count
2262
+ !p->children_count // if this process does not have any children
2263
+ && !p->merged // and is not already merged
2264
+ && p->parent // and has a parent
2265
+ && p->parent->children_count // and its parent has children
2266
+ // and the target of this process and its parent is the same,
2267
+ // or the parent does not have a target
2268
&& (p->target == p->parent->target || !p->parent->target)
2274
- && p->ppid != INIT_PID
2269
+ && p->ppid != INIT_PID // and its parent is not init
2270
)) {
2271
+ // mark it as merged
2272
p->parent->children_count--;
2273
p->merged = 1;
2274
@@ -2296,6 +2292,10 @@ static void apply_apps_groups_targets_inheritance(void) {
2292
if(all_pids[INIT_PID])
2293
all_pids[INIT_PID]->target = apps_groups_default_target;
2294
2295
+ // pid 0 goes always to default target
2296
+ if(all_pids[0])
2297
+ all_pids[0]->target = apps_groups_default_target;
2298
+
2299
// give a default target on all top level processes
2300
if(unlikely(debug)) loops++;
2301
for(p = root_of_pids; p ; p = p->next) {