MediaWiki REL1_35
CommandFactory.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Shell;
22
24use Psr\Log\LoggerAwareTrait;
25use Psr\Log\NullLogger;
26
33 use LoggerAwareTrait;
34
36 private $limits;
37
39 private $cgroup;
40
42 private $doLogStderr = false;
43
48
52 private $firejail;
53
59 public function __construct( array $limits, $cgroup, $restrictionMethod ) {
60 $this->limits = $limits;
61 $this->cgroup = $cgroup;
62 if ( $restrictionMethod === 'autodetect' ) {
63 // On Linux systems check for firejail
64 if ( PHP_OS === 'Linux' && $this->findFirejail() !== null ) {
65 $this->restrictionMethod = 'firejail';
66 } else {
67 $this->restrictionMethod = false;
68 }
69 } else {
70 $this->restrictionMethod = $restrictionMethod;
71 }
72 $this->setLogger( new NullLogger() );
73 }
74
75 protected function findFirejail(): ?string {
76 if ( $this->firejail === null ) {
77 // Convert a `false` from ExecutableFinder to `null` (T257282)
78 $this->firejail = ExecutableFinder::findInDefaultPaths( 'firejail' ) ?: null;
79 }
80
81 return $this->firejail;
82 }
83
90 public function logStderr( bool $yesno = true ): void {
91 $this->doLogStderr = $yesno;
92 }
93
99 public function create(): Command {
100 if ( $this->restrictionMethod === 'firejail' ) {
101 $command = new FirejailCommand( $this->findFirejail() );
102 $command->restrict( Shell::RESTRICT_DEFAULT );
103 } else {
104 $command = new Command();
105 }
106 $command->setLogger( $this->logger );
107
108 return $command
109 ->limits( $this->limits )
110 ->cgroup( $this->cgroup )
111 ->logStderr( $this->doLogStderr );
112 }
113}
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Definition Setup.php:85
Utility class to find executables in likely places.
static findInDefaultPaths( $names, $versionInfo=false)
Same as locateExecutable(), but checks in getPossibleBinPaths() by default.
Factory facilitating dependency injection for Command.
logStderr(bool $yesno=true)
When enabled, text sent to stderr will be logged with a level of 'error'.
__construct(array $limits, $cgroup, $restrictionMethod)
create()
Instantiates a new Command.
Class used for executing shell commands.
Definition Command.php:36
Restricts execution of shell commands using firejail.
$command
Definition mcc.php:125
Copyright (C) 2017 Kunal Mehta legoktm@member.fsf.org
Definition Command.php:21