Skip to content

Commit

Permalink
[daemon] Simplify loops
Browse files Browse the repository at this point in the history
  • Loading branch information
strang1ato committed Sep 17, 2023
1 parent f3da320 commit 00c63b8
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions daemon/src/nhi.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void handle_kill_SIGUSR(struct kill_event *kill_event)
meta_create_row(db, indicator);

int i = 0;
for (int j = 0; j<SHELLS_MAX_ENTRIES; j++) {
while (i<SHELLS_MAX_ENTRIES) {
struct shell shell;
bpf_map_lookup_elem(shells_fd, &i, &shell);
if (!shell.shell_pid) {
Expand Down Expand Up @@ -288,16 +288,14 @@ void handle_kill_SIGRTMIN(struct kill_event *kill_event, size_t data_sz)
long indicator = 0;
char ***environ_address = 0;
{
int i = 0;
for (int j = 0; j<SHELLS_MAX_ENTRIES; j++) {
for (int i = 0; i<SHELLS_MAX_ENTRIES; i++) {
struct shell shell;
bpf_map_lookup_elem(shells_fd, &i, &shell);
if (shell.shell_pid == kill_event->shell_pid) {
indicator = shell.indicator;
environ_address = shell.environ_address;
break;
}
i++;
}
}
get_shell_environ(kill_event->shell_pid, environ_address);
Expand All @@ -324,15 +322,13 @@ void handle_child_creation(pid_t *shell_pid)
// find indicator of the shell
long indicator = 0;
{
int i = 0;
for (int j = 0; j<SHELLS_MAX_ENTRIES; j++) {
for (int i = 0; i<SHELLS_MAX_ENTRIES; i++) {
struct shell shell;
bpf_map_lookup_elem(shells_fd, &i, &shell);
if (shell.shell_pid == *shell_pid) {
indicator = shell.indicator;
break;
}
i++;
}
}

Expand Down

0 comments on commit 00c63b8

Please sign in to comment.