[英]Java program can't execute file it writes to /tmp, no such file or directory
I am running into trouble with a java program, which attempts to write files to the /tmp
directory on Ubuntu 18.10. 我在使用Java程序时遇到麻烦,该Java程序试图将文件写入Ubuntu 18.10上的
/tmp
目录。 It runs into errors as it can not write the temporary file it expects. 由于无法写入期望的临时文件,因此发生错误。 It fails for error 2: No such file or directory.
错误2失败:没有这样的文件或目录。 The privileges on
/tmp
are default. /tmp
上的特权是默认的。
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. 我已经读到这不是Windows或Mac OS的问题,因为它不会以这种方式受到限制。
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*
有问题的文件实际上是创建的,权限为
-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"));
/tmp
目录由File(System.getProperty("java.io.tmpdir"));
正确确定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. 运行
exec /tmp/[file name]
返回相同的错误。
Edit: result of ´strace -e stat,execve -f bash -c /tmp/monalisa1846113800189529428bin´ 编辑:“ 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 +++`
I would bet that your /tmp directory is mounted as noexec - which means you're not able to execute any program there. 我敢打赌,您的/ tmp目录挂载为noexec-这意味着您无法在此处执行任何程序。
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. 可能的解决方案:写入其他位置(也许是用户的主目录?),或从/ etc / fstab中删除noexec以进行/ tmp并重新挂载-但在执行此操作之前,请确保您了解其含义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.