summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2015-02-18 17:40:41 -0500
committerKeith Bostic <keith@wiredtiger.com>2015-02-18 17:41:22 -0500
commitd985bf7de6cdbf7b8c06e83270dc6c0c38c09678 (patch)
tree65655f60fdad1a0c0c3b5dee6d638d1a2fdc4b7a
parent3d1eeded1271b82ffb018500c55332689623eed7 (diff)
downloadmongo-d985bf7de6cdbf7b8c06e83270dc6c0c38c09678.tar.gz
I broke the Windows error handling code with the WT_SESSION.strerror
rework, take another run at it.
-rw-r--r--dist/api_err.py39
-rw-r--r--src/conn/api_strerror.c38
-rw-r--r--src/include/extern.h3
-rw-r--r--src/os_posix/os_errno.c38
-rw-r--r--src/os_win/os_errno.c51
-rw-r--r--src/session/session_api.c9
6 files changed, 78 insertions, 100 deletions
diff --git a/dist/api_err.py b/dist/api_err.py
index a35b3f931e6..d39f076656f 100644
--- a/dist/api_err.py
+++ b/dist/api_err.py
@@ -94,26 +94,39 @@ tfile.write('''/* DO NOT EDIT: automatically built by dist/api_err.py. */
* port didn't need anything more complex; Windows requires memory allocation
* of error strings, so we added the WT_SESSION.strerror method. Because we
* want wiredtiger_strerror to continue to be as thread-safe as possible, errors
- * are split into three categories: WiredTiger constant strings, system constant
- * strings and Everything Else, and we check constant strings before Everything
- * Else.
+ * are split into two categories: WiredTiger's or the system's constant strings
+ * and Everything Else, and we check constant strings before Everything Else.
*/
/*
- * __wiredtiger_error --
- *\tReturn a constant string for the WiredTiger errors.
+ * __wt_wiredtiger_error --
+ *\tReturn a constant string for WiredTiger POSIX-standard and errors.
*/
const char *
__wt_wiredtiger_error(int error)
{
+\tconst char *p;
+
+\t/*
+\t * Check for WiredTiger specific errors.
+\t */
\tswitch (error) {
''')
for err in errors:
tfile.write('\tcase ' + err.name + ':\n')
tfile.write('\t\treturn ("' + err.name + ': ' + err.desc + '");\n')
-
tfile.write('''\t}
+
+\t/*
+\t * POSIX errors are non-negative integers; check for 0 explicitly
+\t * in-case the underlying strerror doesn't handle 0, some don't.
+\t */
+\tif (error == 0)
+\t\treturn ("Successful return: 0");
+\tif (error > 0 && (p = strerror(error)) != NULL)
+\t\treturn (p);
+
\treturn (NULL);
}
@@ -125,20 +138,8 @@ const char *
wiredtiger_strerror(int error)
{
\tstatic char buf[128];
-\tconst char *p;
-
-\t/* Check for a constant string. */
-\tif ((p = __wt_wiredtiger_error(error)) != NULL)
-\t\treturn (p);
-\tif ((p = __wt_strerror(error)) != NULL)
-\t\treturn (p);
-
-\t/* Else, fill in the non-thread-safe static buffer. */
-\tif (snprintf(buf, sizeof(buf), "error return: %d", error) > 0)
-\t\treturn (buf);
-\t/* OK, we're done. */
-\treturn ("Unable to return error string");
+\treturn (__wt_strerror(NULL, error, buf, sizeof(buf)));
}
''')
tfile.close()
diff --git a/src/conn/api_strerror.c b/src/conn/api_strerror.c
index f08d70969dd..e41e402a1fd 100644
--- a/src/conn/api_strerror.c
+++ b/src/conn/api_strerror.c
@@ -7,18 +7,22 @@
* port didn't need anything more complex; Windows requires memory allocation
* of error strings, so we added the WT_SESSION.strerror method. Because we
* want wiredtiger_strerror to continue to be as thread-safe as possible, errors
- * are split into three categories: WiredTiger constant strings, system constant
- * strings and Everything Else, and we check constant strings before Everything
- * Else.
+ * are split into two categories: WiredTiger's or the system's constant strings
+ * and Everything Else, and we check constant strings before Everything Else.
*/
/*
- * __wiredtiger_error --
- * Return a constant string for the WiredTiger errors.
+ * __wt_wiredtiger_error --
+ * Return a constant string for WiredTiger POSIX-standard and errors.
*/
const char *
__wt_wiredtiger_error(int error)
{
+ const char *p;
+
+ /*
+ * Check for WiredTiger specific errors.
+ */
switch (error) {
case WT_ROLLBACK:
return ("WT_ROLLBACK: conflict between concurrent operations");
@@ -35,6 +39,16 @@ __wt_wiredtiger_error(int error)
case WT_RUN_RECOVERY:
return ("WT_RUN_RECOVERY: recovery must be run to continue");
}
+
+ /*
+ * POSIX errors are non-negative integers; check for 0 explicitly
+ * in-case the underlying strerror doesn't handle 0, some don't.
+ */
+ if (error == 0)
+ return ("Successful return: 0");
+ if (error > 0 && (p = strerror(error)) != NULL)
+ return (p);
+
return (NULL);
}
@@ -46,18 +60,6 @@ const char *
wiredtiger_strerror(int error)
{
static char buf[128];
- const char *p;
-
- /* Check for a constant string. */
- if ((p = __wt_wiredtiger_error(error)) != NULL)
- return (p);
- if ((p = __wt_strerror(error)) != NULL)
- return (p);
-
- /* Else, fill in the non-thread-safe static buffer. */
- if (snprintf(buf, sizeof(buf), "error return: %d", error) > 0)
- return (buf);
- /* OK, we're done. */
- return ("Unable to return error string");
+ return (__wt_strerror(NULL, error, buf, sizeof(buf)));
}
diff --git a/src/include/extern.h b/src/include/extern.h
index 3b08d79e842..af1ea057ca7 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -438,8 +438,7 @@ extern int __wt_dlopen(WT_SESSION_IMPL *session, const char *path, WT_DLH **dlhp
extern int __wt_dlsym(WT_SESSION_IMPL *session, WT_DLH *dlh, const char *name, int fail, void *sym_ret);
extern int __wt_dlclose(WT_SESSION_IMPL *session, WT_DLH *dlh);
extern int __wt_errno(void);
-extern const char *__wt_strerror(int error);
-extern const char *__wt_session_strerror(WT_SESSION_IMPL *session, int error);
+extern const char *__wt_strerror(WT_SESSION_IMPL *session, int error, char *errbuf, size_t errlen);
extern int __wt_exist(WT_SESSION_IMPL *session, const char *filename, int *existp);
extern void __wt_fallocate_config(WT_SESSION_IMPL *session, WT_FH *fh);
extern int __wt_fallocate( WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t offset, wt_off_t len);
diff --git a/src/os_posix/os_errno.c b/src/os_posix/os_errno.c
index c022cfda6bc..229b68e0008 100644
--- a/src/os_posix/os_errno.c
+++ b/src/os_posix/os_errno.c
@@ -24,39 +24,29 @@ __wt_errno(void)
/*
* __wt_strerror --
- * POSIX implementation of wiredtiger_strerror.
+ * POSIX implementation of WT_SESSION.strerror and wiredtiger_strerror.
*/
const char *
-__wt_strerror(int error)
+__wt_strerror(WT_SESSION_IMPL *session, int error, char *errbuf, size_t errlen)
{
const char *p;
/*
- * POSIX errors are non-negative integers; check for 0 explicitly
- * in-case the underlying strerror doesn't handle 0, some don't.
+ * Check for a WiredTiger or POSIX constant string, no buffer needed.
*/
- if (error == 0)
- return ("Successful return: 0");
- if (error > 0 && (p = strerror(error)) != NULL)
+ if ((p = __wt_wiredtiger_error(error)) != NULL)
return (p);
- return (NULL);
-}
-/*
- * __wt_session_strerror --
- * POSIX implementation of WT_SESSION.strerror.
- */
-const char *
-__wt_session_strerror(WT_SESSION_IMPL *session, int error)
-{
- const char *p;
-
- /* Check for POSIX errors. */
- if ((p = __wt_strerror(error)) != NULL)
- return (p);
-
- /* Fallback to a generic message. */
- if (__wt_buf_fmt(
+ /*
+ * When called from wiredtiger_strerror, write a passed-in buffer.
+ * When called from WT_SESSION.strerror, write the session's buffer.
+ *
+ * Fallback to a generic message.
+ */
+ if (session == NULL &&
+ snprintf(errbuf, errlen, "error return: %d", error) > 0)
+ return (errbuf);
+ if (session != NULL && __wt_buf_fmt(
session, &session->err, "error return: %d", error) == 0)
return (session->err.data);
diff --git a/src/os_win/os_errno.c b/src/os_win/os_errno.c
index c81432299a3..81bcdf9089e 100644
--- a/src/os_win/os_errno.c
+++ b/src/os_win/os_errno.c
@@ -58,43 +58,27 @@ __wt_errno(void)
/*
* __wt_strerror --
- * Windows implementation of wiredtiger_strerror.
+ * Windows implementation of WT_SESSION.strerror and wiredtiger_strerror.
*/
const char *
-__wt_strerror(int error)
+__wt_strerror(WT_SESSION_IMPL *session, int error, char *errbuf, size_t errlen)
{
+ DWORD lasterror;
const char *p;
+ char buf[512];
/*
- * POSIX errors are non-negative integers; check for 0 explicitly
- * in-case the underlying strerror doesn't handle 0, some don't.
+ * Check for a WiredTiger or POSIX constant string, no buffer needed.
*/
- if (error == 0)
- return ("Successful return: 0");
- if (error > 0 && (p = strerror(error)) != NULL)
+ if ((p = __wt_wiredtiger_error(error)) != NULL)
return (p);
- return (NULL);
-}
-
-/*
- * __wt_session_strerror --
- * Windows implementation of WT_SESSION.strerror.
- */
-const char *
-__wt_session_strerror(WT_SESSION_IMPL *session, int error)
-{
- DWORD lasterror;
- const char *p;
- char buf[256];
/*
- * Check for POSIX errors, Windows errors, then fallback to something
- * generic. Copy the string into the user's buffer, return success if
- * anything printed.
+ * When called from wiredtiger_strerror, write a passed-in buffer.
+ * When called from WT_SESSION.strerror, write the session's buffer.
+ *
+ * Check for Windows errors.
*/
- if ((p = __wt_strerror(error)) != NULL)
- return (p);
-
if (error < 0) {
error = __wt_map_error_to_windows_error(error);
@@ -108,13 +92,22 @@ __wt_session_strerror(WT_SESSION_IMPL *session, int error)
sizeof(buf),
NULL);
- if (lasterror != 0 &&
+ if (lasterror != 0 && session == NULL &&
+ snprintf(errbuf, errlen, "%s", buf) > 0)
+ return (errbuf);
+ if (lasterror != 0 && session != NULL &&
__wt_buf_set(session, &session->err, buf, strlen(buf)) == 0)
return (session->err.data);
-
- /* Fall through to the fallback error code */
}
+ /* Fallback to a generic message. */
+ if (session == NULL &&
+ snprintf(errbuf, errlen, "error return: %d", error) > 0)
+ return (errbuf);
+ if (session != NULL && __wt_buf_fmt(
+ session, &session->err, "error return: %d", error) == 0)
+ return (session->err.data);
+
/* Defeated. */
return ("Unable to return error string");
}
diff --git a/src/session/session_api.c b/src/session/session_api.c
index 986473ae1cc..e54553aa071 100644
--- a/src/session/session_api.c
+++ b/src/session/session_api.c
@@ -910,17 +910,10 @@ static const char *
__session_strerror(WT_SESSION *wt_session, int error)
{
WT_SESSION_IMPL *session;
- const char *p;
session = (WT_SESSION_IMPL *)wt_session;
- /* Check for a constant string. */
- if ((p = __wt_wiredtiger_error(error)) != NULL)
- return (p);
- if ((p = __wt_strerror(error)) != NULL)
- return (p);
-
- return (__wt_session_strerror(session, error));
+ return (__wt_strerror(session, error, NULL, 0));
}
/*