Use 'ps <pid>' to test for process existence if posix is not available
Summary: posix may not be loaded on the web/cgi SAPI but we call posix functions on this pathway, which we hit on /daemon/. Fall back to exec if we don't have posix. Test Plan: Added "&& false" and verified the page executed a bunch of "ps" tests. Reviewers: Koolvin, btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T821 Differential Revision: https://secure.phabricator.com/D1540
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright 2011 Facebook, Inc.
 | 
			
		||||
 * Copyright 2012 Facebook, Inc.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
@@ -63,15 +63,21 @@ final class PhabricatorDaemonReference {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 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;
 | 
			
		||||
    if (function_exists('posix_kill')) {
 | 
			
		||||
      // 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;
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      // If we don't have the posix extension, just exec.
 | 
			
		||||
      list($err) = exec_manual('ps %s', $pid);
 | 
			
		||||
      $is_running = ($err == 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return $is_running;
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
phutil_require_module('phutil', 'future/exec');
 | 
			
		||||
phutil_require_module('phutil', 'utils');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user