patch for the fam extension

From: Date: Tue, 31 May 2005 21:08:17 +0000
Subject: patch for the fam extension
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2404@lists.php.net to get a copy of this message
I'm using the fam extension for a pet project. I noticed that when monitoring multiple files/directories, there is no way to tell which directory the file being reported about is in. libfam itself doesn't return it in the FAMEvent structure. I looked around for how other users deal with this issue, and it seems that most of them use the userdata parameter to return the directory. The following patch is the beginnings of an attempt to put the directory in the userdata member of the FAMEvent structure, and return it to php userspace in the 'directory' element when the user calls fam_next_event(). I think it would probably leak memory. The dirname is freed immediately if I do not do estrndup(), but if I estrndup, then the memory isn't freed until the script ends. The only way I can think of to deal with this is to modify the fam requests resource to hold the directory name as well as the FAMMonitor struct. Then when the resource is destroyed, I can free the memory. I wanted to get some input before I put any more work into this as to whether or not this was the right way to go, and if there was any chance any of this would be accepted. Thanks, John LeSueur diff -U4 -r fam-orig/fam.c fam/fam.c
--- php-5.0.4/ext/fam/fam.c     2005-02-08 05:38:04.000000000 +0000
+++ ../php-5.0.4/ext/fam/fam.c 2005-05-31 20:21:08.000000000 +0000 @@ -199,10 +199,10 @@
       ZEND_FETCH_RESOURCE(fc, FAMConnection *, &id, -1, "fam", le_fam);
       ZEND_VERIFY_RESOURCE(fc);
       fr = emalloc(sizeof *fr);
-
-       if (FAMMonitorDirectory(fc, dirname, fr, NULL) < 0) {
+       dirname = estrndup(dirname, dirname_len);
+       if (FAMMonitorDirectory(fc, dirname, fr, dirname) < 0) {
               efree(fr);
               RETURN_FALSE;
       }
@@ -386,8 +386,9 @@
       array_init(return_value);
       if (fe.hostname)
               add_assoc_string(return_value, "hostname", fe.hostname, 1);
+       add_assoc_string(return_value, "directory", fe.userdata, 1);
       add_assoc_string(return_value, "filename", fe.filename, 1);
       add_assoc_long(return_value, "code", fe.code);
} /* }}} */

« previous php.pecl.dev (#2404) next »