Skip to content

Commit

Permalink
fix(linux): use $XDG_RUNTIME_DIR on GNU/Linux
Browse files Browse the repository at this point in the history
Some systems mount `/tmp` with `noexec`, causing `spawn EACCES` errors.

See: balena-io/etcher#1699
See: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html
Change-Type: patch
Changelog-Entry: Store GNU/Linux temporary scripts in `$XDG_RUNTIME_DIR`.
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Aug 28, 2017
1 parent 6e5cfcb commit 9ad6e99
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ const path = require('path');
const os = require('os');
const crypto = require('crypto');

/**
* @summary A temporary directory to store scripts
* @type {String}
* @constant
*
* @description
* Some users mount their system temporary directory with the `noexec`
* option, which means we can't execute the files we put there.
*
* As a workaround, we try to use XDG_RUNTIME_DIR, which is probably
* a better bet.
*/
const TMP_DIRECTORY = process.env.XDG_RUNTIME_DIR || os.tmpdir();

/**
* @summary Generate a tmp filename with full path of OS' tmp dir
* @function
Expand All @@ -38,7 +52,7 @@ const crypto = require('crypto');
const tmpFilename = (extension) => {
const random = crypto.randomBytes(6).toString('hex');
const filename = `${packageInfo.name}-${random}${extension}`;
return path.join(os.tmpdir(), filename);
return path.join(TMP_DIRECTORY, filename);
};

/**
Expand Down

0 comments on commit 9ad6e99

Please sign in to comment.