]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
samples/bpf: run cleanup routines when receiving SIGTERM
authorAndy Gospodarek <andy@greyhouse.net>
Thu, 11 May 2017 19:52:30 +0000 (15:52 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 12 May 2017 01:43:30 +0000 (21:43 -0400)
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 <andy@greyhouse.net>
Reported-by: Shahid Habib <shahid.habib@broadcom.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
samples/bpf/cookie_uid_helper_example.c
samples/bpf/offwaketime_user.c
samples/bpf/sampleip_user.c
samples/bpf/trace_event_user.c
samples/bpf/tracex2_user.c
samples/bpf/xdp1_user.c
samples/bpf/xdp_tx_iptunnel_user.c

index b08ab4e889293c30f64b717065e6860603063f7c..9d751e209f313ca8f20a07e6d578cfb98c23defd 100644 (file)
@@ -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");
index 9cce2a66bd664c40668b3c8ca0dd12bd148bb21b..512f87a5fd20e08d0b97893b17e20e971425830e 100644 (file)
@@ -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");
index be59d7dcbdde3664c573a78d6d27adee03234a16..4ed690b907ff844961499d492350746065e423fb 100644 (file)
@@ -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",
index 0c5561d193a487f2257ccece359530b97b06a170..fa4336423da569f31fc432b9adc61f0835bb3f69 100644 (file)
@@ -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");
index 7fee0f1ba9a313baf2d233b3bf705994c183755e..7321a3f253c991f88e96f2a53e6ffa3e7c5f1719 100644 (file)
@@ -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");
index 17be9ea3ecb2f80389f37996fdab277727ecc5ed..2431c0321b712ce54d15414836b148d483a8a632 100644 (file)
@@ -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");
index 631cdcc41c97e957166f1b46cb46041ba4f2b528..715cd12eaca5c0729d11e0918e564db9e2fa980f 100644 (file)
@@ -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++);