LD_PRELOAD哪个程序是目标

时间:2022-09-06 21:37:15

Is there a way to figure out which program is the one being targeted by a LD_PRELOAD?

是否有一种方法可以确定哪个程序是被LD_PRELOAD锁定的?

LD_PRELOAD=/path/to/libstuff.so ./stuff <args>

Like when building the libstuff library in C/C++ and when it's preloaded is there a way to figure out that the program targeted is stuff?

比如在C/ c++中构建libstuff库,当它被预加载时是否有办法确定目标程序是东西?

And is this a safe way of doing so by if it were the case that the file is stuff then do things and else just let the lib die.

这是一种安全的做法吗?如果是这样的话,文件就是文件,然后做一些事情,然后让lib死亡。

IF this is not recommended

如果不建议这样做

The reason for asking is I can't get

问的原因是我不明白

HOME=$WORK_PATH start-stop-daemon --start --chuid servers --quiet --background --nicelevel -1 --pidfile $PIDFILE --make-pidfile --exec $WORK_PATH/program <args>

to work with LD_PRELOAD targeting program and not start-stop-daemon

使用LD_PRELOAD目标程序而不是启停守护进程

I don't know if this is allowed going offtopic like this (sorry incase) but if someone could help me with that would make my day too.

我不知道是否允许这样偏离主题(不好意思,以防万一),但如果有人能帮助我,我也会很开心。

Thanks in advance.

提前谢谢。

1 个解决方案

#1


2  

Run it using the env program, which modifies the environment then calls exec:

使用env程序运行它,该程序修改环境,然后调用exec:

start-stop-daemon --start --chuid servers --quiet --background --nicelevel -1 --pidfile $PIDFILE --make-pidfile \
   --exec env "LD_PRELOAD=/path/to/libstuff.so" "HOME=$WORK_PATH" "$WORK_PATH/program" <args>

#1


2  

Run it using the env program, which modifies the environment then calls exec:

使用env程序运行它,该程序修改环境,然后调用exec:

start-stop-daemon --start --chuid servers --quiet --background --nicelevel -1 --pidfile $PIDFILE --make-pidfile \
   --exec env "LD_PRELOAD=/path/to/libstuff.so" "HOME=$WORK_PATH" "$WORK_PATH/program" <args>