Why is faketime command skipping section of code

134 views Asked by At

I have a cpp code that I'm trying to run with faketime command. I'm running it on two identical computers. They're both running RHEL 7. I noticed that when I run my code, on one computer, it totally skips my popen call.

My code is essentially

char ntp[]= "192.168.1.200";
    FILE *jitter;
    char line[100];
    char *start;
    char * eol;
    char pps[] = "NTPS";
    jitter = popen("chronyc sources", "r");
        int i;
cout<<"reached here"<<endl;
    while(fgets(line,sizeof(line),jitter))
{
cout<<"line is\n"<<line<<endl;
 if(strstr(line,pps)){
        start = strpbrk(line,"#0+-");    
        cout<<"PPS is "<<start<<endl; 
        //find new line character and replace it with comma
        eol = strrchr(start,'\n');
        i=eol-start;
        start[i]=',';
    
        myfile<<start;
    }

    if(strstr(line,ntp)){
        myfile<<start;  
    }
}
    pclose(jitter);
}

I added a print statement of

cout<<"reached here"<<endl;

but when I run it with "faketime 'last friday 5pm' ./code", on one computer it never reaches the print statement for some reason while on the other it does. I searched online to no success (I'm not running a approximating algorithm, they have the same compiler and make file, etc. I'm literally doing a git pull of the code and running it).

Does anyone know why?

Thanks

1

There are 1 answers

0
bchang32 On

So it appears the issue was with SELinux. Apparently chrony doesn't interact well when SELinux is in enforced mode. I switched it to permissive and it behaves as expected now. I can call faketime 'last friday 5pm' chronyc sources as well as use it in my popen code