名为 =program.c 的程序的一部分
int memoryPercent()
{
int memoryPercent=0;
FILE *pipe1 = NULL;
pipe1=popen("/home/jatin/scripts/memoryPercent.sh","r");
if(!pipe1)
{
snmp_log(LOG_ERR,"popen failed in temp(),errno:%d\n",errno);
return -1;
}
if( fscanf(pipe1,"%d",&memoryPercent) != 1)
{
snmp_log(LOG_ERR,"fscanf failed in temp fun(),errno:\n");
return -2;
}
pclose(pipe1);
return memoryPercent;
}
上面是我的调用代码/home/jatin/scripts/memoryPercent.sh 在此位置给出了一个脚本,它返回一个 INTEGER 值。
在 UBUNTU 12.04 中,当我编译并执行此代码时,它运行完美。
但在我的 VM-WARE 中
我已将所有必要的依赖项复制到位置/var/snmp3 并使用 CHROOT 执行此二进制文件,语法为
/usr/sbin/chroot /var/snmp3/ /usr/local/bin/program
它仅显示值“-1”! 谁能告诉我我错过了什么?
该脚本位于 /var/snmp3/home/jatin/scripts/memoryPercent.sh
中的同一位置
以及 775 模式下的 /home/jatin/scripts/memoryPercent.sh
...
最佳答案
尝试从 chrooted shell 手动运行脚本。
我认为您缺少 memoryPercent.sh 使用的 shell。您是否已将 shell 复制到 chroot 环境?
关于在 chroot 模式下从二进制调用脚本,不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12707770/