From bdc059028aecf2f2887971edf23754819f29c345 Mon Sep 17 00:00:00 2001 From: jygaulier Date: Wed, 26 Sep 2012 15:27:14 +0200 Subject: [PATCH 1/4] fix issue 895 (scheduler creates zombies) fix bug in windows : tasks did not start cleanup --- lib/classes/module/console/taskrun.class.php | 2 +- lib/classes/task/Scheduler.class.php | 5 +++++ lib/classes/task/abstract.class.php | 2 +- lib/classes/task/manager.class.php | 12 ++++++------ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/classes/module/console/taskrun.class.php b/lib/classes/module/console/taskrun.class.php index b52d1c8093..8554042bc9 100644 --- a/lib/classes/module/console/taskrun.class.php +++ b/lib/classes/module/console/taskrun.class.php @@ -145,7 +145,7 @@ class module_console_taskrun extends Command if (time() - $start > 0) { if ($this->shedulerPID) { - if ( ! posix_kill($this->shedulerPID, 0)) { + if (function_exists('posix_kill') && !posix_kill($this->shedulerPID, 0)) { if (method_exists($this->task, 'signal')) { $this->task->signal('SIGNAL_SCHEDULER_DIED'); } else { diff --git a/lib/classes/task/Scheduler.class.php b/lib/classes/task/Scheduler.class.php index 8df09ae8be..e3da9688b2 100755 --- a/lib/classes/task/Scheduler.class.php +++ b/lib/classes/task/Scheduler.class.php @@ -54,6 +54,11 @@ class task_Scheduler */ public function run() { + if (function_exists('pcntl_signal')) { + // avoid php when a task ends + pcntl_signal(SIGCHLD, SIG_IGN); + } + $appbox = appbox::get_instance(\bootstrap::getCore()); $registry = $appbox->get_registry(); diff --git a/lib/classes/task/abstract.class.php b/lib/classes/task/abstract.class.php index be7d16beae..794ecb97c3 100755 --- a/lib/classes/task/abstract.class.php +++ b/lib/classes/task/abstract.class.php @@ -321,7 +321,7 @@ abstract class task_abstract abstract public function help(); - public function __construct($taskid, Logger $logger) + public function __construct($taskid, Logger $logger = NULL) { $this->logger = $logger; diff --git a/lib/classes/task/manager.class.php b/lib/classes/task/manager.class.php index 6f4d7e4505..0202bbfd16 100755 --- a/lib/classes/task/manager.class.php +++ b/lib/classes/task/manager.class.php @@ -41,9 +41,9 @@ class task_manager $core = \bootstrap::getCore(); - if ( ! $logger) { - $logger = $core['monolog']; - } +// if ( ! $logger) { +// $logger = $core['monolog']; +// } $sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC"; $stmt = $this->appbox->get_connection()->prepare($sql); @@ -81,9 +81,9 @@ class task_manager { $core = \bootstrap::getCore(); - if ( ! $logger) { - $logger = $core['monolog']; - } +// if ( ! $logger) { +// $logger = $core['monolog']; +// } $tasks = $this->getTasks(false, $logger); From a078aac6da4ae03718732cddaaa68b5ec60993fc Mon Sep 17 00:00:00 2001 From: jygaulier Date: Wed, 26 Sep 2012 17:04:02 +0200 Subject: [PATCH 2/4] security fix fix bug : indexer did not start --- lib/classes/task/period/cindexer.class.php | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/classes/task/period/cindexer.class.php b/lib/classes/task/period/cindexer.class.php index f6ea98a7de..3726b3f0ff 100755 --- a/lib/classes/task/period/cindexer.class.php +++ b/lib/classes/task/period/cindexer.class.php @@ -222,13 +222,12 @@ class task_period_cindexer extends task_abstract if(user.value) cmd += " -u=" + user.value; if(password.value) - cmd += " -p=" + password.value; + cmd += " -p=xxxxxx"; // + password.value; if(socket.value) cmd += " --socket=" + socket.value; if(charset.value) cmd += " --default-character-set=" + charset.value; - if(use_sbas.checked) - cmd += " -o"; + cmd += " -o"; if(nolog.checked) cmd += " -n"; if(clng.value) @@ -395,16 +394,14 @@ class task_period_cindexer extends task_abstract } if ($this->password) { $args[] = '-p=' . $this->password; - $args_nopwd[] = '-p=******'; + $args_nopwd[] = '-p=xxxxxxx'; } if ($this->socket) { $args[] = '--socket=' . $this->socket; $args_nopwd[] = '--socket=' . $this->socket; } - if ($this->use_sbas) { - $args[] = '-o'; - $args_nopwd[] = '-o'; - } + $args[] = '-o'; + $args_nopwd[] = '-o'; if ($this->charset) { $args[] = '--default-character-set=' . $this->charset; $args_nopwd[] = '--default-character-set=' . $this->charset; @@ -460,9 +457,20 @@ class task_period_cindexer extends task_abstract $pipes = array(); - $this->log(sprintf('cmd=\'%s %s\'', $cmd, implode(' ', $args_nopwd))); + $logcmd = $cmd; + foreach ($args_nopwd as $arg) + { + $logcmd .= ' ' . escapeshellarg($arg); + } - $process = proc_open($cmd . ' ' . implode(' ', $args), $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true)); + $this->log(sprintf('cmd=\'%s\'', escapeshellcmd($logcmd) )); + + $execmd = $cmd; + foreach ($args as $arg) + { + $execmd .= ' ' . escapeshellarg($arg); + } + $process = proc_open(escapeshellcmd($execmd), $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true)); $pid = NULL; if (is_resource($process)) { From 7e2d522c7757008ed2483ae0eda688a97f48baac Mon Sep 17 00:00:00 2001 From: jygaulier Date: Wed, 26 Sep 2012 17:14:14 +0200 Subject: [PATCH 3/4] CS --- lib/classes/task/period/cindexer.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/classes/task/period/cindexer.class.php b/lib/classes/task/period/cindexer.class.php index 3726b3f0ff..2a4d13f512 100755 --- a/lib/classes/task/period/cindexer.class.php +++ b/lib/classes/task/period/cindexer.class.php @@ -187,7 +187,6 @@ class task_period_cindexer extends task_abstract parent.calccmd(); cmd log(sprintf('cmd=\'%s\'', escapeshellcmd($logcmd) )); + $this->log(sprintf('cmd=\'%s\'', escapeshellcmd($logcmd))); $execmd = $cmd; - foreach ($args as $arg) - { + foreach ($args as $arg) { $execmd .= ' ' . escapeshellarg($arg); } $process = proc_open(escapeshellcmd($execmd), $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true)); From 9476fb6b5193b2b62de274ba3cc620b725934703 Mon Sep 17 00:00:00 2001 From: jygaulier Date: Wed, 26 Sep 2012 17:52:07 +0200 Subject: [PATCH 4/4] reverts --- lib/classes/task/Scheduler.class.php | 7 +++---- lib/classes/task/abstract.class.php | 2 +- lib/classes/task/manager.class.php | 12 ++++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/classes/task/Scheduler.class.php b/lib/classes/task/Scheduler.class.php index e3da9688b2..9cfce19a53 100755 --- a/lib/classes/task/Scheduler.class.php +++ b/lib/classes/task/Scheduler.class.php @@ -54,10 +54,6 @@ class task_Scheduler */ public function run() { - if (function_exists('pcntl_signal')) { - // avoid php when a task ends - pcntl_signal(SIGCHLD, SIG_IGN); - } $appbox = appbox::get_instance(\bootstrap::getCore()); $registry = $appbox->get_registry(); @@ -76,6 +72,9 @@ class task_Scheduler } if (function_exists('pcntl_fork')) { + // avoid php when a task ends + pcntl_signal(SIGCHLD, SIG_IGN); + $this->method = self::METHOD_FORK; } diff --git a/lib/classes/task/abstract.class.php b/lib/classes/task/abstract.class.php index 794ecb97c3..be7d16beae 100755 --- a/lib/classes/task/abstract.class.php +++ b/lib/classes/task/abstract.class.php @@ -321,7 +321,7 @@ abstract class task_abstract abstract public function help(); - public function __construct($taskid, Logger $logger = NULL) + public function __construct($taskid, Logger $logger) { $this->logger = $logger; diff --git a/lib/classes/task/manager.class.php b/lib/classes/task/manager.class.php index 0202bbfd16..6f4d7e4505 100755 --- a/lib/classes/task/manager.class.php +++ b/lib/classes/task/manager.class.php @@ -41,9 +41,9 @@ class task_manager $core = \bootstrap::getCore(); -// if ( ! $logger) { -// $logger = $core['monolog']; -// } + if ( ! $logger) { + $logger = $core['monolog']; + } $sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC"; $stmt = $this->appbox->get_connection()->prepare($sql); @@ -81,9 +81,9 @@ class task_manager { $core = \bootstrap::getCore(); -// if ( ! $logger) { -// $logger = $core['monolog']; -// } + if ( ! $logger) { + $logger = $core['monolog']; + } $tasks = $this->getTasks(false, $logger);