diff options
author | Andy Gospodarek <andy@greyhouse.net> | 2017-05-11 15:52:30 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-05-11 21:43:30 -0400 |
commit | ad990dbe6d3ac3af1f5f4484b1126b9fc601e98a (patch) | |
tree | dd21487768f0a759ea6c2432c58e4a459fc9e183 | |
parent | d2be3667f3769b3c60aa294ef7f2b03d1b16559c (diff) |
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: 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>
-rw-r--r-- | samples/bpf/cookie_uid_helper_example.c | 4 | ||||
-rw-r--r-- | samples/bpf/offwaketime_user.c | 1 | ||||
-rw-r--r-- | samples/bpf/sampleip_user.c | 1 | ||||
-rw-r--r-- | samples/bpf/trace_event_user.c | 1 | ||||
-rw-r--r-- | samples/bpf/tracex2_user.c | 1 | ||||
-rw-r--r-- | samples/bpf/xdp1_user.c | 1 | ||||
-rw-r--r-- | samples/bpf/xdp_tx_iptunnel_user.c | 1 |
7 files changed, 9 insertions, 1 deletions
diff --git a/samples/bpf/cookie_uid_helper_example.c b/samples/bpf/cookie_uid_helper_example.c index b08ab4e88929..9d751e209f31 100644 --- a/samples/bpf/cookie_uid_helper_example.c +++ b/samples/bpf/cookie_uid_helper_example.c | |||
@@ -306,7 +306,9 @@ int main(int argc, char *argv[]) | |||
306 | prog_attach_iptables(argv[2]); | 306 | prog_attach_iptables(argv[2]); |
307 | if (cfg_test_traffic) { | 307 | if (cfg_test_traffic) { |
308 | if (signal(SIGINT, finish) == SIG_ERR) | 308 | if (signal(SIGINT, finish) == SIG_ERR) |
309 | error(1, errno, "register handler failed"); | 309 | error(1, errno, "register SIGINT handler failed"); |
310 | if (signal(SIGTERM, finish) == SIG_ERR) | ||
311 | error(1, errno, "register SIGTERM handler failed"); | ||
310 | while (!test_finish) { | 312 | while (!test_finish) { |
311 | print_table(); | 313 | print_table(); |
312 | printf("\n"); | 314 | printf("\n"); |
diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c index 9cce2a66bd66..512f87a5fd20 100644 --- a/samples/bpf/offwaketime_user.c +++ b/samples/bpf/offwaketime_user.c | |||
@@ -100,6 +100,7 @@ int main(int argc, char **argv) | |||
100 | setrlimit(RLIMIT_MEMLOCK, &r); | 100 | setrlimit(RLIMIT_MEMLOCK, &r); |
101 | 101 | ||
102 | signal(SIGINT, int_exit); | 102 | signal(SIGINT, int_exit); |
103 | signal(SIGTERM, int_exit); | ||
103 | 104 | ||
104 | if (load_kallsyms()) { | 105 | if (load_kallsyms()) { |
105 | printf("failed to process /proc/kallsyms\n"); | 106 | printf("failed to process /proc/kallsyms\n"); |
diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c index be59d7dcbdde..4ed690b907ff 100644 --- a/samples/bpf/sampleip_user.c +++ b/samples/bpf/sampleip_user.c | |||
@@ -180,6 +180,7 @@ int main(int argc, char **argv) | |||
180 | return 1; | 180 | return 1; |
181 | } | 181 | } |
182 | signal(SIGINT, int_exit); | 182 | signal(SIGINT, int_exit); |
183 | signal(SIGTERM, int_exit); | ||
183 | 184 | ||
184 | /* do sampling */ | 185 | /* do sampling */ |
185 | printf("Sampling at %d Hertz for %d seconds. Ctrl-C also ends.\n", | 186 | printf("Sampling at %d Hertz for %d seconds. Ctrl-C also ends.\n", |
diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c index 0c5561d193a4..fa4336423da5 100644 --- a/samples/bpf/trace_event_user.c +++ b/samples/bpf/trace_event_user.c | |||
@@ -192,6 +192,7 @@ int main(int argc, char **argv) | |||
192 | setrlimit(RLIMIT_MEMLOCK, &r); | 192 | setrlimit(RLIMIT_MEMLOCK, &r); |
193 | 193 | ||
194 | signal(SIGINT, int_exit); | 194 | signal(SIGINT, int_exit); |
195 | signal(SIGTERM, int_exit); | ||
195 | 196 | ||
196 | if (load_kallsyms()) { | 197 | if (load_kallsyms()) { |
197 | printf("failed to process /proc/kallsyms\n"); | 198 | printf("failed to process /proc/kallsyms\n"); |
diff --git a/samples/bpf/tracex2_user.c b/samples/bpf/tracex2_user.c index 7fee0f1ba9a3..7321a3f253c9 100644 --- a/samples/bpf/tracex2_user.c +++ b/samples/bpf/tracex2_user.c | |||
@@ -127,6 +127,7 @@ int main(int ac, char **argv) | |||
127 | } | 127 | } |
128 | 128 | ||
129 | signal(SIGINT, int_exit); | 129 | signal(SIGINT, int_exit); |
130 | signal(SIGTERM, int_exit); | ||
130 | 131 | ||
131 | /* start 'ping' in the background to have some kfree_skb events */ | 132 | /* start 'ping' in the background to have some kfree_skb events */ |
132 | f = popen("ping -c5 localhost", "r"); | 133 | f = popen("ping -c5 localhost", "r"); |
diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c index 17be9ea3ecb2..2431c0321b71 100644 --- a/samples/bpf/xdp1_user.c +++ b/samples/bpf/xdp1_user.c | |||
@@ -106,6 +106,7 @@ int main(int argc, char **argv) | |||
106 | } | 106 | } |
107 | 107 | ||
108 | signal(SIGINT, int_exit); | 108 | signal(SIGINT, int_exit); |
109 | signal(SIGTERM, int_exit); | ||
109 | 110 | ||
110 | if (set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) { | 111 | if (set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) { |
111 | printf("link set xdp fd failed\n"); | 112 | printf("link set xdp fd failed\n"); |
diff --git a/samples/bpf/xdp_tx_iptunnel_user.c b/samples/bpf/xdp_tx_iptunnel_user.c index 631cdcc41c97..715cd12eaca5 100644 --- a/samples/bpf/xdp_tx_iptunnel_user.c +++ b/samples/bpf/xdp_tx_iptunnel_user.c | |||
@@ -244,6 +244,7 @@ int main(int argc, char **argv) | |||
244 | } | 244 | } |
245 | 245 | ||
246 | signal(SIGINT, int_exit); | 246 | signal(SIGINT, int_exit); |
247 | signal(SIGTERM, int_exit); | ||
247 | 248 | ||
248 | while (min_port <= max_port) { | 249 | while (min_port <= max_port) { |
249 | vip.dport = htons(min_port++); | 250 | vip.dport = htons(min_port++); |