From edb330686d933bd35739e740e2cb27d6b65c0a0b Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 27 Mar 2025 12:56:28 -0400 Subject: [PATCH] tools,pceplib,ospfclient: clean up variable-shadow warnings Clean up -Wshadow warnings in these components Signed-off-by: Mark Stapp --- ospfclient/ospfclient.c | 20 ++++++++-------- pceplib/pcep_pcc.c | 48 ++++++++++++++++++------------------- pceplib/pcep_utils_memory.c | 8 +++---- tools/start-stop-daemon.c | 44 +++++++++++++++++----------------- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/ospfclient/ospfclient.c b/ospfclient/ospfclient.c index 24ff08561d..315da6bb0a 100644 --- a/ospfclient/ospfclient.c +++ b/ospfclient/ospfclient.c @@ -54,7 +54,7 @@ struct zebra_privs_t ospfd_privs = {.user = NULL, struct event_loop *master; /* Global variables */ -struct ospf_apiclient *oclient; +struct ospf_apiclient *g_oclient; char **args; /* Our opaque LSAs have the following format. */ @@ -209,13 +209,13 @@ static void ready_callback(uint8_t lsa_type, uint8_t opaque_type, lsa_type, opaque_type, &addr); /* Schedule opaque LSA originate in 5 secs */ - event_add_timer(master, lsa_inject, oclient, 5, NULL); + event_add_timer(master, lsa_inject, g_oclient, 5, NULL); /* Schedule opaque LSA update with new value */ - event_add_timer(master, lsa_inject, oclient, 10, NULL); + event_add_timer(master, lsa_inject, g_oclient, 10, NULL); /* Schedule delete */ - event_add_timer(master, lsa_delete, oclient, 30, NULL); + event_add_timer(master, lsa_delete, g_oclient, 30, NULL); } static void new_if_callback(struct in_addr ifaddr, struct in_addr area_id) @@ -296,27 +296,27 @@ int main(int argc, char *argv[]) master = event_master_create(NULL); /* Open connection to OSPF daemon */ - oclient = ospf_apiclient_connect(args[1], ASYNCPORT); - if (!oclient) { + g_oclient = ospf_apiclient_connect(args[1], ASYNCPORT); + if (!g_oclient) { printf("Connecting to OSPF daemon on %s failed!\n", args[1]); exit(1); } /* Register callback functions. */ ospf_apiclient_register_callback( - oclient, ready_callback, new_if_callback, del_if_callback, + g_oclient, ready_callback, new_if_callback, del_if_callback, ism_change_callback, nsm_change_callback, lsa_update_callback, lsa_delete_callback); /* Register LSA type and opaque type. */ - ospf_apiclient_register_opaque_type(oclient, atoi(args[2]), + ospf_apiclient_register_opaque_type(g_oclient, atoi(args[2]), atoi(args[3])); /* Synchronize database with OSPF daemon. */ - ospf_apiclient_sync_lsdb(oclient); + ospf_apiclient_sync_lsdb(g_oclient); /* Schedule thread that handles asynchronous messages */ - event_add_read(master, lsa_read, oclient, oclient->fd_async, NULL); + event_add_read(master, lsa_read, g_oclient, g_oclient->fd_async, NULL); /* Now connection is established, run loop */ while (1) { diff --git a/pceplib/pcep_pcc.c b/pceplib/pcep_pcc.c index 92a968ef78..d53469e7cd 100644 --- a/pceplib/pcep_pcc.c +++ b/pceplib/pcep_pcc.c @@ -47,11 +47,11 @@ struct cmd_line_args { }; bool pcc_active_ = true; -pcep_session *session = NULL; -struct cmd_line_args *cmd_line_args = NULL; +pcep_session *g_session = NULL; +struct cmd_line_args *g_cmd_line_args = NULL; /* pcep_event callback variables */ bool pcep_event_condition = false; -struct pcep_event *event = NULL; +struct pcep_event *g_event = NULL; pthread_mutex_t pcep_event_mutex; pthread_cond_t pcep_event_cond_var; @@ -180,7 +180,7 @@ void handle_signal_action(int sig_number) if (sig_number == SIGINT) { pcep_log(LOG_INFO, "%s: SIGINT was caught!", __func__); pcc_active_ = false; - if (cmd_line_args->eventpoll == false) { + if (g_cmd_line_args->eventpoll == false) { pthread_mutex_lock(&pcep_event_mutex); pcep_event_condition = true; pthread_cond_signal(&pcep_event_cond_var); @@ -189,12 +189,12 @@ void handle_signal_action(int sig_number) } else if (sig_number == SIGUSR1) { pcep_log(LOG_INFO, "%s: SIGUSR1 was caught, dumping counters", __func__); - dump_pcep_session_counters(session); + dump_pcep_session_counters(g_session); pceplib_memory_dump(); } else if (sig_number == SIGUSR2) { pcep_log(LOG_INFO, "%s: SIGUSR2 was caught, reseting counters", __func__); - reset_pcep_session_counters(session); + reset_pcep_session_counters(g_session); } } @@ -377,7 +377,7 @@ void pcep_event_callback(void *cb_data, pcep_event *e) pcep_log(LOG_NOTICE, "%s: [%ld-%ld] pcep_event_callback", __func__, time(NULL), pthread_self()); pthread_mutex_lock(&pcep_event_mutex); - event = e; + g_event = e; pcep_event_condition = true; pthread_cond_signal(&pcep_event_cond_var); pthread_mutex_unlock(&pcep_event_mutex); @@ -388,14 +388,14 @@ int main(int argc, char **argv) pcep_log(LOG_NOTICE, "%s: [%ld-%ld] starting pcc_pcep example client", __func__, time(NULL), pthread_self()); - cmd_line_args = get_cmdline_args(argc, argv); - if (cmd_line_args == NULL) { + g_cmd_line_args = get_cmdline_args(argc, argv); + if (g_cmd_line_args == NULL) { return -1; } setup_signals(); - if (cmd_line_args->eventpoll == false) { + if (g_cmd_line_args->eventpoll == false) { struct pceplib_infra_config infra_config; memset(&infra_config, 0, sizeof(infra_config)); infra_config.pcep_event_func = pcep_event_callback; @@ -415,31 +415,31 @@ int main(int argc, char **argv) pcep_configuration *config = create_default_pcep_configuration(); config->pcep_msg_versioning->draft_ietf_pce_segment_routing_07 = true; - config->src_pcep_port = cmd_line_args->src_tcp_port; + config->src_pcep_port = g_cmd_line_args->src_tcp_port; config->is_tcp_auth_md5 = true; - strlcpy(config->tcp_authentication_str, cmd_line_args->tcp_md5_str, + strlcpy(config->tcp_authentication_str, g_cmd_line_args->tcp_md5_str, sizeof(config->tcp_authentication_str)); - int af = (cmd_line_args->is_ipv6 ? AF_INET6 : AF_INET); + int af = (g_cmd_line_args->is_ipv6 ? AF_INET6 : AF_INET); struct hostent *host_info = - gethostbyname2(cmd_line_args->dest_ip_str, af); + gethostbyname2(g_cmd_line_args->dest_ip_str, af); if (host_info == NULL) { pcep_log(LOG_ERR, "%s: Error getting IP address.", __func__); return -1; } - if (cmd_line_args->is_ipv6) { + if (g_cmd_line_args->is_ipv6) { struct in6_addr host_address; memcpy(&host_address, host_info->h_addr, host_info->h_length); - session = connect_pce_ipv6(config, &host_address); + g_session = connect_pce_ipv6(config, &host_address); } else { struct in_addr host_address; memcpy(&host_address, host_info->h_addr, host_info->h_length); - session = connect_pce(config, &host_address); + g_session = connect_pce(config, &host_address); } - if (session == NULL) { + if (g_session == NULL) { pcep_log(LOG_WARNING, "%s: Error in connect_pce.", __func__); destroy_pcep_configuration(config); return -1; @@ -447,12 +447,12 @@ int main(int argc, char **argv) sleep(2); - send_pce_report_message(session); + send_pce_report_message(g_session); /*send_pce_path_request_message(session);*/ /* Wait for pcep_event's either by polling the event queue or by * callback */ - if (cmd_line_args->eventpoll == true) { + if (g_cmd_line_args->eventpoll == true) { /* Poll the pcep_event queue*/ while (pcc_active_) { if (event_queue_is_empty() == false) { @@ -479,8 +479,8 @@ int main(int argc, char **argv) /* Check if we have been interrupted by SIGINT */ if (pcc_active_) { - print_queue_event(event); - destroy_pcep_event(event); + print_queue_event(g_event); + destroy_pcep_event(g_event); } pcep_event_condition = false; @@ -492,9 +492,9 @@ int main(int argc, char **argv) } pcep_log(LOG_NOTICE, "%s: Disconnecting from PCE", __func__); - disconnect_pce(session); + disconnect_pce(g_session); destroy_pcep_configuration(config); - free(cmd_line_args); + free(g_cmd_line_args); if (!destroy_pcc()) { pcep_log(LOG_NOTICE, "%s: Error stopping PCC.", __func__); diff --git a/pceplib/pcep_utils_memory.c b/pceplib/pcep_utils_memory.c index c3a2ab90cd..225c058711 100644 --- a/pceplib/pcep_utils_memory.c +++ b/pceplib/pcep_utils_memory.c @@ -44,15 +44,15 @@ void *PCEPLIB_INFRA = &pceplib_infra_mt; void *PCEPLIB_MESSAGES = &pceplib_messages_mt; /* Initialize memory function pointers and memory type pointers */ -bool pceplib_memory_initialize(void *pceplib_infra_mt, - void *pceplib_messages_mt, +bool pceplib_memory_initialize(void *infra_mt, + void *messages_mt, pceplib_malloc_func mf, pceplib_calloc_func cf, pceplib_realloc_func rf, pceplib_strdup_func sf, pceplib_free_func ff) { - PCEPLIB_INFRA = (pceplib_infra_mt ? pceplib_infra_mt : PCEPLIB_INFRA); + PCEPLIB_INFRA = (infra_mt ? infra_mt : PCEPLIB_INFRA); PCEPLIB_MESSAGES = - (pceplib_messages_mt ? pceplib_messages_mt : PCEPLIB_MESSAGES); + (messages_mt ? messages_mt : PCEPLIB_MESSAGES); mfunc = (mf ? mf : mfunc); cfunc = (cf ? cf : cfunc); diff --git a/tools/start-stop-daemon.c b/tools/start-stop-daemon.c index 4406a68f61..5d6cf01936 100644 --- a/tools/start-stop-daemon.c +++ b/tools/start-stop-daemon.c @@ -73,14 +73,14 @@ size_t strlcpy(char *__restrict dest, #endif static int testmode = 0; -static int quietmode = 0; +static int g_quietmode = 0; static int exitnodo = 1; static int start = 0; static int stop = 0; static int background = 0; static int mpidfile = 0; -static int signal_nr = 15; -static const char *signal_str = NULL; +static int g_signal_nr = 15; +static const char *g_signal_str = NULL; static int user_id = -1; static int runas_uid = -1; static int runas_gid = -1; @@ -93,7 +93,7 @@ static char *execname = NULL; static char *startas = NULL; static const char *pidfile = NULL; static char what_stop[1024]; -static const char *schedule_str = NULL; +static const char *g_schedule_str = NULL; static const char *progname = ""; static int nicelevel = 0; @@ -438,7 +438,7 @@ static void parse_schedule(const char *schedule_str) if (count == 0) { schedule[0].type = sched_signal; - schedule[0].value = signal_nr; + schedule[0].value = g_signal_nr; parse_schedule_item(schedule_str, &schedule[1]); if (schedule[1].type != sched_timeout) { badusage( @@ -528,10 +528,10 @@ static void parse_options(int argc, char *const *argv) pidfile = optarg; break; case 'q': /* --quiet */ - quietmode = 1; + g_quietmode = 1; break; case 's': /* --signal */ - signal_str = optarg; + g_signal_str = optarg; break; case 't': /* --test */ testmode = 1; @@ -540,7 +540,7 @@ static void parse_options(int argc, char *const *argv) userspec = optarg; break; case 'v': /* --verbose */ - quietmode = -1; + g_quietmode = -1; break; case 'x': /* --exec */ execname = optarg; @@ -567,21 +567,21 @@ static void parse_options(int argc, char *const *argv) mpidfile = 1; break; case 'R': /* --retry | */ - schedule_str = optarg; + g_schedule_str = optarg; break; default: badusage(NULL); /* message printed by getopt */ } } - if (signal_str != NULL) { - if (parse_signal(signal_str, &signal_nr) != 0) + if (g_signal_str != NULL) { + if (parse_signal(g_signal_str, &g_signal_nr) != 0) badusage( "signal value must be numeric or name of signal (KILL, INTR, ...)"); } - if (schedule_str != NULL) { - parse_schedule(schedule_str); + if (g_schedule_str != NULL) { + parse_schedule(g_schedule_str); } if (start == stop) @@ -787,8 +787,8 @@ static int run_stop_schedule(void) n_killed = 0; if (schedule == NULL) { - do_stop(signal_nr, quietmode, &n_killed, &n_notkilled, 0); - if (n_notkilled > 0 && quietmode <= 0) + do_stop(g_signal_nr, g_quietmode, &n_killed, &n_notkilled, 0); + if (n_notkilled > 0 && g_quietmode <= 0) printf("%d pids were not killed\n", n_notkilled); if (n_killed) anykilled = 1; @@ -806,7 +806,7 @@ static int run_stop_schedule(void) continue; case sched_signal: - do_stop(value, quietmode, &n_killed, &n_notkilled, + do_stop(value, g_quietmode, &n_killed, &n_notkilled, retry_nr++); if (!n_killed) goto x_finished; @@ -899,7 +899,7 @@ static int run_stop_schedule(void) position++; } - if (quietmode <= 0) + if (g_quietmode <= 0) printf("Program %s, %d process(es), refused to die.\n", what_stop, n_killed); @@ -907,7 +907,7 @@ static int run_stop_schedule(void) x_finished: if (!anykilled) { - if (quietmode <= 0) + if (g_quietmode <= 0) printf("No %s found running; none killed.\n", what_stop); return exitnodo; @@ -969,7 +969,7 @@ int main(int argc, char **argv) do_findprocs(); if (found) { - if (quietmode <= 0) + if (g_quietmode <= 0) printf("%s already running.\n", execname); exit(exitnodo); } @@ -992,7 +992,7 @@ int main(int argc, char **argv) printf(".\n"); exit(0); } - if (quietmode < 0) + if (g_quietmode < 0) printf("Starting %s...\n", startas); *--argv = startas; if (changeroot != NULL) { @@ -1013,14 +1013,14 @@ int main(int argc, char **argv) if (background) { /* ok, we need to detach this process */ int i, fd; - if (quietmode < 0) + if (g_quietmode < 0) printf("Detaching to start %s...", startas); i = fork(); if (i < 0) { fatal("Unable to fork.\n"); } if (i) { /* parent */ - if (quietmode < 0) + if (g_quietmode < 0) printf("done.\n"); exit(0); } -- 2.39.5