Skip to content

Commit

Permalink
Improved Synchronisation
Browse files Browse the repository at this point in the history
* Added configuration option to switch between timeout utils
* Modified user option to require value
  • Loading branch information
mettke authored and thomas-pike committed May 4, 2019
1 parent 2ed9c67 commit 8b67238
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions config/config-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ logo = /logo-header-opera.png
; " < $gt;
footer = 'Developed by <a href="https://www.opera.com/">Opera Software</a>.'

[general]
; Use timeout --version to find out the current version
; used on e.g. debian
timeout_util = GNU coreutils
; used on e.g. alpine
; timeout_util = BusyBox

[security]
; It is important that SKA is able to verify that it has connected to the
; server that it expected to connect to (otherwise it could be tricked into
Expand Down
11 changes: 10 additions & 1 deletion scripts/sync-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class SyncProcess {
* @param Request $request object that triggered this sync
*/
public function __construct($command, $args, $request = null) {
global $config;
$timeout_util = $config['general']['timeout_util'];

$this->request = $request;
$this->output = '';
$descriptorspec = array(
Expand All @@ -40,7 +43,13 @@ public function __construct($command, $args, $request = null) {
2 => array("pipe", "w"), // stderr
3 => array("pipe", "w") //
);
$commandline = '/usr/bin/timeout 60s '.$command.' '.implode(' ', array_map('escapeshellarg', $args));
switch ($timeout_util) {
case "BusyBox":
$commandline = '/usr/bin/timeout -t 60 '.$command.' '.implode(' ', array_map('escapeshellarg', $args));
break;
default:
$commandline = '/usr/bin/timeout 60s '.$command.' '.implode(' ', array_map('escapeshellarg', $args));
}

$this->handle = proc_open($commandline, $descriptorspec, $this->pipes);
stream_set_blocking($this->pipes[1], 0);
Expand Down

0 comments on commit 8b67238

Please sign in to comment.