From: Mark Stapp Date: Thu, 24 Apr 2025 15:39:33 +0000 (-0400) Subject: *: expose and clean up 'noreturn' functions X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=098d692b6f422dccfd7cf81361f575d504913678;p=mirror%2Ffrr.git *: expose and clean up 'noreturn' functions Enable the -Wmissing-noreturn warning, and resolve warnings for gcc and clang. Add a FRR_NORETURN macro and use that for the new changes. Signed-off-by: Mark Stapp --- diff --git a/babeld/babel_main.c b/babeld/babel_main.c index 77658eb57d..088ce8b979 100644 --- a/babeld/babel_main.c +++ b/babeld/babel_main.c @@ -34,9 +34,9 @@ Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek #include "babel_zebra.h" #include "babel_errors.h" -static void babel_fail(void); +static FRR_NORETURN void babel_fail(void); static void babel_init_random(void); -static void babel_exit_properly(void); +static FRR_NORETURN void babel_exit_properly(void); static void babel_save_state_file(void); @@ -85,8 +85,7 @@ struct zebra_privs_t babeld_privs = .cap_num_i = 0 }; -static void -babel_sigexit(void) +static FRR_NORETURN void babel_sigexit(void) { zlog_notice("Terminating on signal"); @@ -208,8 +207,7 @@ main(int argc, char **argv) return 0; } -static void -babel_fail(void) +static FRR_NORETURN void babel_fail(void) { exit(1); } @@ -297,8 +295,7 @@ fini: return ; } -static void -babel_exit_properly(void) +static FRR_NORETURN void babel_exit_properly(void) { debugf(BABEL_DEBUG_COMMON, "Exiting..."); usleep(roughly(10000)); diff --git a/bfdd/bfdd.c b/bfdd/bfdd.c index c2d8e926bf..8edcac18ff 100644 --- a/bfdd/bfdd.c +++ b/bfdd/bfdd.c @@ -57,7 +57,7 @@ static void sigusr1_handler(void) zlog_rotate(); } -static void sigterm_handler(void) +static FRR_NORETURN void sigterm_handler(void) { bglobal.bg_shutdown = true; diff --git a/configure.ac b/configure.ac index 00a5620529..4484c079e0 100644 --- a/configure.ac +++ b/configure.ac @@ -468,9 +468,10 @@ AC_C_FLAG([-Wwrite-strings]) AC_C_FLAG([-Wundef]) AC_C_FLAG([-Wimplicit-fallthrough]) AC_C_FLAG([-Wshadow]) +AC_C_FLAG([-Wmissing-noreturn]) +AC_C_FLAG([-Wno-error=missing-noreturn]) if test "$enable_gcc_ultra_verbose" = "yes" ; then AC_C_FLAG([-Wcast-qual]) - AC_C_FLAG([-Wmissing-noreturn]) AC_C_FLAG([-Wmissing-format-attribute]) AC_C_FLAG([-Wunreachable-code]) AC_C_FLAG([-Wpacked]) diff --git a/eigrpd/eigrp_main.c b/eigrpd/eigrp_main.c index c9ce018966..6f102f5f07 100644 --- a/eigrpd/eigrp_main.c +++ b/eigrpd/eigrp_main.c @@ -92,7 +92,7 @@ static void sighup(void) } /* SIGINT / SIGTERM handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal"); diff --git a/ldpd/lde.c b/ldpd/lde.c index b0f9e5191f..562133ce91 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -176,8 +176,7 @@ lde_init(struct ldpd_init *init) zclient_sync_init(); } -static void -lde_shutdown(void) +static FRR_NORETURN void lde_shutdown(void) { /* close pipes */ if (iev_ldpe) { diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index e4e1dc6fec..94f9ada6da 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -443,8 +443,7 @@ main(int argc, char *argv[]) return (0); } -static void -ldpd_shutdown(void) +static FRR_NORETURN void ldpd_shutdown(void) { pid_t pid; int status; diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 50875e644d..987a4e0415 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -25,7 +25,7 @@ #include "libfrr.h" #include "zlog_live.h" -static void ldpe_shutdown(void); +static FRR_NORETURN void ldpe_shutdown(void); static void ldpe_dispatch_main(struct event *thread); static void ldpe_dispatch_lde(struct event *thread); #ifdef __OpenBSD__ @@ -66,8 +66,7 @@ struct zebra_privs_t ldpe_privs = }; /* SIGINT / SIGTERM handler. */ -static void -sigint(void) +static FRR_NORETURN void sigint(void) { ldpe_shutdown(); } @@ -182,8 +181,7 @@ ldpe_init(struct ldpd_init *init) accept_init(); } -static void -ldpe_shutdown(void) +static FRR_NORETURN void ldpe_shutdown(void) { struct if_addr *if_addr; struct adj *adj; diff --git a/lib/command_lex.l b/lib/command_lex.l index dc89191c13..42b1f440a7 100644 --- a/lib/command_lex.l +++ b/lib/command_lex.l @@ -18,6 +18,7 @@ /* ignore harmless bugs in old versions of flex */ #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wmissing-prototypes" +#pragma GCC diagnostic ignored "-Wmissing-noreturn" #include "lib/command_parse.h" diff --git a/lib/compiler.h b/lib/compiler.h index 9d39026c66..d52db1313f 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -461,6 +461,9 @@ _Static_assert(sizeof(_uint64_t) == 8 && sizeof(_int64_t) == 8, #define _DATA_SECTION(name) __attribute__((section(".data." name))) #endif +/* Wrapper for the 'noreturn' metadata */ +#define FRR_NORETURN __attribute__((noreturn)) + #ifdef __cplusplus } #endif diff --git a/lib/defun_lex.l b/lib/defun_lex.l index 9528e44852..0cac429576 100644 --- a/lib/defun_lex.l +++ b/lib/defun_lex.l @@ -29,6 +29,7 @@ /* ignore harmless bugs in old versions of flex */ #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wunused-value" +#pragma GCC diagnostic ignored "-Wmissing-noreturn" #include "config.h" #include diff --git a/lib/libfrr.c b/lib/libfrr.c index d40624a102..712408aca0 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -868,7 +868,7 @@ static void rcv_signal(int signum) /* poll() is interrupted by the signal; handled below */ } -static void frr_daemon_wait(int fd) +static FRR_NORETURN void frr_daemon_wait(int fd) { struct pollfd pfd[1]; int ret; diff --git a/lib/memory.h b/lib/memory.h index 8658018832..54de20eb7d 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -183,8 +183,7 @@ typedef int qmem_walk_fn(void *arg, struct memgroup *mg, struct memtype *mt); extern int qmem_walk(qmem_walk_fn *func, void *arg); extern int log_memstats(const char *daemon_name, bool enabled); -extern __attribute__((__noreturn__)) void memory_oom(size_t size, - const char *name); +extern FRR_NORETURN void memory_oom(size_t size, const char *name); #ifdef __cplusplus } diff --git a/lib/sigevent.c b/lib/sigevent.c index 7c465bfcec..0ee986e9d5 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -206,8 +206,8 @@ static void *program_counter(void *context) return NULL; } -static void __attribute__((noreturn)) -exit_handler(int signo, siginfo_t *siginfo, void *context) +static void FRR_NORETURN exit_handler(int signo, siginfo_t *siginfo, + void *context) { void *pc = program_counter(context); @@ -215,8 +215,8 @@ exit_handler(int signo, siginfo_t *siginfo, void *context) _exit(128 + signo); } -static void __attribute__((noreturn)) -core_handler(int signo, siginfo_t *siginfo, void *context) +static void FRR_NORETURN core_handler(int signo, siginfo_t *siginfo, + void *context) { void *pc = program_counter(context); diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c index 7c632ef230..f353cc6792 100644 --- a/mgmtd/mgmt_fe_adapter.c +++ b/mgmtd/mgmt_fe_adapter.c @@ -2030,7 +2030,7 @@ void mgmt_fe_adapter_init(struct event_loop *tm) } } -static void mgmt_fe_abort_if_session(void *data) +static FRR_NORETURN void mgmt_fe_abort_if_session(void *data) { struct mgmt_fe_session_ctx *session = data; diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c index adb8be36d3..3c33db3167 100644 --- a/nhrpd/nhrp_main.c +++ b/nhrpd/nhrp_main.c @@ -78,7 +78,7 @@ static void nhrp_sigusr1(void) zlog_rotate(); } -static void nhrp_request_stop(void) +static FRR_NORETURN void nhrp_request_stop(void) { debugf(NHRP_DEBUG_COMMON, "Exiting..."); frr_early_fini(); diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index e94f2a1c47..ae61e8b35f 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -125,14 +125,14 @@ static void sighup(void) } /* SIGINT handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal SIGINT"); ospf6_exit(0); } /* SIGTERM handler. */ -static void sigterm(void) +static FRR_NORETURN void sigterm(void) { zlog_notice("Terminating on signal SIGTERM"); ospf6_exit(0); diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 5c11027506..1c48d37785 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -99,7 +99,7 @@ static void sighup(void) } /* SIGINT / SIGTERM handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal"); bfd_protocol_integration_set_shutdown(true); diff --git a/pathd/path_main.c b/pathd/path_main.c index 23cbb9cced..f4220a7cf8 100644 --- a/pathd/path_main.c +++ b/pathd/path_main.c @@ -55,7 +55,7 @@ static void sighup(void) } /* SIGINT / SIGTERM handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal"); zlog_notice("Unregister from opaque,etc "); diff --git a/pbrd/pbr_main.c b/pbrd/pbr_main.c index 6695b537a8..7724a795d7 100644 --- a/pbrd/pbr_main.c +++ b/pbrd/pbr_main.c @@ -65,7 +65,7 @@ static void sighup(void) } /* SIGINT / SIGTERM handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal"); diff --git a/pimd/pim6_main.c b/pimd/pim6_main.c index 07b70ae2b3..69ce912205 100644 --- a/pimd/pim6_main.c +++ b/pimd/pim6_main.c @@ -56,14 +56,14 @@ static void pim6_sighup(void) zlog_info("SIGHUP received, ignoring"); } -static void pim6_sigint(void) +static FRR_NORETURN void pim6_sigint(void) { zlog_notice("Terminating on signal SIGINT"); pim6_terminate(); exit(1); } -static void pim6_sigterm(void) +static FRR_NORETURN void pim6_sigterm(void) { zlog_notice("Terminating on signal SIGTERM"); pim6_terminate(); diff --git a/pimd/pim_signals.c b/pimd/pim_signals.c index 146a4e9e98..d78dcc483b 100644 --- a/pimd/pim_signals.c +++ b/pimd/pim_signals.c @@ -25,14 +25,14 @@ static void pim_sighup(void) zlog_info("SIGHUP received, ignoring"); } -static void pim_sigint(void) +static FRR_NORETURN void pim_sigint(void) { zlog_notice("Terminating on signal SIGINT"); pim_terminate(); exit(1); } -static void pim_sigterm(void) +static FRR_NORETURN void pim_sigterm(void) { zlog_notice("Terminating on signal SIGTERM"); pim_terminate(); diff --git a/ripd/rip_main.c b/ripd/rip_main.c index 431e967131..9ec909c067 100644 --- a/ripd/rip_main.c +++ b/ripd/rip_main.c @@ -69,7 +69,7 @@ static void sighup(void) } /* SIGINT handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { struct vrf *vrf; diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c index f0ab67dcb6..c8752fd086 100644 --- a/ripngd/ripng_main.c +++ b/ripngd/ripng_main.c @@ -67,7 +67,7 @@ static void sighup(void) } /* SIGINT handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { struct vrf *vrf; diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c index 2e72a4b990..2374070102 100644 --- a/sharpd/sharp_main.c +++ b/sharpd/sharp_main.c @@ -90,7 +90,7 @@ static void sighup(void) } /* SIGINT / SIGTERM handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal"); diff --git a/staticd/static_main.c b/staticd/static_main.c index 3b59ca6a75..99f8b676d9 100644 --- a/staticd/static_main.c +++ b/staticd/static_main.c @@ -65,7 +65,7 @@ static void sighup(void) } /* SIGINT / SIGTERM handler. */ -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal"); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 16e166beac..a17ad565bd 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -156,7 +156,7 @@ static void vtysh_signal_init(void) } /* Help information display. */ -static void usage(int status) +static FRR_NORETURN void usage(int status) { if (status != 0) fprintf(stderr, "Try `%s --help' for more information.\n", diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index 611a7872d0..cde38aed8c 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -1090,7 +1090,7 @@ void watchfrr_status(struct vty *vty) } } -static void sigint(void) +static FRR_NORETURN void sigint(void) { zlog_notice("Terminating on signal"); systemd_send_stopping(); @@ -1268,7 +1268,7 @@ static void netns_setup(const char *nsname) #else /* !GNU_LINUX */ -static void netns_setup(const char *nsname) +static FRR_NORETURN void netns_setup(const char *nsname) { fprintf(stderr, "network namespaces are only available on Linux\n"); exit(1);