]> git.wh0rd.org Git - tt-rss.git/commitdiff
pass logfile to child tasks if locking is possible, lock logfile before writing,...
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 2 Sep 2013 08:33:59 +0000 (12:33 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 2 Sep 2013 08:33:59 +0000 (12:33 +0400)
include/functions.php
include/rssfuncs.php
update_daemon2.php

index 2d6716b8160768f6b296caf760638d556a6e3736..8ede14a0bfa7a188b036d8ac704aff70dd7c22a9 100644 (file)
         * @return void
         */
        function _debug($msg, $show = true) {
+               if (defined('SUPPRESS_DEBUGGING'))
+                       return false;
 
                $ts = strftime("%H:%M:%S", time());
                if (function_exists('posix_getpid')) {
                        $fp = fopen(LOGFILE, 'a+');
 
                        if ($fp) {
+                               $locked = false;
+
+                               if (function_exists("flock")) {
+                                       $tries = 0;
+
+                                       // try to lock logfile for writing
+                                       while ($tries < 5 && !$locked = flock($fp, LOCK_EX | LOCK_NB)) {
+                                               sleep(1);
+                                               ++$tries;
+                                       }
+
+                                       if (!$locked) {
+                                               fclose($fp);
+                                               return;
+                                       }
+                               }
+
                                fputs($fp, "[$ts] $msg\n");
+
+                               if (function_exists("flock")) {
+                                       flock($fp, LOCK_UN);
+                               }
+
                                fclose($fp);
                        }
                }
index 2bc30b5ce0f2fdd6ec70f82d6a9f6c647e0adb80..7f6417759e1a8b7f310414f186d893618275c85e 100644 (file)
 
                $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
 
+               if (!$debug_enabled) define('SUPPRESS_DEBUGGING', true);
+
                _debug("start", $debug_enabled);
 
                $result = db_query("SELECT id,update_interval,auth_login,
index 9d948a64d3c5cdea2e19cea5e1fcfa8d9f04c5ae..e5bc55ee089474dd5696119b2f211c55b7275b5f 100755 (executable)
                                        register_shutdown_function('task_shutdown');
 
                                        $quiet = (isset($options["quiet"])) ? "--quiet" : "";
+                                       $log = function_exists("flock") && isset($options['log']) ? '--log '.$options['log'] : '';
 
                                        $my_pid = posix_getpid();
 
-                                       passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet --task $j --pidlock $my_pid");
+                                       passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
 
                                        sleep(1);