[英]How to check is application running under OpenOnload?
我需要檢查我的應用程序是否通過在 OpenOnload 下運行來加速。 限制是不能使用 Onload 特定的 API - 應用程序未與 Onload 擴展庫鏈接。
如何做到這一點?
OpenOnload 可以通過預加載的共享庫存在libonload.so
來檢測。
在這種情況下,您的應用程序環境將包含LD_PRELOAD=libonload.so
字符串。
或者您可以枚舉所有加載的共享庫並檢查libonload.so
。
#include <string>
#include <fstream>
#include <iostream>
// Checks is specific SO loaded in current process.
bool is_so_loaded(const std::string& so_name)
{
const std::string proc_path = "/proc/self/maps";
std::ifstream proc(proc_path);
std::string str;
while (std::getline(proc, str))
{
if (str.find(so_name) != std::string::npos) return true;
}
return false;
}
int main()
{
std::cout
<< "Running with OpenOnload: "
<< (is_so_loaded("/libonload.so") ? "Yes" : "No")
<< std::endl;
return 0;
}
只需使用默認共享對象搜索順序搜索符號“onload_is_present”,如果預加載了 onload,它將返回一個有效地址。
bool IsOnloadPresent()
{
void* pIsOnloadPresent = dlsym(RTLD_DEFAULT, "onload_is_present");
if(pIsOnloadPresent == NULL)
return false;
return true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.