summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/os')
-rw-r--r--src/os/os_abort.c6
-rw-r--r--src/os/os_abs.c2
-rw-r--r--src/os/os_addrinfo.c2
-rw-r--r--src/os/os_alloc.c28
-rw-r--r--src/os/os_clock.c13
-rw-r--r--src/os/os_config.c2
-rw-r--r--src/os/os_cpu.c2
-rw-r--r--src/os/os_ctime.c7
-rw-r--r--src/os/os_dir.c2
-rw-r--r--src/os/os_errno.c2
-rw-r--r--src/os/os_fid.c2
-rw-r--r--src/os/os_flock.c2
-rw-r--r--src/os/os_fsync.c2
-rw-r--r--src/os/os_getenv.c2
-rw-r--r--src/os/os_handle.c15
-rw-r--r--src/os/os_map.c43
-rw-r--r--src/os/os_mkdir.c2
-rw-r--r--src/os/os_open.c2
-rw-r--r--src/os/os_path.c2
-rw-r--r--src/os/os_pid.c4
-rw-r--r--src/os/os_rename.c2
-rw-r--r--src/os/os_rmdir.c38
-rw-r--r--src/os/os_root.c2
-rw-r--r--src/os/os_rpath.c2
-rw-r--r--src/os/os_rw.c2
-rw-r--r--src/os/os_seek.c2
-rw-r--r--src/os/os_stack.c135
-rw-r--r--src/os/os_stat.c2
-rw-r--r--src/os/os_tmpdir.c2
-rw-r--r--src/os/os_truncate.c10
-rw-r--r--src/os/os_uid.c65
-rw-r--r--src/os/os_unlink.c2
-rw-r--r--src/os/os_yield.c2
33 files changed, 314 insertions, 94 deletions
diff --git a/src/os/os_abort.c b/src/os/os_abort.c
index 68b4bc05..72ac6751 100644
--- a/src/os/os_abort.c
+++ b/src/os/os_abort.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2005, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -13,11 +13,11 @@
/*
* __os_abort --
*
- * PUBLIC: void __os_abort __P((ENV *));
+ * PUBLIC: void __os_abort __P((const ENV *));
*/
void
__os_abort(env)
- ENV *env;
+ const ENV *env;
{
__os_stack(env); /* Try and get a stack trace. */
diff --git a/src/os/os_abs.c b/src/os/os_abs.c
index 4a1a5abd..a241c653 100644
--- a/src/os/os_abs.c
+++ b/src/os/os_abs.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_addrinfo.c b/src/os/os_addrinfo.c
index 205f41ec..aec30386 100644
--- a/src/os/os_addrinfo.c
+++ b/src/os/os_addrinfo.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2006, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_alloc.c b/src/os/os_alloc.c
index fb7bf109..478924df 100644
--- a/src/os/os_alloc.c
+++ b/src/os/os_alloc.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -11,7 +11,7 @@
#include "db_int.h"
#ifdef DIAGNOSTIC
-static void __os_guard __P((ENV *));
+static void __os_guard __P((const ENV *));
typedef union {
size_t size;
@@ -204,11 +204,11 @@ __os_strdup(env, str, storep)
* __os_calloc --
* The calloc(3) function for DB.
*
- * PUBLIC: int __os_calloc __P((ENV *, size_t, size_t, void *));
+ * PUBLIC: int __os_calloc __P((const ENV *, size_t, size_t, void *));
*/
int
__os_calloc(env, num, size, storep)
- ENV *env;
+ const ENV *env;
size_t num, size;
void *storep;
{
@@ -227,11 +227,11 @@ __os_calloc(env, num, size, storep)
* __os_malloc --
* The malloc(3) function for DB.
*
- * PUBLIC: int __os_malloc __P((ENV *, size_t, void *));
+ * PUBLIC: int __os_malloc __P((const ENV *, size_t, void *));
*/
int
__os_malloc(env, size, storep)
- ENV *env;
+ const ENV *env;
size_t size;
void *storep;
{
@@ -261,9 +261,11 @@ __os_malloc(env, size, storep)
* Windows/NT in an MT environment.
*/
if ((ret = __os_get_errno_ret_zero()) == 0) {
- ret = ENOMEM;
+ ret = USR_ERR(env, ENOMEM);
__os_set_errno(ENOMEM);
}
+ else
+ (void)USR_ERR(env, ret);
__db_err(env, ret, DB_STR_A("0147", "malloc: %lu", "%lu"),
(u_long)size);
return (ret);
@@ -292,11 +294,11 @@ __os_malloc(env, size, storep)
* __os_realloc --
* The realloc(3) function for DB.
*
- * PUBLIC: int __os_realloc __P((ENV *, size_t, void *));
+ * PUBLIC: int __os_realloc __P((const ENV *, size_t, void *));
*/
int
__os_realloc(env, size, storep)
- ENV *env;
+ const ENV *env;
size_t size;
void *storep;
{
@@ -345,7 +347,7 @@ __os_realloc(env, size, storep)
* Windows/NT in an MT environment.
*/
if ((ret = __os_get_errno_ret_zero()) == 0) {
- ret = ENOMEM;
+ ret = USR_ERR(env, ENOMEM);
__os_set_errno(ENOMEM);
}
__db_err(env, ret, DB_STR_A("0148", "realloc: %lu", "%lu"),
@@ -368,11 +370,11 @@ __os_realloc(env, size, storep)
* __os_free --
* The free(3) function for DB.
*
- * PUBLIC: void __os_free __P((ENV *, void *));
+ * PUBLIC: void __os_free __P((const ENV *, void *));
*/
void
__os_free(env, ptr)
- ENV *env;
+ const ENV *env;
void *ptr;
{
#ifdef DIAGNOSTIC
@@ -416,7 +418,7 @@ __os_free(env, ptr)
*/
static void
__os_guard(env)
- ENV *env;
+ const ENV *env;
{
__db_errx(env, DB_STR("0149",
"Guard byte incorrect during free"));
diff --git a/src/os/os_clock.c b/src/os/os_clock.c
index 25eeb704..78f1c8df 100644
--- a/src/os/os_clock.c
+++ b/src/os/os_clock.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -14,11 +14,15 @@
* __os_gettime --
* Return the current time-of-day clock in seconds and nanoseconds.
*
- * PUBLIC: void __os_gettime __P((ENV *, db_timespec *, int));
+ * If you want the time of day, pass 0 in the monotonic argument. If you pass
+ * non-zero, you might get time-of-day or you might get a non-decreasing number
+ * which is unrelated to the time of day, such as the seconds since system boot.
+ *
+ * PUBLIC: void __os_gettime __P((const ENV *, db_timespec *, int));
*/
void
__os_gettime(env, tp, monotonic)
- ENV *env;
+ const ENV *env;
db_timespec *tp;
int monotonic;
{
@@ -35,7 +39,6 @@ __os_gettime(env, tp, monotonic)
RETRY_CHK((clock_gettime(
CLOCK_REALTIME, (struct timespec *)tp)), ret);
- RETRY_CHK((clock_gettime(CLOCK_REALTIME, (struct timespec *)tp)), ret);
if (ret != 0) {
sc = "clock_gettime";
goto err;
@@ -69,5 +72,5 @@ __os_gettime(env, tp, monotonic)
return;
err: __db_syserr(env, ret, "%s", sc);
- (void)__env_panic(env, __os_posix_err(ret));
+ (void)__env_panic((ENV *) env, __os_posix_err(ret));
}
diff --git a/src/os/os_config.c b/src/os/os_config.c
index c455a349..3fe2f045 100644
--- a/src/os/os_config.c
+++ b/src/os/os_config.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_cpu.c b/src/os/os_cpu.c
index 6b7f9f1e..53cadecb 100644
--- a/src/os/os_cpu.c
+++ b/src/os/os_cpu.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_ctime.c b/src/os/os_ctime.c
index 3f656c32..82925cc1 100644
--- a/src/os/os_ctime.c
+++ b/src/os/os_ctime.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -32,10 +32,7 @@ __os_ctime(tod, time_buf)
* int.
*/
#if defined(HAVE_VXWORKS)
- {
- size_t buflen = CTIME_BUFLEN;
- (void)ctime_r(tod, time_buf, &buflen);
- }
+ (void)ctime_r(tod, time_buf);
#elif defined(HAVE_CTIME_R_3ARG)
(void)ctime_r(tod, time_buf, CTIME_BUFLEN);
#elif defined(HAVE_CTIME_R)
diff --git a/src/os/os_dir.c b/src/os/os_dir.c
index 42bad194..7bd91bff 100644
--- a/src/os/os_dir.c
+++ b/src/os/os_dir.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_errno.c b/src/os/os_errno.c
index a8219f90..9bc15513 100644
--- a/src/os/os_errno.c
+++ b/src/os/os_errno.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_fid.c b/src/os/os_fid.c
index f2d80e25..43c61202 100644
--- a/src/os/os_fid.c
+++ b/src/os/os_fid.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_flock.c b/src/os/os_flock.c
index 904d5efe..8f58f244 100644
--- a/src/os/os_flock.c
+++ b/src/os/os_flock.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_fsync.c b/src/os/os_fsync.c
index 4b757b2c..377d7ff3 100644
--- a/src/os/os_fsync.c
+++ b/src/os/os_fsync.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_getenv.c b/src/os/os_getenv.c
index 05972112..b7c4e990 100644
--- a/src/os/os_getenv.c
+++ b/src/os/os_getenv.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_handle.c b/src/os/os_handle.c
index 8ae9dc7f..7dbe31e1 100644
--- a/src/os/os_handle.c
+++ b/src/os/os_handle.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -90,7 +90,7 @@ __os_openhandle(env, name, flags, mode, fhpp)
* return EEXISTS.
*/
DB_END_SINGLE_THREAD;
- ret = EEXIST;
+ ret = USR_ERR(env, EEXIST);
goto err;
}
/*
@@ -127,7 +127,10 @@ __os_openhandle(env, name, flags, mode, fhpp)
break;
}
- switch (ret = __os_posix_err(__os_get_syserr())) {
+ ret = __os_posix_err(__os_get_syserr());
+ if (ret != ENOENT)
+ (void)USR_ERR(env, ret);
+ switch (ret) {
case EMFILE:
case ENFILE:
case ENOSPC:
@@ -160,9 +163,8 @@ __os_openhandle(env, name, flags, mode, fhpp)
/* Deny file descriptor access to any child process. */
if ((fcntl_flags = fcntl(fhp->fd, F_GETFD)) == -1 ||
fcntl(fhp->fd, F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) {
- ret = __os_get_syserr();
- __db_syserr(env, ret, DB_STR("0162",
- "fcntl(F_SETFD)"));
+ ret = USR_ERR(env, __os_get_syserr());
+ __db_syserr(env, ret, DB_STR("0162", "fcntl(F_SETFD)"));
ret = __os_posix_err(ret);
goto err;
}
@@ -226,6 +228,7 @@ __os_closehandle(env, fhp)
else
RETRY_CHK((close(fhp->fd)), ret);
if (ret != 0) {
+ ret = USR_ERR(env, ret);
__db_syserr(env, ret, DB_STR("0164", "close"));
ret = __os_posix_err(ret);
}
diff --git a/src/os/os_map.c b/src/os/os_map.c
index 0528f473..b17bf107 100644
--- a/src/os/os_map.c
+++ b/src/os/os_map.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -213,6 +213,15 @@ __os_attach(env, infop, rp)
if (rp->max < rp->size)
rp->max = rp->size;
if (ret == 0 && F_ISSET(infop, REGION_CREATE)) {
+#ifdef HAVE_MLOCK
+ /*
+ * When locking the region in memory extend it fully so that it
+ * can all be mlock()'d now, and not later when paging could
+ * interfere with the application. [#21379]
+ */
+ if (F_ISSET(env, ENV_LOCKDOWN))
+ rp->size = rp->max;
+#endif
if (F_ISSET(dbenv, DB_ENV_REGION_INIT))
ret = __db_file_write(env, infop->fhp,
rp->size / MEGABYTE, rp->size % MEGABYTE, 0x00);
@@ -255,7 +264,7 @@ __os_detach(env, infop, destroy)
{
DB_ENV *dbenv;
REGION *rp;
- int ret;
+ int ret, t_ret;
/*
* We pass a DB_ENV handle to the user's replacement unmap function,
@@ -263,8 +272,16 @@ __os_detach(env, infop, destroy)
*/
DB_ASSERT(env, env != NULL && env->dbenv != NULL);
dbenv = env->dbenv;
+ ret = 0;
+ /*
+ * Don't use a region which is no longer valid, e.g., after the
+ * env has been removed.
+ */
rp = infop->rp;
+ if ((rp->id != 0 && rp->id != infop->id) ||
+ rp->type <= INVALID_REGION_TYPE || rp->type > REGION_TYPE_MAX)
+ return (EINVAL);
/* If the user replaced the unmap call, call through their interface. */
if (DB_GLOBAL(j_region_unmap) != NULL)
@@ -314,16 +331,26 @@ __os_detach(env, infop, destroy)
return (ret);
}
+ if (F_ISSET(env, ENV_FORCESYNCENV))
+ if (msync(infop->addr, rp->max, MS_INVALIDATE | MS_SYNC) != 0) {
+ t_ret = __os_get_syserr();
+ __db_syserr(env, t_ret, DB_STR("0248",
+ "msync failed on closing environment"));
+ if (ret == 0)
+ ret = t_ret;
+ }
+
if (munmap(infop->addr, rp->max) != 0) {
- ret = __os_get_syserr();
- __db_syserr(env, ret, DB_STR("0123", "munmap"));
- return (__os_posix_err(ret));
+ t_ret = __os_get_syserr();
+ __db_syserr(env, t_ret, DB_STR("0123", "munmap"));
+ if (ret == 0)
+ ret = t_ret;
}
- if (destroy && (ret = __os_unlink(env, infop->name, 1)) != 0)
- return (ret);
+ if (destroy && (t_ret = __os_unlink(env, infop->name, 1)) != 0 && ret == 0)
+ ret = t_ret;
- return (0);
+ return (ret);
#else
COMPQUIET(destroy, 0);
COMPQUIET(ret, 0);
diff --git a/src/os/os_mkdir.c b/src/os/os_mkdir.c
index 800d445c..b3034e30 100644
--- a/src/os/os_mkdir.c
+++ b/src/os/os_mkdir.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_open.c b/src/os/os_open.c
index 5090c8e1..0c58848e 100644
--- a/src/os/os_open.c
+++ b/src/os/os_open.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_path.c b/src/os/os_path.c
index 478fdf45..b712b31a 100644
--- a/src/os/os_path.c
+++ b/src/os/os_path.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_pid.c b/src/os/os_pid.c
index b1b94d60..9efe4633 100644
--- a/src/os/os_pid.c
+++ b/src/os/os_pid.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -40,7 +40,7 @@ __os_id(dbenv, pidp, tidp)
*pidp = dbenv->env->pid_cache;
}
-/*
+/*
* When building on MinGW, we define both HAVE_PTHREAD_SELF and DB_WIN32,
* and we are using pthreads instead of Windows threads implementation.
* So here, we need to check the thread implementations before checking
diff --git a/src/os/os_rename.c b/src/os/os_rename.c
index 63aac7bb..1a3d7cbd 100644
--- a/src/os/os_rename.c
+++ b/src/os/os_rename.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_rmdir.c b/src/os/os_rmdir.c
new file mode 100644
index 00000000..ab3a1556
--- /dev/null
+++ b/src/os/os_rmdir.c
@@ -0,0 +1,38 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
+ *
+ * $Id$
+ */
+
+#include "db_config.h"
+
+#include "db_int.h"
+
+/*
+ * __os_rmdir --
+ * Remove a directory.
+ *
+ * PUBLIC: int __os_rmdir __P((ENV *, const char *));
+ */
+int
+__os_rmdir(env, name)
+ ENV *env;
+ const char *name;
+{
+ DB_ENV *dbenv;
+ int ret;
+
+ dbenv = env == NULL ? NULL : env->dbenv;
+ if (dbenv != NULL &&
+ FLD_ISSET(dbenv->verbose, DB_VERB_FILEOPS | DB_VERB_FILEOPS_ALL))
+ __db_msg(env, DB_STR_A("0239", "fileops: rmdir %s",
+ "%s"), name);
+
+ RETRY_CHK((rmdir(name)), ret);
+ if (ret != 0)
+ return (__os_posix_err(ret));
+
+ return (ret);
+}
diff --git a/src/os/os_root.c b/src/os/os_root.c
index 77e7a72c..6634a4a2 100644
--- a/src/os/os_root.c
+++ b/src/os/os_root.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_rpath.c b/src/os/os_rpath.c
index 16f3e54c..48c59b3d 100644
--- a/src/os/os_rpath.c
+++ b/src/os/os_rpath.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_rw.c b/src/os/os_rw.c
index c0967514..cc665ee4 100644
--- a/src/os/os_rw.c
+++ b/src/os/os_rw.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_seek.c b/src/os/os_seek.c
index 4676d33a..95408f3d 100644
--- a/src/os/os_seek.c
+++ b/src/os/os_seek.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_stack.c b/src/os/os_stack.c
index 037080f3..9844930f 100644
--- a/src/os/os_stack.c
+++ b/src/os/os_stack.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -14,32 +14,143 @@
#include <execinfo.h>
#endif
+#undef __DB_STACK_MAXFRAMES
+#define __DB_STACK_MAXFRAMES 25
+
/*
* __os_stack --
- * Output a stack trace to the message file handle.
+ * Output a stack trace in a single write to the error file handle.
*
- * PUBLIC: void __os_stack __P((ENV *));
+ * PUBLIC: void __os_stack __P((const ENV *));
*/
void
__os_stack(env)
- ENV *env;
+ const ENV *env;
+{
+ /* Adjust by 2 to exclude __os_stack() and __os_stack_top(). */
+ __os_stack_top(env, __DB_STACK_MAXFRAMES - 2, 2);
+}
+
+/*
+ * __os_stack_top --
+ * Output just a certain range of stack frames to the error file handle.
+ *
+ * PUBLIC: void __os_stack_top __P((const ENV *, unsigned, unsigned));
+ */
+void
+__os_stack_top(env, nframes, skipframes)
+ const ENV *env;
+ unsigned nframes;
+ unsigned skipframes;
{
#if defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
- void *array[200];
- size_t i, size;
- char **strings;
+ char buf[__DB_STACK_MAXFRAMES * 80]; /* Allow for 80 chars/line. */
+ __os_stack_text(env, buf, sizeof(buf), nframes, skipframes + 1);
+ __db_errx(env, "Top of stack:\n%s", buf);
+#else
+ COMPQUIET(env, NULL);
+ COMPQUIET(nframes, 0);
+ COMPQUIET(skipframes, 0);
+#endif
+}
+
+/*
+ * __os_stack_text --
+ * 'Print' the current stack into a char text buffer.
+ *
+ * PUBLIC: void __os_stack_text
+ * PUBLIC: __P((const ENV *, char *, size_t, unsigned, unsigned));
+ */
+void
+__os_stack_text(env, result, bufsize, nframes, skip)
+ const ENV *env;
+ char *result;
+ size_t bufsize;
+ unsigned nframes;
+ unsigned skip;
+{
+ DB_MSGBUF mb;
+
+ DB_MSGBUF_INIT(&mb);
+ mb.buf = mb.cur = result;
+ mb.len = bufsize;
+ F_SET(&mb, DB_MSGBUF_PREALLOCATED);
+ __os_stack_msgadd(env, &mb, nframes, skip, NULL);
+}
+
+/*
+ * __os_stack_save --
+ * Save a certain range of stack frames into the frames argument.
+ *
+ * PUBLIC: int __os_stack_save __P((const ENV *, unsigned, void **));
+ */
+int
+__os_stack_save(env, nframes, frames)
+ const ENV *env;
+ unsigned nframes;
+ void **frames;
+{
+ COMPQUIET(env, NULL);
+#if defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
/*
* Solaris and the GNU C library support this interface. Solaris
* has additional interfaces (printstack and walkcontext), I don't
* know if they offer any additional value or not.
*/
- size = backtrace(array, sizeof(array) / sizeof(array[0]));
- strings = backtrace_symbols(array, size);
+ return ((int) backtrace(frames, nframes));
+#else
+ COMPQUIET(nframes, 0);
+ COMPQUIET(frames, NULL);
+ return (0);
+#endif
+}
+
+/*
+ * __os_stack_msgadd --
+ * Decode a stack and add it to a DB_MSGBUF. The stack was either
+ * previously obtained stack, e.g., from __os_stack_save(), or if it is
+ * null, the current stack is fetched here.
+ *
+ * PUBLIC: void __os_stack_msgadd
+ * PUBLIC: __P((const ENV *, DB_MSGBUF *, unsigned, unsigned, void **));
+ */
+void
+__os_stack_msgadd(env, mb, totalframes, skipframes, stack)
+ const ENV *env;
+ DB_MSGBUF *mb;
+ unsigned totalframes;
+ unsigned skipframes;
+ void **stack;
+{
+#if defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
+ char **strings;
+ void *local_frames[__DB_STACK_MAXFRAMES];
+ unsigned i;
+
+ if (stack == NULL) {
+ stack = local_frames;
+ if (totalframes > __DB_STACK_MAXFRAMES)
+ totalframes = __DB_STACK_MAXFRAMES;
+ totalframes = backtrace(local_frames, totalframes);
+ skipframes++;
+ }
+
+ /*
+ * Solaris and the GNU C library support this interface. Solaris
+ * has additional interfaces (printstack and walkcontext) which have
+ * know if they offer any additional value or not.
+ */
+ strings = backtrace_symbols(stack, totalframes);
- for (i = 0; i < size; ++i)
- __db_errx(env, "%s", strings[i]);
+ for (i = skipframes; i < totalframes; ++i)
+ __db_msgadd((ENV *)env, mb, "\t%s\n", strings[i]);
free(strings);
-#endif
+#else
COMPQUIET(env, NULL);
+ COMPQUIET(mb, NULL);
+ COMPQUIET(totalframes, 0);
+ COMPQUIET(skipframes, 0);
+ COMPQUIET(stack, NULL);
+#endif
}
diff --git a/src/os/os_stat.c b/src/os/os_stat.c
index 43c66075..493531b7 100644
--- a/src/os/os_stat.c
+++ b/src/os/os_stat.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_tmpdir.c b/src/os/os_tmpdir.c
index 06d35ba9..f41383d7 100644
--- a/src/os/os_tmpdir.c
+++ b/src/os/os_tmpdir.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_truncate.c b/src/os/os_truncate.c
index f559e9cb..473db9cc 100644
--- a/src/os/os_truncate.c
+++ b/src/os/os_truncate.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2004, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -14,14 +14,16 @@
* __os_truncate --
* Truncate the file.
*
- * PUBLIC: int __os_truncate __P((ENV *, DB_FH *, db_pgno_t, u_int32_t));
+ * PUBLIC: int __os_truncate
+ * PUBLIC: __P((ENV *, DB_FH *, db_pgno_t, u_int32_t, off_t));
*/
int
-__os_truncate(env, fhp, pgno, pgsize)
+__os_truncate(env, fhp, pgno, pgsize, relative)
ENV *env;
DB_FH *fhp;
db_pgno_t pgno;
u_int32_t pgsize;
+ off_t relative;
{
DB_ENV *dbenv;
off_t offset;
@@ -33,7 +35,7 @@ __os_truncate(env, fhp, pgno, pgsize)
* Truncate a file so that "pgno" is discarded from the end of the
* file.
*/
- offset = (off_t)pgsize * pgno;
+ offset = (off_t)pgsize * pgno + relative;
if (dbenv != NULL &&
FLD_ISSET(dbenv->verbose, DB_VERB_FILEOPS | DB_VERB_FILEOPS_ALL))
diff --git a/src/os/os_uid.c b/src/os/os_uid.c
index 2e5c9f87..c3bccb3d 100644
--- a/src/os/os_uid.c
+++ b/src/os/os_uid.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -26,8 +26,6 @@ __os_unique_id(env, idp)
pid_t pid;
u_int32_t id;
- *idp = 0;
-
dbenv = env == NULL ? NULL : env->dbenv;
/*
@@ -35,21 +33,60 @@ __os_unique_id(env, idp)
* time of day and a stack address, all XOR'd together.
*/
__os_id(dbenv, &pid, NULL);
- __os_gettime(env, &v, 1);
+ __os_gettime(env, &v, 0);
id = (u_int32_t)pid ^
(u_int32_t)v.tv_sec ^ (u_int32_t)v.tv_nsec ^ P_TO_UINT32(&pid);
- /*
- * We could try and find a reasonable random-number generator, but
- * that's not all that easy to do. Seed and use srand()/rand(), if
- * we can find them.
- */
- if (DB_GLOBAL(uid_init) == 0) {
- DB_GLOBAL(uid_init) = 1;
- srand((u_int)id);
- }
- id ^= (u_int)rand();
+ if (DB_GLOBAL(random_seeded) == 0)
+ __os_srandom(id);
+ id ^= __os_random();
*idp = id;
}
+
+/*
+ * __os_srandom --
+ * Set the random number generator seed for BDB.
+ *
+ * PUBLIC: void __os_srandom __P((u_int));
+ */
+void
+__os_srandom(seed)
+ u_int seed;
+{
+ DB_GLOBAL(random_seeded) = 1;
+#ifdef HAVE_RANDOM_R
+ (void)initstate_r(seed, &DB_GLOBAL(random_state),
+ sizeof(DB_GLOBAL(random_state)), &DB_GLOBAL(random_data));
+ (void)srandom_r(seed, &DB_GLOBAL(random_data));
+#elif defined(HAVE_RANDOM)
+ srandom(seed);
+#else
+ srand(seed);
+#endif
+}
+
+/*
+ * __os_random --
+ * Return the next the random number generator for BDB.
+ *
+ * PUBLIC: u_int __os_random __P((void));
+ */
+u_int
+__os_random()
+{
+#ifdef HAVE_RANDOM_R
+ int32_t result;
+#endif
+ if (DB_GLOBAL(random_seeded) == 0)
+ __os_srandom((u_int)time(NULL));
+#ifdef HAVE_RANDOM_R
+ random_r(&DB_GLOBAL(random_data), &result);
+ return ((u_int)result);
+#elif defined(HAVE_RANDOM)
+ return ((u_int)random());
+#else
+ return ((u_int)rand());
+#endif
+}
diff --git a/src/os/os_unlink.c b/src/os/os_unlink.c
index f9a0b688..9b6d26fa 100644
--- a/src/os/os_unlink.c
+++ b/src/os/os_unlink.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
diff --git a/src/os/os_yield.c b/src/os/os_yield.c
index f0e170f0..ff54921e 100644
--- a/src/os/os_yield.c
+++ b/src/os/os_yield.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/