helly           Thu Nov 14 09:32:39 2002 EDT

  Modified files:              
    /php4/ext/dba       dba.c php_dba.h 
    /php4/ext/dba/tests dba_cdb.phpt dba_db2.phpt dba_db3.phpt 
                        dba_dbm.phpt dba_flatfile.phpt dba_gdbm.phpt 
                        dba_handler.inc dba_ndbm.phpt 
  Log:
  Fix locking behaviour: On some systems read during write is permitted but
  most libraries are not capable of that. GDBM is system dependant so there
  we only test  that we do not deadlock.
  
  
Index: php4/ext/dba/dba.c
diff -u php4/ext/dba/dba.c:1.61 php4/ext/dba/dba.c:1.62
--- php4/ext/dba/dba.c:1.61     Mon Nov 11 15:53:41 2002
+++ php4/ext/dba/dba.c  Thu Nov 14 09:32:39 2002
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba.c,v 1.61 2002/11/11 20:53:41 helly Exp $ */
+/* $Id: dba.c,v 1.62 2002/11/14 14:32:39 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -302,6 +302,31 @@
 
 #define FREENOW if(args) efree(args); if(key) efree(key)
 
+/* {{{ php_find_dbm
+ */
+dba_info *php_dba_find(const char* path TSRMLS_DC)
+{
+       list_entry *le;
+       dba_info *info;
+       int numitems, i;
+
+       numitems = zend_hash_next_free_element(&EG(regular_list));
+       for (i=1; i<numitems; i++) {
+               if (zend_hash_index_find(&EG(regular_list), i, (void **) 
+&le)==FAILURE) {
+                       continue;
+               }
+               if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) {
+                       info = (dba_info *)(le->ptr);
+                       if (!strcmp(info->path, path)) {
+                               return (dba_info *)(le->ptr);
+                       }
+               }
+       }
+
+       return NULL;
+}
+/* }}} */
+
 /* {{{ php_dba_open
  */
 static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
@@ -309,7 +334,7 @@
        zval ***args = (zval ***) NULL;
        int ac = ZEND_NUM_ARGS();
        dba_mode_t modenr;
-       dba_info *info;
+       dba_info *info, *other;
        dba_handler *hptr;
        char *key = NULL, *error = NULL;
        int keylen = 0;
@@ -451,8 +476,24 @@
        info->mode = modenr;
        info->argc = ac - 3;
        info->argv = args + 3;
+       info->flags = (hptr->flags & ~DBA_LOCK_ALL) | (lock_flag & DBA_LOCK_ALL);
+       info->lock.mode = lock_mode;
+
+       /* if any open call is a locking call:
+        * check if we already habe a locking call open that should block this call
+        * the problem is some systems would allow read during write
+        */
+       if (hptr->flags & DBA_LOCK_ALL) {
+               if ((other = php_dba_find(info->path TSRMLS_CC)) != NULL) {
+                       if (   ( (lock_mode&LOCK_EX)        && 
+(other->lock.mode&(LOCK_EX|LOCK_SH)) )
+                           || ( (other->lock.mode&LOCK_EX) && 
+(lock_mode&(LOCK_EX|LOCK_SH))        )
+                          ) {
+                               error = "Unable to establish lock (database file 
+already open)"; /* force failure exit */
+                       }
+               }
+       }
 
-       if (lock_mode) {
+       if (!error && lock_mode) {
                if (lock_dbf) {
                        info->lock.name = estrdup(info->path);
                        lock_file_mode = file_mode;
Index: php4/ext/dba/php_dba.h
diff -u php4/ext/dba/php_dba.h:1.19 php4/ext/dba/php_dba.h:1.20
--- php4/ext/dba/php_dba.h:1.19 Sun Nov 10 12:58:46 2002
+++ php4/ext/dba/php_dba.h      Thu Nov 14 09:32:39 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_dba.h,v 1.19 2002/11/10 17:58:46 helly Exp $ */
+/* $Id: php_dba.h,v 1.20 2002/11/14 14:32:39 helly Exp $ */
 
 #ifndef PHP_DBA_H
 #define PHP_DBA_H
@@ -35,6 +35,7 @@
        php_stream *fp;
        int fd;
        char *name;
+       int mode; /* LOCK_EX,LOCK_SH */
 } dba_lock;
 
 typedef struct dba_info {
@@ -47,6 +48,7 @@
        int argc;
        zval ***argv;
        /* private */
+       int flags; /* whether and how dba did locking and other flags*/
        struct dba_handler *hnd;        
        dba_lock lock;
 } dba_info;
Index: php4/ext/dba/tests/dba_cdb.phpt
diff -u php4/ext/dba/tests/dba_cdb.phpt:1.4 php4/ext/dba/tests/dba_cdb.phpt:1.5
--- php4/ext/dba/tests/dba_cdb.phpt:1.4 Wed Nov  6 06:18:00 2002
+++ php4/ext/dba/tests/dba_cdb.phpt     Thu Nov 14 09:32:39 2002
@@ -17,7 +17,7 @@
 3NYNYY
 Content String 2
 Content 2 replaced
-Read during write permitted
+Read during write: not allowed
 Content 2 replaced 2nd time
 The 6th value
 array(3) {
Index: php4/ext/dba/tests/dba_db2.phpt
diff -u php4/ext/dba/tests/dba_db2.phpt:1.2 php4/ext/dba/tests/dba_db2.phpt:1.3
--- php4/ext/dba/tests/dba_db2.phpt:1.2 Wed Nov  6 06:18:00 2002
+++ php4/ext/dba/tests/dba_db2.phpt     Thu Nov 14 09:32:39 2002
@@ -16,7 +16,7 @@
 3NYNYY
 Content String 2
 Content 2 replaced
-Read during write permitted
+Read during write: not allowed
 Content 2 replaced 2nd time
 The 6th value
 array(3) {
Index: php4/ext/dba/tests/dba_db3.phpt
diff -u php4/ext/dba/tests/dba_db3.phpt:1.2 php4/ext/dba/tests/dba_db3.phpt:1.3
--- php4/ext/dba/tests/dba_db3.phpt:1.2 Wed Nov  6 06:18:00 2002
+++ php4/ext/dba/tests/dba_db3.phpt     Thu Nov 14 09:32:39 2002
@@ -16,7 +16,7 @@
 3NYNYY
 Content String 2
 Content 2 replaced
-Read during write permitted
+Read during write: not allowed
 Content 2 replaced 2nd time
 The 6th value
 array(3) {
Index: php4/ext/dba/tests/dba_dbm.phpt
diff -u php4/ext/dba/tests/dba_dbm.phpt:1.2 php4/ext/dba/tests/dba_dbm.phpt:1.3
--- php4/ext/dba/tests/dba_dbm.phpt:1.2 Wed Nov  6 06:18:00 2002
+++ php4/ext/dba/tests/dba_dbm.phpt     Thu Nov 14 09:32:39 2002
@@ -16,7 +16,7 @@
 3NYNYY
 Content String 2
 Content 2 replaced
-Read during write permitted
+Read during write: not allowed
 Content 2 replaced 2nd time
 The 6th value
 array(3) {
Index: php4/ext/dba/tests/dba_flatfile.phpt
diff -u php4/ext/dba/tests/dba_flatfile.phpt:1.2 
php4/ext/dba/tests/dba_flatfile.phpt:1.3
--- php4/ext/dba/tests/dba_flatfile.phpt:1.2    Wed Nov  6 06:18:00 2002
+++ php4/ext/dba/tests/dba_flatfile.phpt        Thu Nov 14 09:32:39 2002
@@ -16,7 +16,7 @@
 3NYNYY
 Content String 2
 Content 2 replaced
-Read during write permitted
+Read during write: not allowed
 Content 2 replaced 2nd time
 The 6th value
 array(3) {
Index: php4/ext/dba/tests/dba_gdbm.phpt
diff -u php4/ext/dba/tests/dba_gdbm.phpt:1.3 php4/ext/dba/tests/dba_gdbm.phpt:1.4
--- php4/ext/dba/tests/dba_gdbm.phpt:1.3        Sun Nov 10 17:56:29 2002
+++ php4/ext/dba/tests/dba_gdbm.phpt    Thu Nov 14 09:32:39 2002
@@ -11,13 +11,15 @@
        $handler = 'gdbm';
        $lock_flag = ''; // lock in library
        require_once('dba_handler.inc');
+       
+       // Read during write is system dependant. Important is that there is no 
+deadlock
 ?>
---EXPECT--
+--EXPECTF--
 database handler: gdbm
 3NYNYY
 Content String 2
 Content 2 replaced
-Read during write permitted
+Read during write:%sallowed
 Content 2 replaced 2nd time
 The 6th value
 array(3) {
Index: php4/ext/dba/tests/dba_handler.inc
diff -u php4/ext/dba/tests/dba_handler.inc:1.7 php4/ext/dba/tests/dba_handler.inc:1.8
--- php4/ext/dba/tests/dba_handler.inc:1.7      Mon Nov 11 07:00:58 2002
+++ php4/ext/dba/tests/dba_handler.inc  Thu Nov 14 09:32:39 2002
@@ -28,9 +28,9 @@
        }
        $db_writer = dba_open($db_filename, 'w'.$lock_flag, $handler);
        if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag ? 't' : 
''), $handler))===false) {
-               echo "Cannot read during write operation\n";
+               echo "Read during write: not allowed\n";
        } else {
-               echo "Read during write permitted\n";
+               echo "Read during write: allowed\n";
        }
        if ($db_writer!==FALSE) {
                dba_insert("key number 6", "The 6th value", $db_writer);
Index: php4/ext/dba/tests/dba_ndbm.phpt
diff -u php4/ext/dba/tests/dba_ndbm.phpt:1.2 php4/ext/dba/tests/dba_ndbm.phpt:1.3
--- php4/ext/dba/tests/dba_ndbm.phpt:1.2        Wed Nov  6 06:18:00 2002
+++ php4/ext/dba/tests/dba_ndbm.phpt    Thu Nov 14 09:32:39 2002
@@ -16,7 +16,7 @@
 3NYNYY
 Content String 2
 Content 2 replaced
-Read during write permitted
+Read during write: not allowed
 Content 2 replaced 2nd time
 The 6th value
 array(3) {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to