Skip to content

Commit

Permalink
do not use hard coded path /tmp (fixes #132)
Browse files Browse the repository at this point in the history
  • Loading branch information
timar committed May 20, 2021
1 parent b3b390f commit d301d2e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ function errorExit($msg)
// Where the appimage is installed
$appImage = __DIR__ . '/collabora/Collabora_Online.AppImage';

$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
$lockfile = "$tmp_dir/loolwsd.lock";
$pidfile = "$tmp_dir/loolwsd.pid";

function getLoolwsdPid()
{
$pidfile = '/tmp/loolwsd.pid';
global $pidfile;

clearstatcache();
if (file_exists($pidfile))
{
Expand All @@ -70,22 +75,24 @@ function isLoolwsdRunning()
function startLoolwsd()
{
global $appImage;
global $pidfile;
global $lockfile;

// Extract the AppImage if FUSE is not available
$launchCmd = "bash -c \"( $appImage || $appImage --appimage-extract-and-run ) >/dev/null & disown\"";
$launchCmd = "bash -c \"( $appImage --pidfile=$pidfile || $appImage --appimage-extract-and-run --pidfile=$pidfile) >/dev/null & disown\"";

// Remove stale lock file (just in case)
if (file_exists('/tmp/loolwsd.lock'))
if (time() - filectime('/tmp/loolwsd.lock') > 60 * 5)
unlink('/tmp/loolwsd.lock');
if (file_exists("$lockfile"))
if (time() - filectime("$lockfile") > 60 * 5)
unlink("$lockfile");

// Prevent second start
$lock = @fopen("/tmp/loolwsd.lock", "x");
$lock = @fopen("$lockfile", "x");
if ($lock)
{
// We start a new server, we don't need stale pidfile around
if (file_exists('/tmp/loolwsd.pid'))
unlink('/tmp/loolwsd.pid');
if (file_exists("$pidfile"))
unlink("$pidfile");

debug_log("Launch the loolwsd server: $launchCmd");
exec($launchCmd, $output, $return);
Expand All @@ -98,8 +105,8 @@ function startLoolwsd()
while (!isLoolwsdRunning())
sleep(1);

if (file_exists('/tmp/loolwsd.lock'))
unlink('/tmp/loolwsd.lock');
if (file_exists("$lockfile"))
unlink("$lockfile");
}

function stopLoolwsd()
Expand Down

0 comments on commit d301d2e

Please sign in to comment.