Reputation: 65
I am running into trouble with a java program, which attempts to write files to the /tmp
directory on Ubuntu 18.10. It runs into errors as it can not write the temporary file it expects. It fails for error 2: No such file or directory. The privileges on /tmp
are default.
I have read this is not a problem with Windows or Mac OS for the reason that it would not be restricted in this way.
How do I solve this? Should I configure my system differently (preferred) or alter the code?
Edit:
The file in question is actually created, permissions are
-rwxrwxr-x 1 lucas lucas 51263 Apr 26 11:12 monalisa13902330713449850714bin*
However, the the program cannot find it:
monalisa.tools.tinv.TInvariantCalculator$InvokeProcessException: java.io.IOException: Cannot run program "/tmp/monalisa13902330713449850714bin" (in directory "/tmp"): error=2, No such file or directory
The /tmp
directory is determined correctly by File(System.getProperty("java.io.tmpdir"));
The file is created here:
toolFile = FileUtils.extractResource("tinv_unix", "monalisa", "bin");
public static File extractResource(URL resource, String prefix,
String suffix) throws IOException {
LOGGER.debug("Extracting resource '" + resource.toString() + "'");
File file = File.createTempFile(prefix, suffix);
file.setExecutable(true, false);
Running exec /tmp/[file name]
returns the same error.
Edit: result of ´strace -e stat,execve -f bash -c /tmp/monalisa1846113800189529428bin´
`
execve("/bin/bash", ["bash", "-c", "/tmp/monalisa1846113800189529428"...], 0x7ffdb3fa2b68 /* 59 vars */) = 0
stat("/home/lucas", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/home/lucas", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/tmp/bin/bash", 0x7ffdd5b7b7d0) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/bash", 0x7ffdd5b7b7d0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/bash", 0x7ffdd5b7b7d0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/bash", 0x7ffdd5b7b7d0) = -1 ENOENT (No such file or directory)
stat("/usr/bin/bash", 0x7ffdd5b7b7d0) = -1 ENOENT (No such file or directory)
stat("/sbin/bash", 0x7ffdd5b7b7d0) = -1 ENOENT (No such file or directory)
stat("/bin/bash", {st_mode=S_IFREG|0755, st_size=1121696, ...}) = 0
stat("/bin/bash", {st_mode=S_IFREG|0755, st_size=1121696, ...}) = 0
stat("/bin/bash", {st_mode=S_IFREG|0755, st_size=1121696, ...}) = 0
stat("/bin/bash", {st_mode=S_IFREG|0755, st_size=1121696, ...}) = 0
stat("/bin/bash", {st_mode=S_IFREG|0755, st_size=1121696, ...}) = 0
stat("/bin/bash", {st_mode=S_IFREG|0755, st_size=1121696, ...}) = 0
execve("/tmp/monalisa1846113800189529428bin", ["/tmp/monalisa1846113800189529428"...], 0x55d86a4d0960 /* 59 vars */) = -1 ENOENT (No such file or directory)
stat("/tmp/monalisa1846113800189529428bin", {st_mode=S_IFREG|0744, st_size=51263, ...}) = 0
stat("/tmp/monalisa1846113800189529428bin", {st_mode=S_IFREG|0744, st_size=51263, ...}) = 0
stat("/tmp/monalisa1846113800189529428bin", {st_mode=S_IFREG|0744, st_size=51263, ...}) = 0
stat("/tmp/monalisa1846113800189529428bin", {st_mode=S_IFREG|0744, st_size=51263, ...}) = 0
bash: /tmp/monalisa1846113800189529428bin: No such file or directory
+++ exited with 127 +++`
Upvotes: 0
Views: 2828
Reputation: 1
a solution to run a java program with no execution right in /tmp is to redirect java to another folder with the option -Djava.io.tmpdir=[PATH_TO_FOLDER_YOU_CAN_EXECUTE]
Upvotes: 0
Reputation: 2375
I would bet that your /tmp directory is mounted as noexec - which means you're not able to execute any program there.
Possible solutions: write to somewhere else (user's home directory perhaps?) or remove noexec from /etc/fstab for /tmp and remount - but be sure you understand what that implies before you do so.
Upvotes: 3