Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php b/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php
index 1a4481ab48..3f9abb8cdd 100644
--- a/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php
+++ b/src/applications/daemon/view/daemonloglist/PhabricatorDaemonLogListView.php
@@ -1,123 +1,117 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorDaemonLogListView extends AphrontView {
private $daemonLogs;
private $user;
public function setDaemonLogs(array $daemon_logs) {
$this->daemonLogs = $daemon_logs;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
$rows = array();
if (!$this->user) {
throw new Exception("Call setUser() before rendering!");
}
foreach ($this->daemonLogs as $log) {
$epoch = $log->getDateCreated();
if ($log->getHost() == php_uname('n')) {
- // This will probably fail since apache can't signal the process, but
- // we can check the error code to figure out if the process exists.
- $is_running = posix_kill($log->getPID(), 0);
- if (posix_get_last_error() == 1) {
- // "Operation Not Permitted", indicates that the PID exists. If it
- // doesn't, we'll get an error 3 ("No such process") instead.
- $is_running = true;
- }
+ $pid = $log->getPID();
+ $is_running = PhabricatorDaemonReference::isProcessRunning($pid);
if ($is_running) {
$running = phutil_render_tag(
'span',
array(
'style' => 'color: #00cc00',
'title' => 'Running',
),
'&bull;');
} else {
$running = phutil_render_tag(
'span',
array(
'style' => 'color: #cc0000',
'title' => 'Not running',
),
'&bull;');
}
} else {
$running = phutil_render_tag(
'span',
array(
'style' => 'color: #888888',
'title' => 'Not on this host',
),
'?');
}
$rows[] = array(
$running,
phutil_escape_html($log->getDaemon()),
phutil_escape_html($log->getHost()),
$log->getPID(),
phabricator_date($epoch, $this->user),
phabricator_time($epoch, $this->user),
phutil_render_tag(
'a',
array(
'href' => '/daemon/log/'.$log->getID().'/',
'class' => 'button small grey',
),
'View Log'),
);
}
$daemon_table = new AphrontTableView($rows);
$daemon_table->setHeaders(
array(
'',
'Daemon',
'Host',
'PID',
'Date',
'Time',
'View',
));
$daemon_table->setColumnClasses(
array(
'',
'wide wrap',
'',
'',
'',
'right',
'action',
));
return $daemon_table->render();
}
}
diff --git a/src/applications/daemon/view/daemonloglist/__init__.php b/src/applications/daemon/view/daemonloglist/__init__.php
index 0cb14d1492..c476f15cd3 100644
--- a/src/applications/daemon/view/daemonloglist/__init__.php
+++ b/src/applications/daemon/view/daemonloglist/__init__.php
@@ -1,16 +1,17 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
+phutil_require_module('phabricator', 'infrastructure/daemon/control/reference');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_source('PhabricatorDaemonLogListView.php');
diff --git a/src/infrastructure/daemon/control/reference/PhabricatorDaemonReference.php b/src/infrastructure/daemon/control/reference/PhabricatorDaemonReference.php
index ba6b948c50..fc801ccccd 100644
--- a/src/infrastructure/daemon/control/reference/PhabricatorDaemonReference.php
+++ b/src/infrastructure/daemon/control/reference/PhabricatorDaemonReference.php
@@ -1,76 +1,91 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorDaemonReference {
private $name;
private $pid;
private $start;
private $pidFile;
public static function newFromDictionary(array $dict) {
$ref = new PhabricatorDaemonReference();
$ref->name = idx($dict, 'name', 'Unknown');
$ref->pid = idx($dict, 'pid');
$ref->start = idx($dict, 'start');
return $ref;
}
public function getPID() {
return $this->pid;
}
public function getName() {
return $this->name;
}
public function getEpochStarted() {
return $this->start;
}
public function setPIDFile($pid_file) {
$this->pidFile = $pid_file;
return $this;
}
public function getPIDFile() {
return $this->pidFile;
}
public function isRunning() {
- $pid = $this->getPID();
+ return self::isProcessRunning($this->getPID());
+ }
+
+ public static function isProcessRunning($pid) {
if (!$pid) {
return false;
}
- return posix_kill($pid, 0);
+
+ // This may fail if we can't signal the process because we are running as
+ // a different user (for example, we are 'apache' and the process is some
+ // other user's, or we are a normal user and the process is root's), but
+ // we can check the error code to figure out if the process exists.
+ $is_running = posix_kill($pid, 0);
+ if (posix_get_last_error() == 1) {
+ // "Operation Not Permitted", indicates that the PID exists. If it
+ // doesn't, we'll get an error 3 ("No such process") instead.
+ $is_running = true;
+ }
+
+ return $is_running;
}
public function waitForExit($seconds) {
$start = time();
while (time() < $start + $seconds) {
usleep(100000);
if (!$this->isRunning()) {
return true;
}
}
return !$this->isRunning();
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jul 27, 9:38 PM (1 w, 13 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
186234
Default Alt Text
(7 KB)

Event Timeline