struct event_loop *master;
/* Global variables */
-struct ospf_apiclient *oclient;
+struct ospf_apiclient *g_oclient;
char **args;
/* Our opaque LSAs have the following format. */
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)
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) {
};
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;
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);
} 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);
}
}
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);
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;
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;
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) {
/* 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;
}
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__);
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);
#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;
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;
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(
pidfile = optarg;
break;
case 'q': /* --quiet */
- quietmode = 1;
+ g_quietmode = 1;
break;
case 's': /* --signal <signal> */
- signal_str = optarg;
+ g_signal_str = optarg;
break;
case 't': /* --test */
testmode = 1;
userspec = optarg;
break;
case 'v': /* --verbose */
- quietmode = -1;
+ g_quietmode = -1;
break;
case 'x': /* --exec <executable> */
execname = optarg;
mpidfile = 1;
break;
case 'R': /* --retry <schedule>|<timeout> */
- 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)
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;
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;
position++;
}
- if (quietmode <= 0)
+ if (g_quietmode <= 0)
printf("Program %s, %d process(es), refused to die.\n",
what_stop, n_killed);
x_finished:
if (!anykilled) {
- if (quietmode <= 0)
+ if (g_quietmode <= 0)
printf("No %s found running; none killed.\n",
what_stop);
return exitnodo;
do_findprocs();
if (found) {
- if (quietmode <= 0)
+ if (g_quietmode <= 0)
printf("%s already running.\n", execname);
exit(exitnodo);
}
printf(".\n");
exit(0);
}
- if (quietmode < 0)
+ if (g_quietmode < 0)
printf("Starting %s...\n", startas);
*--argv = startas;
if (changeroot != NULL) {
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);
}