Commit ad990dbe authored by Andy Gospodarek's avatar Andy Gospodarek Committed by David S. Miller

samples/bpf: run cleanup routines when receiving SIGTERM

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: default avatarAndy Gospodarek <andy@greyhouse.net>
Reported-by: default avatarShahid Habib <shahid.habib@broadcom.com>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d2be3667
...@@ -306,7 +306,9 @@ int main(int argc, char *argv[]) ...@@ -306,7 +306,9 @@ int main(int argc, char *argv[])
prog_attach_iptables(argv[2]); prog_attach_iptables(argv[2]);
if (cfg_test_traffic) { if (cfg_test_traffic) {
if (signal(SIGINT, finish) == SIG_ERR) 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) { while (!test_finish) {
print_table(); print_table();
printf("\n"); printf("\n");
......
...@@ -100,6 +100,7 @@ int main(int argc, char **argv) ...@@ -100,6 +100,7 @@ int main(int argc, char **argv)
setrlimit(RLIMIT_MEMLOCK, &r); setrlimit(RLIMIT_MEMLOCK, &r);
signal(SIGINT, int_exit); signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);
if (load_kallsyms()) { if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n"); printf("failed to process /proc/kallsyms\n");
......
...@@ -180,6 +180,7 @@ int main(int argc, char **argv) ...@@ -180,6 +180,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
signal(SIGINT, int_exit); signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);
/* do sampling */ /* do sampling */
printf("Sampling at %d Hertz for %d seconds. Ctrl-C also ends.\n", printf("Sampling at %d Hertz for %d seconds. Ctrl-C also ends.\n",
......
...@@ -192,6 +192,7 @@ int main(int argc, char **argv) ...@@ -192,6 +192,7 @@ int main(int argc, char **argv)
setrlimit(RLIMIT_MEMLOCK, &r); setrlimit(RLIMIT_MEMLOCK, &r);
signal(SIGINT, int_exit); signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);
if (load_kallsyms()) { if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n"); printf("failed to process /proc/kallsyms\n");
......
...@@ -127,6 +127,7 @@ int main(int ac, char **argv) ...@@ -127,6 +127,7 @@ int main(int ac, char **argv)
} }
signal(SIGINT, int_exit); signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);
/* start 'ping' in the background to have some kfree_skb events */ /* start 'ping' in the background to have some kfree_skb events */
f = popen("ping -c5 localhost", "r"); f = popen("ping -c5 localhost", "r");
......
...@@ -106,6 +106,7 @@ int main(int argc, char **argv) ...@@ -106,6 +106,7 @@ int main(int argc, char **argv)
} }
signal(SIGINT, int_exit); signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);
if (set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) { if (set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) {
printf("link set xdp fd failed\n"); printf("link set xdp fd failed\n");
......
...@@ -244,6 +244,7 @@ int main(int argc, char **argv) ...@@ -244,6 +244,7 @@ int main(int argc, char **argv)
} }
signal(SIGINT, int_exit); signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);
while (min_port <= max_port) { while (min_port <= max_port) {
vip.dport = htons(min_port++); vip.dport = htons(min_port++);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment