Skip to content

Commit

Permalink
Document and fail fast if tmp directory is noexec
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Jun 3, 2024
1 parent a23befc commit 57f8bbe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ If using features that rely on OpenCV (see the [Downsampling type](#downsampling

__NOTE:__ If you are setting `jna.library.path` via the `JAVA_OPTS` environment variable, make sure the path is to the folder __containing__ the library not path to the library itself.

If the default temporary directory (usually `/tmp/`) is mounted as `noexec`, conversion will fail.
The easiest solution is to choose a different temporary directory by adding `-Djava.io.tmpdir=/path/to/alternate/tmp` to `JAVA_OPTS`.
If multiple properties need to be set via `JAVA_OPTS`, separate them with a space, e.g. `JAVA_OPTS=-Djava.io.tmpdir/path/to/alternate/tmp -Djna.library.path=/path/to/blosc`.

Installation
============

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,25 @@ public Integer call() throws Exception {
tileWidth, tileHeight);
}

// if the tmpdir is mounted as noexec, then any native library
// loading (OpenCV, turbojpeg, etc.) is expected to fail, which
// can cause conversion to fail with an exception that is not user friendly
//
// try to detect this case early and fail before the conversion begins,
// with a more informative message

// a temp file is created and set as executable
// in the noexec case, setting as executable is expected to silently fail
File tmpdirCheck = File.createTempFile("noexec-test", ".txt");
// expect 'success' to be true in the noexec case, even though
// the file will not actually be executable
boolean success = tmpdirCheck.setExecutable(true);
tmpdirCheck.deleteOnExit();
if (!success || !tmpdirCheck.canExecute()) {
throw new RuntimeException(System.getProperty("java.io.tmpdir") +
" is noexec; fix it or specify a different java.io.tmpdir");
}

OpenCVTools.loadOpenCV();

if (progressBars) {
Expand Down

0 comments on commit 57f8bbe

Please sign in to comment.