为什么当我用 LD_PRELOAD 在 nginx 中捕获 open() 时不能很好地工作?

问题描述

我想用LD_PRELOAD来捕捉Nginxopen()调用来记录Nginx打开的文件,但是好像不行。 我搜索Nginx 的源代码,我认为它使用函数 open() 打开文件nginx source code use open()

我使用和其他人一样的方法来钩住 open() ,它在正常测试中运行良好,就像这样

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

int main() {
  int fd = open("config.c",O_RDWR);
  printf("%d\n",fd);
  char buf[100] = {0};
  ssize_t t = read(fd,buf,10);
  printf("buf:%s\n",buf);
  return 0;
}

但是当我以这种方式使用它时(使用 Nginx):

LD_PRELOAD=./myopen.so Nginx

它不会工作

谁能教我为什么它在 Nginx 中不起作用?我应该尝试什么?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)