Question

I am running mongoose 3.7 server on my qnx system.

I receive http request to upgrade the firmware. On the request, I use, system() call in the request handler to upgrade the firmware.

But, strangely, system() returns 255. The same call was working before with mongoose 2.0.

Even more strange, the command which I issued through the system() call works after it returned 255.

I am using WEXITSTATUS to know the error which system() returns

Any idea why this is happening?

Was it helpful?

Solution

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.”

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.”

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top