Skip to content

Commit

Permalink
samples/bpf: run cleanup routines when receiving SIGTERM
Browse files Browse the repository at this point in the history
Shahid Habib noticed that when xdp1 was killed from a different console the xdp
program was not cleaned-up properly in the kernel and it continued to forward
traffic.

Most of the applications in samples/bpf cleanup properly, but only when getting
SIGINT.  Since kill defaults to using SIGTERM, add support to cleanup when the
application receives either SIGINT or SIGTERM.

Signed-off-by: Andy Gospodarek <[email protected]>
Reported-by: Shahid Habib <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
gospo authored and davem330 committed May 12, 2017
1 parent d2be366 commit ad990db
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion samples/bpf/cookie_uid_helper_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ int main(int argc, char *argv[])
prog_attach_iptables(argv[2]);
if (cfg_test_traffic) {
if (signal(SIGINT, finish) == SIG_ERR)
error(1, errno, "register handler failed");
error(1, errno, "register SIGINT handler failed");
if (signal(SIGTERM, finish) == SIG_ERR)
error(1, errno, "register SIGTERM handler failed");
while (!test_finish) {
print_table();
printf("\n");
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/offwaketime_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int main(int argc, char **argv)
setrlimit(RLIMIT_MEMLOCK, &r);

signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);

if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n");
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/sampleip_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ int main(int argc, char **argv)
return 1;
}
signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);

/* do sampling */
printf("Sampling at %d Hertz for %d seconds. Ctrl-C also ends.\n",
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/trace_event_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ int main(int argc, char **argv)
setrlimit(RLIMIT_MEMLOCK, &r);

signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);

if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n");
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/tracex2_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ int main(int ac, char **argv)
}

signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);

/* start 'ping' in the background to have some kfree_skb events */
f = popen("ping -c5 localhost", "r");
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/xdp1_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ int main(int argc, char **argv)
}

signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);

if (set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) {
printf("link set xdp fd failed\n");
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/xdp_tx_iptunnel_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ int main(int argc, char **argv)
}

signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);

while (min_port <= max_port) {
vip.dport = htons(min_port++);
Expand Down

0 comments on commit ad990db

Please sign in to comment.