From e8d154baea1877d0daf81083c2d53ffa9fa46010 Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Thu, 29 Jan 2015 15:43:57 -0800 Subject: [PATCH] HADOOP-11403. Avoid using sys_errlist on Solaris, which lacks support for it (Malcolm Kavalsky via Colin P. McCabe) (cherry picked from commit e36ef3b4022a8527cdfa937c4ffc9d46e71cfe28) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../hadoop-common/src/main/native/src/exception.c | 6 ++++++ .../src/org/apache/hadoop/io/nativeio/NativeIO.c | 7 ++----- .../src/contrib/libwebhdfs/src/hdfs_http_client.c | 11 ++--------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 9a060c27172..55f2a99d2ac 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -438,6 +438,9 @@ Release 2.7.0 - UNRELEASED HADOOP-9907. Webapp http://hostname:port/metrics link is not working. (aajisaka) + HADOOP-11403. Avoid using sys_errlist on Solaris, which lacks support for it + (Malcolm Kavalsky via Colin P. McCabe) + Release 2.6.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/native/src/exception.c b/hadoop-common-project/hadoop-common/src/main/native/src/exception.c index 228af11bd8e..fc072e8002b 100644 --- a/hadoop-common-project/hadoop-common/src/main/native/src/exception.c +++ b/hadoop-common-project/hadoop-common/src/main/native/src/exception.c @@ -110,9 +110,15 @@ jthrowable newIOException(JNIEnv* env, const char *fmt, ...) const char* terror(int errnum) { + +#if defined(__sun) +// MT-Safe under Solaris which doesn't support sys_errlist/sys_nerr + return strerror(errnum); +#else if ((errnum < 0) || (errnum >= sys_nerr)) { return "unknown error."; } return sys_errlist[errnum]; +#endif } diff --git a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c index d7f8d4ba491..071d8300026 100644 --- a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c +++ b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c @@ -19,6 +19,7 @@ #include "org_apache_hadoop.h" #include "org_apache_hadoop_io_nativeio_NativeIO.h" #include "org_apache_hadoop_io_nativeio_NativeIO_POSIX.h" +#include "exception.h" #ifdef UNIX #include @@ -893,11 +894,7 @@ void throw_ioe(JNIEnv* env, int errnum) char message[80]; jstring jstr_message; - if ((errnum >= 0) && (errnum < sys_nerr)) { - snprintf(message, sizeof(message), "%s", sys_errlist[errnum]); - } else { - snprintf(message, sizeof(message), "Unknown error %d", errnum); - } + snprintf(message,sizeof(message),"%s",terror(errnum)); jobject errno_obj = errno_to_enum(env, errnum); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/contrib/libwebhdfs/src/hdfs_http_client.c b/hadoop-hdfs-project/hadoop-hdfs/src/contrib/libwebhdfs/src/hdfs_http_client.c index e41f950828d..dc58318b025 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/contrib/libwebhdfs/src/hdfs_http_client.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/contrib/libwebhdfs/src/hdfs_http_client.c @@ -21,21 +21,14 @@ #include #include "hdfs_http_client.h" +#include "exception.h" static pthread_mutex_t curlInitMutex = PTHREAD_MUTEX_INITIALIZER; static volatile int curlGlobalInited = 0; const char *hdfs_strerror(int errnoval) { - const char *msg = NULL; - if (errnoval < 0 || errnoval >= sys_nerr) { - msg = "Invalid Error Code"; - } else if (sys_errlist == NULL) { - msg = "Unknown Error"; - } else { - msg = sys_errlist[errnoval]; - } - return msg; + return terror(errnoval); } int initResponseBuffer(struct ResponseBuffer **buffer)