convert strerror() into strerror_r()

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2665 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
Angus Salkeld 2010-02-25 19:28:36 +00:00
parent 2290913d28
commit 20f3331d0e
8 changed files with 68 additions and 21 deletions

View File

@ -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 */
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;