[BUGFIX] flock() calls in TYPO3 prevent NFS hosting
authorDmitry Dulepov <dmitry@typo3.org>
Mon, 21 Nov 2011 14:13:28 +0000 (16:13 +0200)
committerSteffen Gebert <steffen.gebert@typo3.org>
Sat, 24 Dec 2011 12:15:15 +0000 (13:15 +0100)
flock() happens in several places in TYPO3. This function does
not work properly on NFS shares. t3lib_lock should be used
instead.

Change-Id: I30392bf06c5e20e27e929fb06d77ee9f96978902
Resolves: #31460
Releases: 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/6778
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
Reviewed-by: Xavier Perseguers
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
t3lib/class.t3lib_div.php
t3lib/mail/class.t3lib_mail_mboxtransport.php

index 66f45ff..925de8c 100644 (file)
@@ -5396,14 +5396,17 @@ final class t3lib_div {
 
                                // write message to a file
                        if ($type == 'file') {
+                               $lockObject = t3lib_div::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
+                               /** @var t3lib_lock $lockObject */
+                               $lockObject->setEnableLogging(FALSE);
+                               $lockObject->acquire();
                                $file = fopen($destination, 'a');
                                if ($file) {
-                                       flock($file, LOCK_EX); // try locking, but ignore if not available (eg. on NFS and FAT)
                                        fwrite($file, date($dateFormat . ' ' . $timeFormat) . $msgLine . LF);
-                                       flock($file, LOCK_UN); // release the lock
                                        fclose($file);
                                        self::fixPermissions($destination);
                                }
+                               $lockObject->release();
                        }
                                // send message per mail
                        elseif ($type == 'mail') {
@@ -5481,14 +5484,17 @@ final class t3lib_div {
                if (stripos($log, 'file') !== FALSE) {
                                // write a longer message to the deprecation log
                        $destination = self::getDeprecationLogFileName();
+                       $lockObject = t3lib_div::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
+                       /** @var t3lib_lock $lockObject */
+                       $lockObject->setEnableLogging(FALSE);
+                       $lockObject->acquire();
                        $file = @fopen($destination, 'a');
                        if ($file) {
-                               flock($file, LOCK_EX); // try locking, but ignore if not available (eg. on NFS and FAT)
                                @fwrite($file, $date . $msg . LF);
-                               flock($file, LOCK_UN); // release the lock
                                @fclose($file);
                                self::fixPermissions($destination);
                        }
+                       $lockObject->release();
                }
 
                if (stripos($log, 'devlog') !== FALSE) {
index f988a68..612fd1b 100644 (file)
@@ -89,22 +89,27 @@ class t3lib_mail_MboxTransport implements Swift_Transport {
                $messageStr .= $message->toString();
                $messageStr .= LF . LF;
 
+               $lockObject = t3lib_div::makeInstance('t3lib_lock', $this->debugFile, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
+               /** @var t3lib_lock $lockObject */
+               $lockObject->acquire();
+
                        // Write the mbox file
                $file = @fopen($this->debugFile, 'a');
                if (!$file) {
+                       $lockObject->release();
                        throw new RuntimeException(
                                sprintf('Could not write to file "%s" when sending an email to debug transport', $this->debugFile),
                                1291064151
                        );
                }
 
-               flock($file, LOCK_EX);
                @fwrite($file, $messageStr);
-               flock($file, LOCK_UN);
                @fclose($file);
 
                t3lib_div::fixPermissions($this->debugFile);
 
+               $lockObject->release();
+
                        // Return every receipient as "delivered"
                $count = (
                        count((array) $message->getTo())