Reverting back to old linking code
This commit is contained in:
parent
3960919efe
commit
46e5fca147
37
src/server.c
37
src/server.c
@ -110,32 +110,29 @@ int resetVisits(Process *head) {
|
||||
|
||||
|
||||
void linkFamily(Process *head) {
|
||||
int orphans = resetVisits(head);
|
||||
int orphans = 1;
|
||||
|
||||
while (orphans) {
|
||||
Process *cur, *parent = head;
|
||||
// get next unvisited node
|
||||
while (parent != NULL && parent->visited) parent = parent->next;
|
||||
orphans = 0;
|
||||
Process *current = head;
|
||||
// while on an actual process node, and it has a parent link or doesn't need a parent link (kernel)
|
||||
while (current != NULL && (current->parent != NULL || current->ppid == current->pid)) current = current->next;
|
||||
if (current == NULL) break;
|
||||
orphans = 1;
|
||||
|
||||
if (parent == NULL) { // sanity check
|
||||
printf("Error: Found %d orphan process(es):\n", orphans);
|
||||
break;
|
||||
Process *parent = head;
|
||||
while (parent != NULL && parent->pid != current->ppid) parent = parent->next;
|
||||
if (parent == NULL) {
|
||||
printf("Found orphan process: %d\n", current->pid);
|
||||
current->ppid = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
parent->visited = 1;
|
||||
|
||||
// Search for children
|
||||
for (cur = head; cur != NULL; cur = cur->next) {
|
||||
if (cur->ppid != parent->pid) continue;
|
||||
|
||||
// We have a parent and child ready to be united
|
||||
orphans--;
|
||||
cur->parent = parent;
|
||||
// place child amongst siblings, if any are present
|
||||
// We have a parent and a child ready to be united
|
||||
current->parent = parent;
|
||||
Process **placement = &(parent->child);
|
||||
while ((*placement) != NULL) placement = &((*placement)->sibling);
|
||||
*placement = cur;
|
||||
}
|
||||
*placement = current;
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,7 +269,7 @@ char *readProcesses(char *procdir) {
|
||||
if (first < '0' || first > '9') continue;
|
||||
|
||||
if (cur->visited) {
|
||||
// get new process node if necessary
|
||||
// get new process if necessary
|
||||
prev = cur;
|
||||
cur->next = calloc(1, sizeof(Process));
|
||||
cur = cur->next;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user