From 552bc48c368892b838b205f81c3cddb6372cc101 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 18 Jun 2020 11:02:18 +0000 Subject: [PATCH] Add ff_ipc_exit() to clean temp files in /var/ while run F-Stack tools netstat/ngctl/sysctl/top/traffic/knictl. --- tools/knictl/knictl.c | 7 +++++++ tools/netstat/main.c | 35 ++++++++++++++++++++++++++++++++++- tools/ngctl/main.c | 4 ++++ tools/sysctl/sysctl.c | 20 +++++++++++++++++--- tools/top/top.c | 6 ++++++ tools/traffic/traffic.c | 8 ++++++++ 6 files changed, 76 insertions(+), 4 deletions(-) diff --git a/tools/knictl/knictl.c b/tools/knictl/knictl.c index f47bc4a6..24569202 100644 --- a/tools/knictl/knictl.c +++ b/tools/knictl/knictl.c @@ -102,12 +102,14 @@ int main(int argc, char **argv) max_proc_id = atoi(optarg); if (max_proc_id < 0 || max_proc_id >= RTE_MAX_LCORE) { usage(); + ff_ipc_exit(); return -1; } break; case 'a': if (has_action){ usage(); + ff_ipc_exit(); return -1; } has_action = 1; @@ -115,12 +117,14 @@ int main(int argc, char **argv) knictl.kni_action = get_action(optarg); if (knictl.kni_action < FF_KNICTL_ACTION_DEFAULT || knictl.kni_action >= FF_KNICTL_ACTION_MAX){ usage(); + ff_ipc_exit(); return -1; } break; case 'n': if (has_action){ usage(); + ff_ipc_exit(); return -1; } has_action = 1; @@ -129,6 +133,7 @@ int main(int argc, char **argv) case 'h': default: usage(); + ff_ipc_exit(); return -1; } } @@ -146,4 +151,6 @@ int main(int argc, char **argv) printf(" %s to %s knictl type: %s, proc_id: %d\n", ret ? "fail": "success", pknictl[proc_id].kni_cmd == FF_KNICTL_CMD_GET ? "get" : "set", get_action_str(pknictl[proc_id].kni_action), proc_id); } } + + ff_ipc_exit(); } \ No newline at end of file diff --git a/tools/netstat/main.c b/tools/netstat/main.c index 5bcc8376..8b6130d9 100644 --- a/tools/netstat/main.c +++ b/tools/netstat/main.c @@ -254,8 +254,12 @@ main(int argc, char *argv[]) af = AF_UNSPEC; argc = xo_parse_args(argc, argv); - if (argc < 0) + if (argc < 0) { +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(EXIT_FAILURE); + } #ifndef FSTACK while ((ch = getopt(argc, argv, "46AaBbdF:f:ghI:iLlM:mN:np:Qq:RrSTsuWw:xz")) @@ -459,6 +463,9 @@ main(int argc, char *argv[]) usage(); bpf_stats(interface); xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(0); } if (mflag) { @@ -470,6 +477,9 @@ main(int argc, char *argv[]) } else mbpr(NULL, 0); xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(0); } if (Qflag) { @@ -481,6 +491,9 @@ main(int argc, char *argv[]) } else netisr_stats(); xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(0); } @@ -503,6 +516,9 @@ main(int argc, char *argv[]) intpr(NULL, af); xo_close_container("statistics"); xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(0); } if (rflag) { @@ -514,6 +530,9 @@ main(int argc, char *argv[]) routepr(fib, af); xo_close_container("statistics"); xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(0); } @@ -536,6 +555,9 @@ main(int argc, char *argv[]) } xo_close_container("statistics"); xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(0); } @@ -551,6 +573,9 @@ main(int argc, char *argv[]) xo_close_list("socket"); xo_close_container("statistics"); xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(0); } @@ -582,6 +607,11 @@ main(int argc, char *argv[]) xo_close_list("socket"); xo_close_container("statistics"); xo_finish(); + +#ifdef FSTACK + ff_ipc_exit(); +#endif + exit(0); } @@ -947,5 +977,8 @@ usage(void) #endif xo_finish(); +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(1); } diff --git a/tools/ngctl/main.c b/tools/ngctl/main.c index e4d60896..486aa57f 100644 --- a/tools/ngctl/main.c +++ b/tools/ngctl/main.c @@ -235,6 +235,9 @@ main(int ac, char *av[]) rtn = EX_OSERR; break; } +#ifdef FSTACK + ff_ipc_exit(); +#endif return (rtn); } @@ -720,6 +723,7 @@ Usage(const char *msg) "usage: ngctl [-d] [-f file] [-n name] [command ...]\n"); #else "usage: ngctl -p [-d] [-f file] [-n name] [command ...]\n"); + ff_ipc_exit(); #endif exit(EX_USAGE); } diff --git a/tools/sysctl/sysctl.c b/tools/sysctl/sysctl.c index 7d7e9f87..d91a05fb 100644 --- a/tools/sysctl/sysctl.c +++ b/tools/sysctl/sysctl.c @@ -231,6 +231,7 @@ usage(void) (void)fprintf(stderr, "%s\n%s\n", "usage: sysctl -p [-bdehiNnoqTtWx] [ -B ] [-f filename] name[=value] ...", " sysctl -p [-bdehNnoqTtWx] [ -B ] -a"); + ff_ipc_exit(); #endif exit(1); } @@ -329,8 +330,13 @@ main(int argc, char **argv) if (Nflag && nflag) usage(); - if (aflag && argc == 0) - exit(sysctl_all(0, 0)); + if (aflag && argc == 0) { + int ret = sysctl_all(0, 0); +#ifdef FSTACK + ff_ipc_exit(); +#endif + exit(ret); + } if (argc == 0 && conffile == NULL) usage(); @@ -341,6 +347,10 @@ main(int argc, char **argv) while (argc-- > 0) warncount += parse(*argv++, 0); +#ifdef FSTACK + ff_ipc_exit(); +#endif + return (warncount); } @@ -429,8 +439,12 @@ parse(const char *string, int lineno) warn("couldn't find format of oid '%s'%s", bufp, line); if (iflag) return (1); - else + else { +#ifdef FSTACK + ff_ipc_exit(); +#endif exit(1); + } } if (newvalstr == NULL || dflag) { diff --git a/tools/top/top.c b/tools/top/top.c index 7433868c..f0f58fa5 100644 --- a/tools/top/top.c +++ b/tools/top/top.c @@ -74,6 +74,7 @@ int main(int argc, char **argv) max_proc_id = atoi(optarg); if (max_proc_id < 0 || max_proc_id >= RTE_MAX_LCORE) { usage(); + ff_ipc_exit(); return -1; } break; @@ -86,6 +87,7 @@ int main(int argc, char **argv) case 'h': default: usage(); + ff_ipc_exit(); return -1; } } @@ -94,6 +96,7 @@ int main(int argc, char **argv) if (max_proc_id == -1) { if (cpu_status(&top)) { printf("fstack ipc message error !\n"); + ff_ipc_exit(); return -1; } @@ -131,6 +134,7 @@ int main(int argc, char **argv) ff_set_proc_id(j); if (cpu_status(&ptop[j])) { printf("fstack ipc message error, proc id:%d!\n", j); + ff_ipc_exit(); return -1; } @@ -168,5 +172,7 @@ int main(int argc, char **argv) sleep(delay); } + ff_ipc_exit(); + return 0; } diff --git a/tools/traffic/traffic.c b/tools/traffic/traffic.c index 38dd09bf..866ef9e3 100644 --- a/tools/traffic/traffic.c +++ b/tools/traffic/traffic.c @@ -75,6 +75,7 @@ int main(int argc, char **argv) max_proc_id = atoi(optarg); if (max_proc_id < 0 || max_proc_id >= RTE_MAX_LCORE) { usage(); + ff_ipc_exit(); return -1; } break; @@ -90,6 +91,7 @@ int main(int argc, char **argv) case 'h': default: usage(); + ff_ipc_exit(); return -1; } } @@ -98,6 +100,7 @@ int main(int argc, char **argv) if (max_proc_id == -1) { if (traffic_status(&traffic)) { printf("fstack ipc message error !\n"); + ff_ipc_exit(); return -1; } @@ -108,6 +111,7 @@ int main(int argc, char **argv) ff_set_proc_id(j); if (traffic_status(&ptraffic[j])) { printf("fstack ipc message error, proc id:%d!\n", j); + ff_ipc_exit(); return -1; } @@ -125,6 +129,7 @@ int main(int argc, char **argv) "total", traffic.rx_packets, traffic.rx_bytes, traffic.tx_packets, traffic.tx_bytes); } + ff_ipc_exit(); return 0; } @@ -132,6 +137,7 @@ int main(int argc, char **argv) if (max_proc_id == -1) { if (traffic_status(&traffic)) { printf("fstack ipc message error !\n"); + ff_ipc_exit(); return -1; } @@ -173,6 +179,7 @@ int main(int argc, char **argv) ff_set_proc_id(j); if (traffic_status(&ptraffic[j])) { printf("fstack ipc message error, proc id:%d!\n", j); + ff_ipc_exit(); return -1; } @@ -208,5 +215,6 @@ int main(int argc, char **argv) sleep(delay); } + ff_ipc_exit(); return 0; }