I found the issue..
The issue was that the mongoose call back thread which issues the system() command will not wait for the return status becuase of this line:
On the mg_start() function, which starts the server thread, they have included this line:
mg_start()
line no 5159:
(void) signal(SIGCHLD, SIG_IGN);
They have done this inorder to not create a zombie process.
Ref: http://www.win.tue.nl/~aeb/linux/lk/lk-5.html
But, According to QNX documentation,
“Setting a signal action to SIG_IGN
for a signal that's pending
causes the pending signal to be discarded, whether or not it is
blocked. If a process sets the action for the SIGCHLD
signal to
SIG_IGN
, the behavior is unspecified.”</p>
calling SIG_IGN
on SIGCHLD
causes the parent process to ignore the status signal from the child.
When we make a system()
call, it blocks the SIGCHLD signal from the shell that is being launched. According to UNIX documentation:
“Blocking SIGCHLD
while waiting for the child to terminate prevents
the application from catching the signal and obtaining status from
system()'s child process before system()
can get the status itself.”</p>
But, since mongoose discards the signal, it does not wait for the signal from system()
at all.
It simply continues to serve the response without a valid return status from system()
.
I just commented out this line for the time being. And it’s working.