我正在开发一个项目,该项目需要将基于 Rust 的插件(共享对象)任意加载/卸载到隔离的动态库命名空间中。
我用来dlmopen(LM_ID_NEWLM, "rust-plugin.so", RTLD_LAZY)为共享对象创建一个新的命名空间。当不再需要共享对象时,我调用dlclose().
不幸的是,我发现即使我dlclose()一次只有一个共享对象有效,在使用dlmopen()14 个 Rust 插件对象后,我也会收到错误消息:
dlmopen(rust-plugin.so) failed: /lib/x86_64-linux-gnu/libc.so.6: cannot allocate memory in static TLS block
Run Code Online (Sandbox Code Playgroud)
dlmopen()在此失败后继续尝试导致分段错误和no more namespaces available for dlmopen().
我似乎已将问题与libpthread.soRust 共享对象的依赖关系隔离。其他共享对象依赖项libgcc_s.so.1(以及我尝试过的任何 .so 文件,就此而言)可以通过以下代码无限期地打开和关闭,而libpthread.so在我打开和关闭它 14 次后会出现错误。
#include <link.h>
#include <stdio.h>
#include <dlfcn.h>
#include <cstdlib>
void load(char const *file) {
void *handle_ = dlmopen(LM_ID_NEWLM, file, RTLD_LAZY);
if (!handle_) {
printf("dlmopen(%s) failed: %s\n", file, dlerror());
exit(1);
}
if (dlclose(handle_) …Run Code Online (Sandbox Code Playgroud) 我希望我的微服务在一个新的命令行中打开,并从那里一个接一个地运行它。下面是我的 bash 脚本
################ first SERVER #####################
gnome-terminal -x sh -c 'java -jar server/target/first-server.jar; exec bash'
################ second SERVER #####################
export service_port=8771
export host_name=firstdomain
gnome-terminal -x sh -c 'java -Dservice.port="${service_port}" -Dhost.name="${host_name}" -jar eureka/target/second-server.jar; exec bash'
Run Code Online (Sandbox Code Playgroud)
问题是我想在成功启动“first-server.jar”后启动“second-server.jar”。我可以通过检查服务是否正在侦听网络端口来检测这一点。有什么办法可以存档这个吗?sleep bash 命令不适合我。
我想要实现的是在工作区目录中的groovy中创建一个临时文件,但是作为一个例子/tmp/foo就足够了。
因此,这是完美运行的Java代码:
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
class foo {
public static void main(String[] args) {
try {
String s="/tmp/foo";
Path p=Paths.get(s);
Path tmp=Files.createTempFile(p,"pref",".suf");
System.out.println(tmp.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当在詹金斯管道中使用时,它根本不起作用:
def mktemp() {
//String s=pwd(tmp:true)
String s="/tmp/foo"
Path p=Paths.get(s)
Path tmp=Files.createTempFile(p,"pref",".suf")
return tmp;
}
Run Code Online (Sandbox Code Playgroud)
结果是数组元素类型不匹配消息,在管道日志中没有任何帮助:
java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.parametersForVarargs(GroovyCallSiteSelector.java:104)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.matches(GroovyCallSiteSelector.java:51)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.findMatchingMethod(GroovyCallSiteSelector.java:197)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.staticMethod(GroovyCallSiteSelector.java:191)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onStaticCall(SandboxInterceptor.java:153)
at org.kohsuke.groovy.sandbox.impl.Checker$2.call(Checker.java:184)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedStaticCall(Checker.java:188)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:95)
at …Run Code Online (Sandbox Code Playgroud)