i am use Fanotify sample code to handle file open and close events. In handle_events() function i am called my function checkFileIsExecutable(). after calling function my system is hang and need to hard restart. i am providing my function which is use to check executable file or not. i am added my hanging code as a reference please chck it and help me to solve this problem.
checkFileIsExecutable(const char *filepath)
{
string data;
FILE* stream;
char buffer[64];
char res[64];
if(sFileName.empty())
{
return "error";
}
string cmd("file ");
cmd.append(filepath);
cout<< "Going to execute cmd: "<< cmd.c_str()) <<endl;
stream = popen(cmd.c_str(), "r"); //here my code is hangs
if(stream)
{
while(!feof(stream))
{
if(fgets(buffer, 64, stream) != NULL)
{
data.append(buffer);
}
}
pclose(stream);
}
strcpy(res, data.c_str());
if(0 == strcasecmp(res, "executable"))
{
cout << "File is executable\n" << endl;
return true;
}
return false;
}
error code:
Going to execute cmd:file /root/Test/access hangs....