[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] Spawning processes from access handler callback

From: david . myers
Subject: [libmicrohttpd] Spawning processes from access handler callback
Date: Mon, 20 Apr 2015 15:56:34 +0000
User-agent: Roundcube Webmail/1.0.2


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 command\n", szCommand );
  status = -1;
/* Read the output a line at a time - output it. */
while (!feof(fp))
  if (fgets(buffer, max_buffer, fp) != NULL) strResponse.append(buffer);


strResponse += "</body></html>"; //terminate response string
SendResponse(connection, strResponse);

return status;

Best regards

David Myers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]