Hi Christian,
My embedded linux webserver uses thread-per-connection mode. Using
either the linux system() call or the popen() call, I am issuing a linux
"ifconfig" command in my access handler callback, every second, on
command from a webpage. I wait for the result and return the result
string to the webpage in the response string.
I find that after a variable number of minutes, I get a memory scribble
which crashes my webserver application/daemon.
Any linux command seems to show the same problem so it's not related to
the "ifconfig", it crashes the same with "ps" or "ls" commands.
Is there any reason why issuing system() or popen() calls in the
callback might be unsafe?
Here's the code I call in the callback
int GetNetStats(MHD_Connection * connection, const char * szCommand)
{
FILE *fp;
int status = 0;
string strResponse = "<html><body>";
const int max_buffer = 256;
char buffer[max_buffer];
/* Open the command for reading. */
fp = popen(szCommand, "r");
if (fp == NULL) {
printf("Failed to run %s commandn", szCommand );
status = -1;
}
else
{
/* Read the output a line at a time - output it. */
while (!feof(fp))
if (fgets(buffer, max_buffer, fp) != NULL) strResponse.append(buffer);
pclose(fp);
}
strResponse += "</body></html>"; //terminate response string
SendResponse(connection, strResponse);
return status;
}
Best regards
David Myers