From 20f3331d0e61705138177f580bdebd3f05aeb9c4 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 25 Feb 2010 19:28:36 +0000 Subject: [PATCH] convert strerror() into strerror_r() git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2665 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/coroipcs.c | 17 +++++++++++++---- exec/coroparse.c | 4 +++- exec/logsys.c | 4 +++- exec/main.c | 16 +++++++++++++--- exec/totemconfig.c | 7 +++++-- exec/totemsrp.c | 12 +++++++++--- exec/totemudp.c | 25 +++++++++++++++++++------ lcr/uis.c | 4 +++- 8 files changed, 68 insertions(+), 21 deletions(-) diff --git a/exec/coroipcs.c b/exec/coroipcs.c index d380dada..546b8003 100644 --- a/exec/coroipcs.c +++ b/exec/coroipcs.c @@ -985,6 +985,7 @@ static void _corosync_ipc_init(void) int server_fd; struct sockaddr_un un_addr; int res; + /* * Create socket for IPC clients, name socket, listen for connections */ @@ -1000,7 +1001,9 @@ static void _corosync_ipc_init(void) res = fcntl (server_fd, F_SETFL, O_NONBLOCK); if (res == -1) { - log_printf (LOGSYS_LEVEL_CRIT, "Could not set non-blocking operation on server socket: %s\n", strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + log_printf (LOGSYS_LEVEL_CRIT, "Could not set non-blocking operation on server socket: %s\n", error_str); api->fatal_error ("Could not set non-blocking operation on server socket"); } @@ -1027,7 +1030,9 @@ static void _corosync_ipc_init(void) res = bind (server_fd, (struct sockaddr *)&un_addr, COROSYNC_SUN_LEN(&un_addr)); if (res) { - log_printf (LOGSYS_LEVEL_CRIT, "Could not bind AF_UNIX (%s): %s.\n", un_addr.sun_path, strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + log_printf (LOGSYS_LEVEL_CRIT, "Could not bind AF_UNIX (%s): %s.\n", un_addr.sun_path, error_str); api->fatal_error ("Could not bind to AF_UNIX socket\n"); } @@ -1521,16 +1526,20 @@ retry_accept: } if (new_fd == -1) { + char error_str[100]; + strerror_r (errno, error_str, 100); log_printf (LOGSYS_LEVEL_ERROR, - "Could not accept Library connection: %s\n", strerror (errno)); + "Could not accept Library connection: %s\n", error_str); return (0); /* This is an error, but -1 would indicate disconnect from poll loop */ } res = fcntl (new_fd, F_SETFL, O_NONBLOCK); if (res == -1) { + char error_str[100]; + strerror_r (errno, error_str, 100); log_printf (LOGSYS_LEVEL_ERROR, "Could not set non-blocking operation on library connection: %s\n", - strerror (errno)); + error_str); close (new_fd); return (0); /* This is an error, but -1 would indicate disconnect from poll loop */ } diff --git a/exec/coroparse.c b/exec/coroparse.c index ab2ecb69..a1e38437 100644 --- a/exec/coroparse.c +++ b/exec/coroparse.c @@ -379,9 +379,11 @@ static int read_config_file_into_objdb( fp = fopen (filename, "r"); if (fp == NULL) { + char error_str[100]; + strerror_r (errno, error_str, 100); snprintf (error_reason, sizeof(error_string_response), "Can't read file %s reason = (%s)\n", - filename, strerror (errno)); + filename, error_str); *error_string = error_reason; return -1; } diff --git a/exec/logsys.c b/exec/logsys.c index d43f9839..39c7c0a6 100644 --- a/exec/logsys.c +++ b/exec/logsys.c @@ -943,12 +943,14 @@ static int logsys_config_file_set_unlocked ( logsys_loggers[subsysid].logfile_fp = fopen (file, "a+"); if (logsys_loggers[subsysid].logfile_fp == NULL) { + char error_str[100]; + strerror_r (errno, error_str, 100); free(logsys_loggers[subsysid].logfile); logsys_loggers[subsysid].logfile = NULL; snprintf (error_string_response, sizeof(error_string_response), "Can't open logfile '%s' for reason (%s).\n", - file, strerror (errno)); + file, error_str); *error_string = error_string_response; return (-1); } diff --git a/exec/main.c b/exec/main.c index eb135e62..63a6d5f3 100644 --- a/exec/main.c +++ b/exec/main.c @@ -459,7 +459,11 @@ static void corosync_mlockall (void) #else res = mlockall (MCL_CURRENT | MCL_FUTURE); if (res == -1) { - log_printf (LOGSYS_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + log_printf (LOGSYS_LEVEL_WARNING, + "Could not lock memory of service to avoid page faults: %s\n", + error_str); }; #endif } @@ -1132,9 +1136,11 @@ static void corosync_setscheduler (void) global_sched_param.sched_priority = sched_priority; res = sched_setscheduler (0, SCHED_RR, &global_sched_param); if (res == -1) { + char error_str[100]; + strerror_r (errno, error_str, 100); global_sched_param.sched_priority = 0; log_printf (LOGSYS_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n", - global_sched_param.sched_priority, strerror (errno)); + global_sched_param.sched_priority, error_str); logsys_thread_priority_set (SCHED_OTHER, NULL, 1); } else { @@ -1155,7 +1161,11 @@ static void corosync_setscheduler (void) } } } else { - log_printf (LOGSYS_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + log_printf (LOGSYS_LEVEL_WARNING, + "Could not get maximum scheduler priority: %s\n", + error_str); sched_priority = 0; } #else diff --git a/exec/totemconfig.c b/exec/totemconfig.c index aa54ad3f..e6ba941e 100644 --- a/exec/totemconfig.c +++ b/exec/totemconfig.c @@ -690,12 +690,14 @@ static int read_keyfile ( int res; ssize_t expected_key_len = sizeof (totem_config->private_key); int saved_errno; + char error_str[100]; fd = open (key_location, O_RDONLY); if (fd == -1) { + strerror_r (errno, error_str, 100); snprintf (error_string_response, sizeof(error_string_response), "Could not open %s: %s\n", - key_location, strerror (errno)); + key_location, error_str); goto parse_error; } @@ -704,9 +706,10 @@ static int read_keyfile ( close (fd); if (res == -1) { + strerror_r (errno, error_str, 100); snprintf (error_string_response, sizeof(error_string_response), "Could not read %s: %s\n", - key_location, strerror (saved_errno)); + key_location, error_str); goto parse_error; } diff --git a/exec/totemsrp.c b/exec/totemsrp.c index 24c018ec..e21a0c6b 100644 --- a/exec/totemsrp.c +++ b/exec/totemsrp.c @@ -3071,15 +3071,19 @@ static void memb_ring_id_create_or_load ( umask(0); fd = open (filename, O_CREAT|O_RDWR, 0700); if (fd == -1) { + char error_str[100]; + strerror_r(errno, error_str, 100); log_printf (instance->totemsrp_log_level_warning, - "Couldn't create %s %s\n", filename, strerror (errno)); + "Couldn't create %s %s\n", filename, error_str); } res = write (fd, &memb_ring_id->seq, sizeof (unsigned long long)); assert (res == sizeof (unsigned long long)); close (fd); } else { + char error_str[100]; + strerror_r(errno, error_str, 100); log_printf (instance->totemsrp_log_level_warning, - "Couldn't open %s %s\n", filename, strerror (errno)); + "Couldn't open %s %s\n", filename, error_str); } totemip_copy(&memb_ring_id->rep, &instance->my_id.addr[0]); @@ -3105,9 +3109,11 @@ static void memb_ring_id_set_and_store ( fd = open (filename, O_CREAT|O_RDWR, 0777); } if (fd == -1) { + char error_str[100]; + strerror_r(errno, error_str, 100); log_printf (instance->totemsrp_log_level_warning, "Couldn't store new ring id %llx to stable storage (%s)\n", - instance->my_ring_id.seq, strerror (errno)); + instance->my_ring_id.seq, error_str); assert (0); return; } diff --git a/exec/totemudp.c b/exec/totemudp.c index 6d671502..33c543c3 100644 --- a/exec/totemudp.c +++ b/exec/totemudp.c @@ -1385,10 +1385,14 @@ static void timer_function_netif_check_timeout ( static void totemudp_traffic_control_set(struct totemudp_instance *instance, int sock) { #ifdef SO_PRIORITY - int prio = 6; /* TC_PRIO_INTERACTIVE */ + int prio = 6; /* TC_PRIO_INTERACTIVE */ + char error_str[100]; - if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) - log_printf (instance->totemudp_log_level_warning, "Could not set traffic priority. (%s)\n", strerror (errno)); + if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) { + strerror_r (errno, error_str, 100); + log_printf (instance->totemudp_log_level_warning, + "Could not set traffic priority. (%s)\n", error_str); + } #endif } @@ -1426,7 +1430,10 @@ static int totemudp_build_sockets_ip ( totemip_nosigpipe (sockets->mcast_recv); res = fcntl (sockets->mcast_recv, F_SETFL, O_NONBLOCK); if (res == -1) { - log_printf (instance->totemudp_log_level_warning, "Could not set non-blocking operation on multicast socket: %s\n", strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + log_printf (instance->totemudp_log_level_warning, + "Could not set non-blocking operation on multicast socket: %s\n", error_str); return (-1); } @@ -1462,7 +1469,10 @@ static int totemudp_build_sockets_ip ( totemip_nosigpipe (sockets->mcast_send); res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK); if (res == -1) { - log_printf (instance->totemudp_log_level_warning, "Could not set non-blocking operation on multicast socket: %s\n", strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + log_printf (instance->totemudp_log_level_warning, + "Could not set non-blocking operation on multicast socket: %s\n", error_str); return (-1); } @@ -1495,7 +1505,10 @@ static int totemudp_build_sockets_ip ( totemip_nosigpipe (sockets->token); res = fcntl (sockets->token, F_SETFL, O_NONBLOCK); if (res == -1) { - log_printf (instance->totemudp_log_level_warning, "Could not set non-blocking operation on token socket: %s\n", strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + log_printf (instance->totemudp_log_level_warning, + "Could not set non-blocking operation on token socket: %s\n", error_str); return (-1); } diff --git a/lcr/uis.c b/lcr/uis.c index 6431c7fb..004c4648 100755 --- a/lcr/uis.c +++ b/lcr/uis.c @@ -96,7 +96,9 @@ static void uis_lcr_bind (int *server_fd) res = bind (fd, (struct sockaddr *)&un_addr, AIS_SUN_LEN(&un_addr)); if (res) { - printf ("Could not bind AF_UNIX: %s\n", strerror (errno)); + char error_str[100]; + strerror_r (errno, error_str, 100); + printf ("Could not bind AF_UNIX: %s\n", error_str); } listen (fd, SERVER_BACKLOG); *server_fd = fd;