简体   繁体   English

功能与Linux和Java

[英]Capabilities & Linux & Java

I am experimenting with Linux capabilities for java application. 我正在试验Java应用程序的Linux功能。 I do not want to add capabilities to interpreter (JVM), so I tried to write a simple wrapper (with debugging information printed to stdout): 我不想为解释器(JVM)添加功能,所以我尝试编写一个简单的包装器(将调试信息打印到stdout):

#include <stdio.h>
#include <stdlib.h>
#include <sys/capability.h>
#include <unistd.h>

int main(int argc, char *argv[]){
        cap_t cap = cap_get_proc();

        if (!cap) {
                perror("cap_get_proc");
                exit(1);
        }
        printf("%s: running with caps %s\n", argv[0], cap_to_text(cap, NULL));

        return execlp("/usr/bin/java", "-server", "-jar", "project.jar", (char *)NULL);
}

This way, I can see that the capability is set for this executable: 这样,我可以看到为此可执行文件设置了功能:

./runner: running with caps = cap_net_bind_service+p

And getcap shows getcap节目

runner = cap_net_bind_service+ip

I have the capability set to be inheritable, so there should be no problem. 我有能力设置为可继承,所以应该没有问题。 However, java still doesn't want to bind to privileged ports. 但是,java仍然不想绑定到特权端口。

I am getting this error: 我收到此错误:

sun/nio/ch/Net.java:-2:in `bind': java.net.SocketException: Permission denied (NativeException)

Can someone help me to resolve this? 有人可以帮我解决这个问题吗?

尝试使用1024以上的端口,或以root身份运行。

Any update? 任何更新?

You may find some answers in the Apache Commons-Daemon jsvc project: "...set of libraries and applications for making Java applications run on UNIX more easily." 您可以在Apache Commons-Daemon jsvc项目中找到一些答案:“...用于使Java应用程序更容易在UNIX上运行的一组库和应用程序。”

They uses capabilities, even if they don't allow the user to select which one to apply, for portability reasons I suppose. 他们使用功能,即使他们不允许用户选择应用哪个功能,我认为这是出于可移植性的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM