Java程序无法执行它写入/ tmp的文件,没有此类文件或目录

时间:2019-04-29 08:05:36

标签: java linux ubuntu

我在使用Java程序时遇到麻烦,该Java程序试图将文件写入Ubuntu 18.10上的/tmp目录。由于无法写入期望的临时文件,因此发生错误。错误2失败:没有这样的文件或目录。 /tmp上的特权是默认的。

我已阅读到Windows或Mac OS上没有此问题,因为它不会受到这种方式的限制。

我该如何解决?我应该以其他方式(首选)配置系统还是更改代码?

编辑:

该文件已实际创建,权限为 -rwxrwxr-x 1 lucas lucas 51263 Apr 26 11:12 monalisa13902330713449850714bin*

但是,程序找不到它:

monalisa.tools.tinv.TInvariantCalculator$InvokeProcessException: java.io.IOException: Cannot run program "/tmp/monalisa13902330713449850714bin" (in directory "/tmp"): error=2, No such file or directory

/tmp正确确定了File(System.getProperty("java.io.tmpdir"));目录

在此处创建文件:

    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);

运行exec /tmp/[file name]会返回相同的错误。

编辑:“ 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 +++`

1 个答案:

答案 0 :(得分:2)

我敢打赌,您的/ tmp目录被挂载为noexec-这意味着您无法在其中执行任何程序。

可能的解决方案:写到其他地方(也许是用户的主目录?)或从/ etc / fstab中删除noexec以便/ tmp并重新挂载-但在执行此操作之前,请务必先了解其含义。