Search code examples
clinuxubuntusnmpnet-snmp

calling a script from Binary in chroot mode,not working


Part of a program named =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;
}

above is my calling code /home/jatin/scripts/memoryPercent.sh on this location a scripts is given and it is returning a INTEGER value.

in UBUNTU 12.04 when I compile and execute this code it is running perfectly.

but in my VM-WARE

I have copied all the necessary dependencies at the location /var/snmp3 and executing this binary with CHROOT the syntax is

/usr/sbin/chroot /var/snmp3/ /usr/local/bin/program

it is showing value "-1" only !! Can anyone tell me what I am missing ?

the script is at the same location in /var/snmp3/home/jatin/scripts/memoryPercent.sh as well as /home/jatin/scripts/memoryPercent.sh in 775 mode....


Solution

  • Try running the script manually from a chrooted shell.

    I think you are missing the shell used by memoryPercent.sh. Have you copied the shell to the chrooted environment?