Blame SOURCES/db-5.3.28-condition-variable-ppc.patch

b30d9d
diff -up db-5.3.28/src/dbinc_auto/int_def.in.pthreads_ppc db-5.3.28/src/dbinc_auto/int_def.in
b30d9d
--- db-5.3.28/src/dbinc_auto/int_def.in.pthreads_ppc	2017-06-26 15:06:09.282020804 +0200
b30d9d
+++ db-5.3.28/src/dbinc_auto/int_def.in	2017-06-26 15:06:22.238771039 +0200
b30d9d
@@ -1572,6 +1572,7 @@
b30d9d
 #define	__os_strerror __os_strerror@DB_VERSION_UNIQUE_NAME@
b30d9d
 #define	__os_posix_err __os_posix_err@DB_VERSION_UNIQUE_NAME@
b30d9d
 #define	__os_fileid __os_fileid@DB_VERSION_UNIQUE_NAME@
b30d9d
+#define	__check_lock_fn __check_lock_fn@DB_VERSION_UNIQUE_NAME@
b30d9d
 #define	__os_fdlock __os_fdlock@DB_VERSION_UNIQUE_NAME@
b30d9d
 #define	__os_fsync __os_fsync@DB_VERSION_UNIQUE_NAME@
b30d9d
 #define	__os_getenv __os_getenv@DB_VERSION_UNIQUE_NAME@
b30d9d
diff -up db-5.3.28/src/dbinc_auto/os_ext.h.pthreads_ppc db-5.3.28/src/dbinc_auto/os_ext.h
b30d9d
--- db-5.3.28/src/dbinc_auto/os_ext.h.pthreads_ppc	2017-06-26 15:05:23.792897700 +0200
b30d9d
+++ db-5.3.28/src/dbinc_auto/os_ext.h	2017-06-26 15:06:22.172772311 +0200
b30d9d
@@ -41,6 +41,7 @@ void __os_set_errno __P((int));
b30d9d
 char *__os_strerror __P((int, char *, size_t));
b30d9d
 int __os_posix_err __P((int));
b30d9d
 int __os_fileid __P((ENV *, const char *, int, u_int8_t *));
b30d9d
+int __check_lock_fn __P((char *, pid_t));
b30d9d
 int __os_fdlock __P((ENV *, DB_FH *, off_t, db_lockmode_t, int));
b30d9d
 int __os_fsync __P((ENV *, DB_FH *));
b30d9d
 int __os_getenv __P((ENV *, const char *, char **, size_t));
b30d9d
diff -up db-5.3.28/src/env/env_region.c.pthreads_ppc db-5.3.28/src/env/env_region.c
b30d9d
--- db-5.3.28/src/env/env_region.c.pthreads_ppc	2017-06-26 15:04:40.805726365 +0200
b30d9d
+++ db-5.3.28/src/env/env_region.c	2017-06-26 15:04:40.807726326 +0200
b30d9d
@@ -305,14 +305,6 @@ user_map_functions:
b30d9d
 		goto creation;
b30d9d
 	}
b30d9d
 
b30d9d
-    /* We have an old environment but cannot rebuild it safely. */
b30d9d
-    if (ret == DB_OLD_VERSION) {
b30d9d
- 		__db_errx(env, DB_STR("1539",
b30d9d
-		    "Build signature doesn't match environment"));
b30d9d
-		ret = DB_VERSION_MISMATCH;
b30d9d
-        goto err;
b30d9d
-    }
b30d9d
-
b30d9d
 	if (renv->majver != DB_VERSION_MAJOR ||
b30d9d
 	    renv->minver != DB_VERSION_MINOR) {
b30d9d
 		/*
b30d9d
@@ -337,6 +329,20 @@ user_map_functions:
b30d9d
 		goto err;
b30d9d
 	}
b30d9d
 
b30d9d
+    /*
b30d9d
+     * We have an old environment but cannot rebuild it safely.
b30d9d
+     * The environment might still be readable by the current process
b30d9d
+     * (only the libpthread timestamp changed) if this process is the one
b30d9d
+     * that is holding the lock on the region file as we can be sure
b30d9d
+     * the environment did not get rebuilt under our feet.
b30d9d
+     */
b30d9d
+    if (ret == DB_OLD_VERSION && __check_lock_fn(env->lockfhp->name, getpid()) ) {
b30d9d
+       __db_errx(env, DB_STR("1539",
b30d9d
+           "Build signature doesn't match environment"));
b30d9d
+       ret = DB_VERSION_MISMATCH;
b30d9d
+        goto err;
b30d9d
+    }
b30d9d
+
b30d9d
 	/*
b30d9d
 	 * Check if the environment has had a catastrophic failure.
b30d9d
 	 *
b30d9d
diff -up db-5.3.28/src/os/os_flock.c.pthreads_ppc db-5.3.28/src/os/os_flock.c
b30d9d
--- db-5.3.28/src/os/os_flock.c.pthreads_ppc	2017-06-26 15:04:40.806726346 +0200
b30d9d
+++ db-5.3.28/src/os/os_flock.c	2017-06-26 15:04:40.807726326 +0200
b30d9d
@@ -15,6 +15,70 @@ static int __os_filelocking_notsup __P((
b30d9d
 #endif
b30d9d
 
b30d9d
 /*
b30d9d
+ * __check_lock_fn --
b30d9d
+ * Parse /proc/locks to see if the file described by 'fn' is locked.
b30d9d
+ * Additionally (if 'pid' is not 0) check if the process holding
b30d9d
+ * the lock has the same pid value as 'pid'.
b30d9d
+ *
b30d9d
+ * Returns 0 if a lock on fn is found, 1 if it is not found and -1 on error.
b30d9d
+ * PUBLIC: int __check_lock_fn __P((char *, pid_t));
b30d9d
+ */
b30d9d
+
b30d9d
+int __check_lock_fn(fn, pid)
b30d9d
+    char *fn;
b30d9d
+    pid_t pid;
b30d9d
+{
b30d9d
+    FILE* fp;
b30d9d
+    char buffer[PATH_MAX];
b30d9d
+    char *token;
b30d9d
+    int i, inode;
b30d9d
+    struct stat st;
b30d9d
+    pid_t lpid = 0;
b30d9d
+
b30d9d
+    if (!fn)
b30d9d
+       return -1;
b30d9d
+
b30d9d
+    fp = fopen("/proc/locks", "r");
b30d9d
+    if (!fp)
b30d9d
+        return -1;
b30d9d
+
b30d9d
+    /* Get the file's inode */
b30d9d
+    if (stat(fn, &st)) {
b30d9d
+        fclose(fp);
b30d9d
+        return -1;
b30d9d
+    }
b30d9d
+
b30d9d
+    while (fgets(buffer, sizeof(buffer), fp))
b30d9d
+        for (token = strtok(buffer, " "), i = 0; token; token = strtok(NULL, " "), i++) {
b30d9d
+            /* Do not parse any other fields */
b30d9d
+            if (i > 5)
b30d9d
+                break;
b30d9d
+            /* Save the PID */
b30d9d
+            if (i == 4)
b30d9d
+                lpid = atoi(token);
b30d9d
+            /* Check the inode */
b30d9d
+            else if (i == 5) {
b30d9d
+                inode = 0;
b30d9d
+                sscanf(token, "%*02x:%*02x:%d", &inode;;
b30d9d
+                /* Not the inode we are looking for */
b30d9d
+                if (inode != st.st_ino)
b30d9d
+                    continue;
b30d9d
+                /*
b30d9d
+                 * We have the correct file.
b30d9d
+                 * We are either looking for a specific process or we do not care at all.
b30d9d
+                 */
b30d9d
+                if (!pid || lpid == pid) {
b30d9d
+                    fclose(fp);
b30d9d
+                    return 0;
b30d9d
+                }
b30d9d
+                /* Not the lock we are looking for */
b30d9d
+            }
b30d9d
+        }
b30d9d
+    fclose(fp);
b30d9d
+    return 1;
b30d9d
+}
b30d9d
+
b30d9d
+/*
b30d9d
  * __os_fdlock --
b30d9d
  *	Acquire/release a lock on a byte in a file.
b30d9d
  *