Skip to content

Commit 57f8bbe

Browse files
Document and fail fast if tmp directory is noexec
1 parent a23befc commit 57f8bbe

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ If using features that rely on OpenCV (see the [Downsampling type](#downsampling
3333

3434
__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.
3535

36+
If the default temporary directory (usually `/tmp/`) is mounted as `noexec`, conversion will fail.
37+
The easiest solution is to choose a different temporary directory by adding `-Djava.io.tmpdir=/path/to/alternate/tmp` to `JAVA_OPTS`.
38+
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`.
39+
3640
Installation
3741
============
3842

src/main/java/com/glencoesoftware/bioformats2raw/Converter.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,25 @@ public Integer call() throws Exception {
11721172
tileWidth, tileHeight);
11731173
}
11741174

1175+
// if the tmpdir is mounted as noexec, then any native library
1176+
// loading (OpenCV, turbojpeg, etc.) is expected to fail, which
1177+
// can cause conversion to fail with an exception that is not user friendly
1178+
//
1179+
// try to detect this case early and fail before the conversion begins,
1180+
// with a more informative message
1181+
1182+
// a temp file is created and set as executable
1183+
// in the noexec case, setting as executable is expected to silently fail
1184+
File tmpdirCheck = File.createTempFile("noexec-test", ".txt");
1185+
// expect 'success' to be true in the noexec case, even though
1186+
// the file will not actually be executable
1187+
boolean success = tmpdirCheck.setExecutable(true);
1188+
tmpdirCheck.deleteOnExit();
1189+
if (!success || !tmpdirCheck.canExecute()) {
1190+
throw new RuntimeException(System.getProperty("java.io.tmpdir") +
1191+
" is noexec; fix it or specify a different java.io.tmpdir");
1192+
}
1193+
11751194
OpenCVTools.loadOpenCV();
11761195

11771196
if (progressBars) {

0 commit comments

Comments
 (0)