Commit d3e11854 authored by Pavan Balaji's avatar Pavan Balaji
Browse files

[svn-r4091] Use strerror where available for better error information.

parent 3870fc15
......@@ -139,7 +139,8 @@ HYD_Status HYD_DMX_Wait_for_event(int time)
status = HYD_SUCCESS;
goto fn_exit;
}
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "poll error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "poll error (%s)\n",
HYDU_String_error(errno));
}
break;
}
......
......@@ -100,6 +100,7 @@ HYD_Status HYDU_Chdir(const char *dir);
HYD_Status HYDU_String_alloc_and_join(char **strlist, char **strjoin);
HYD_Status HYDU_String_break(char *str, char **str1, char **str2);
HYD_Status HYDU_String_int_to_str(int x, char **str);
char *HYDU_String_error(int error);
/* Signal utilities */
......
......@@ -20,13 +20,13 @@ HYD_Status HYD_LCHI_stdout_cb(int fd, HYD_Event_t events)
/* Write output to fd 1 */
status = HYDU_Sock_stdout_cb(fd, events, 1, &closed);
HYDU_ERR_SETANDJUMP2(status, status, "stdout callback error on fd %d (errno: %d)\n",
fd, errno);
HYDU_ERR_SETANDJUMP2(status, status, "stdout callback error on fd %d: %s\n",
fd, HYDU_String_error(errno));
if (closed) {
status = HYD_CSI_Close_fd(fd);
HYDU_ERR_SETANDJUMP2(status, status, "socket close error on fd %d (errno: %d)\n",
fd, errno);
HYDU_ERR_SETANDJUMP2(status, status, "socket close error on fd %d: %s\n",
fd, HYDU_String_error(errno));
goto fn_exit;
}
......@@ -48,13 +48,13 @@ HYD_Status HYD_LCHI_stderr_cb(int fd, HYD_Event_t events)
/* Write output to fd 2 */
status = HYDU_Sock_stdout_cb(fd, events, 2, &closed);
HYDU_ERR_SETANDJUMP2(status, status, "stdout callback error on %d (errno: %d)\n",
fd, errno)
HYDU_ERR_SETANDJUMP2(status, status, "stdout callback error on %d (%s)\n",
fd, HYDU_String_error(errno))
if (closed) {
status = HYD_CSI_Close_fd(fd);
HYDU_ERR_SETANDJUMP2(status, status, "socket close error on fd %d (errno: %d)\n",
fd, errno);
HYDU_ERR_SETANDJUMP2(status, status, "socket close error on fd %d (%s)\n",
fd, HYDU_String_error(errno));
goto fn_exit;
}
......
......@@ -34,8 +34,8 @@ HYD_Status HYD_Proxy_listen_cb(int fd, HYD_Event_t events)
else { /* We got a command from mpiexec */
count = read(fd, &cmd, HYD_TMPBUF_SIZE);
if (count < 0) {
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR, "read error on %d (errno: %d)\n",
fd, errno);
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR, "read error on %d (%s)\n",
fd, HYDU_String_error(errno));
}
else if (count == 0) {
/* The connection has closed */
......
......@@ -14,13 +14,16 @@ HYD_Status HYDU_Create_process(char **client_arg, int *in, int *out, int *err, i
HYDU_FUNC_ENTER();
if (in && (pipe(inpipe) < 0))
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "pipe error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "pipe error (%s)\n",
HYDU_String_error(errno));
if (out && (pipe(outpipe) < 0))
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "pipe error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "pipe error (%s)\n",
HYDU_String_error(errno));
if (err && (pipe(errpipe) < 0))
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "pipe error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "pipe error (%s)\n",
HYDU_String_error(errno));
/* Fork off the process */
tpid = fork();
......@@ -28,27 +31,24 @@ HYD_Status HYDU_Create_process(char **client_arg, int *in, int *out, int *err, i
close(outpipe[0]);
close(1);
if (dup2(outpipe[1], 1) < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "dup2 error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "dup2 error (%s)\n",
HYDU_String_error(errno));
close(errpipe[0]);
close(2);
if (dup2(errpipe[1], 2) < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "dup2 error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "dup2 error (%s)\n",
HYDU_String_error(errno));
close(inpipe[1]);
close(0);
if (in && (dup2(inpipe[0], 0) < 0))
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "dup2 error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "dup2 error (%s)\n",
HYDU_String_error(errno));
if (execvp(client_arg[0], client_arg) < 0) {
if (errno == ENOENT) {
HYDU_ERR_SETANDJUMP1(status, HYD_INTERNAL_ERROR,
"execvp error: file %s not found\n", client_arg[0]);
}
else {
HYDU_ERR_SETANDJUMP1(status, HYD_INTERNAL_ERROR,
"execvp error (errno: %d)\n", errno);
}
HYDU_ERR_SETANDJUMP1(status, HYD_INTERNAL_ERROR, "execvp error (%s)\n",
HYDU_String_error(errno));
}
}
else { /* Parent process */
......
......@@ -45,8 +45,8 @@ HYD_Status HYDU_Sock_listen(int *listen_fd, char *port_range, uint16_t * port)
*listen_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (*listen_fd < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "cannot open socket (errno: %d)\n",
errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "cannot open socket (%s)\n",
HYDU_String_error(errno));
if (setsockopt(*listen_fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(int)) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "cannot set TCP_NODELAY\n");
......@@ -70,7 +70,8 @@ HYD_Status HYDU_Sock_listen(int *listen_fd, char *port_range, uint16_t * port)
/* If the address is in use, we should try the next
* port. Otherwise, it's an error. */
if (errno != EADDRINUSE)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "bind error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "bind error (%s)\n",
HYDU_String_error(errno));
}
else /* We got a port */
break;
......@@ -81,7 +82,8 @@ HYD_Status HYDU_Sock_listen(int *listen_fd, char *port_range, uint16_t * port)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "no port to bind\n");
if (listen(*listen_fd, -1) < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "listen error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "listen error (%s)\n",
HYDU_String_error(errno));
/* We asked for any port, so we need to find out which port we
* actually got. */
......@@ -89,8 +91,8 @@ HYD_Status HYDU_Sock_listen(int *listen_fd, char *port_range, uint16_t * port)
socklen_t sinlen = sizeof(sa);
if (getsockname(*listen_fd, (struct sockaddr *) &sa, &sinlen) < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "getsockname error (errno: %d)\n",
errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "getsockname error (%s)\n",
HYDU_String_error(errno));
*port = ntohs(sa.sin_port);
}
......@@ -119,20 +121,20 @@ HYD_Status HYDU_Sock_connect(const char *host, uint16_t port, int *fd)
ht = gethostbyname(host);
if (ht == NULL)
HYDU_ERR_SETANDJUMP1(status, HYD_INVALID_PARAM,
"unable to get host address (errno: %d)\n", errno);
"unable to get host address (%s)\n", HYDU_String_error(errno));
memcpy(&sa.sin_addr, ht->h_addr_list[0], ht->h_length);
/* Create a socket and set the required options */
*fd = socket(AF_INET, SOCK_STREAM, 0);
if (*fd < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "cannot open socket (errno: %d)\n",
errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "cannot open socket (%s)\n",
HYDU_String_error(errno));
/* Not being able to connect is not an error in all cases. So we
* return an error, but only print a warning message. The upper
* layer can decide what to do with the return status. */
if (connect(*fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
HYDU_Warn_printf("connect error (errno: %d)\n", errno);
HYDU_Warn_printf("connect error (%s)\n", HYDU_String_error(errno));
status = HYD_SOCK_ERROR;
goto fn_fail;
}
......@@ -154,7 +156,8 @@ HYD_Status HYDU_Sock_accept(int listen_fd, int *fd)
*fd = accept(listen_fd, 0, 0);
if (*fd < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "accept error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "accept error (%s)\n",
HYDU_String_error(errno));
fn_exit:
HYDU_FUNC_EXIT();
......@@ -186,7 +189,8 @@ HYD_Status HYDU_Sock_readline(int fd, char *buf, int maxlen, int *linelen)
else if (n < 0) {
if (errno == EINTR)
continue;
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "read error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "read error (%s)\n",
HYDU_String_error(errno));
}
*linelen += n;
......@@ -229,7 +233,8 @@ HYD_Status HYDU_Sock_read(int fd, void *buf, int maxlen, int *count)
} while (*count < 0 && errno == EINTR);
if (*count < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "read errno (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "read errno (%s)\n",
HYDU_String_error(errno));
fn_exit:
HYDU_FUNC_EXIT();
......@@ -255,7 +260,8 @@ HYD_Status HYDU_Sock_writeline(int fd, char *buf, int maxsize)
} while (n < 0 && errno == EINTR);
if (n < maxsize)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "write error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "write error (%s)\n",
HYDU_String_error(errno));
fn_exit:
HYDU_FUNC_EXIT();
......@@ -278,7 +284,8 @@ HYD_Status HYDU_Sock_write(int fd, void *buf, int maxsize)
} while (n < 0 && errno == EINTR);
if (n < maxsize)
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "write error (errno: %d)\n", errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "write error (%s)\n",
HYDU_String_error(errno));
fn_exit:
HYDU_FUNC_EXIT();
......@@ -345,8 +352,8 @@ HYD_Status HYDU_Sock_stdout_cb(int fd, HYD_Event_t events, int stdout_fd, int *c
count = read(fd, buf, HYD_TMPBUF_SIZE);
if (count < 0) {
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR, "read error on %d (errno: %d)\n",
fd, errno);
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR, "read error on %d (%s)\n",
fd, HYDU_String_error(errno));
}
else if (count == 0) {
/* The connection has closed */
......@@ -358,8 +365,8 @@ HYD_Status HYDU_Sock_stdout_cb(int fd, HYD_Event_t events, int stdout_fd, int *c
while (written != count) {
ret = write(stdout_fd, buf + written, count - written);
if (ret < 0 && errno != EAGAIN)
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR, "write errnor on %d (errno: %d)\n",
stdout_fd, errno);
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR, "write error on %d (%s)\n",
stdout_fd, HYDU_String_error(errno));
if (ret > 0)
written += ret;
}
......@@ -391,8 +398,8 @@ HYD_Status HYDU_Sock_stdin_cb(int fd, HYD_Event_t events, char *buf, int *buf_co
if (*buf_count) {
count = write(fd, buf + *buf_offset, *buf_count);
if (count < 0)
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR,
"write error on %d (errno: %d)\n", fd, errno)
HYDU_ERR_SETANDJUMP2(status, HYD_SOCK_ERROR, "write error on %d (%s)\n",
fd, HYDU_String_error(errno))
*buf_offset += count;
*buf_count -= count;
break;
......@@ -407,8 +414,8 @@ HYD_Status HYDU_Sock_stdin_cb(int fd, HYD_Event_t events, char *buf, int *buf_co
break;
}
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "read error on 0 (errno: %d)\n",
errno);
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "read error on 0 (%s)\n",
HYDU_String_error(errno));
}
else if (count == 0) {
/* The connection has closed */
......
......@@ -95,3 +95,17 @@ HYD_Status HYDU_String_int_to_str(int x, char **str)
fn_fail:
goto fn_exit;
}
char *HYDU_String_error(int error)
{
char *str;
#if defined HAVE_STRERROR
str = strerror(error);
#else
str = MPIU_Strdup("errno: %d", error);
#endif /* HAVE_STRERROR */
return str;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment