-
Notifications
You must be signed in to change notification settings - Fork 1
/
touchup.c
70 lines (53 loc) · 1.39 KB
/
touchup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdlib.h>
#include "boc.h"
/* Compiles all the regular expressions */
int touchupFilters () {
struct Filter *filter;
for (filter = first_filter; (filter); filter = filter->next_filter) {
if (filter->regular_expression) {
regcomp(&filter->preg, filter->regular_expression, REG_NOSUB);
}
}
return 0;
}
/* Set up links between parents, children and siblings */
int touchupProcs () {
struct Process *proc;
struct Process *pproc;
for (proc = first_process; proc->next_process; proc = proc->next_process) {
/* Dummy process only used for finding siblings to init, like kthreadd */
if (proc->pid == 0) {
continue;
}
pproc = getProcByPid(proc->ppid);
if (pproc) {
addChildProc(pproc, proc);
}
}
/* Siblings added, don't need the dummy anymore */
deleteProcess(first_process);
return 0;
}
int addChildProc(struct Process * parent, struct Process * child) {
struct Process *tmp_proc;
if (parent->first_child == NULL) {
parent->first_child = child;
} else {
tmp_proc = parent->first_child;
while(tmp_proc->next_sibling) {
tmp_proc = tmp_proc->next_sibling;
}
tmp_proc->next_sibling = child;
}
child->parent = parent;
return 0;
}
struct Process * getProcByPid(unsigned int pid) {
struct Process *proc;
for (proc = first_process; (proc->next_process); proc = proc->next_process) {
if (proc->pid == pid) {
return proc;
}
}
return NULL;
}