2

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?

4

1 回答 1

3

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.

于 2013-08-21T12:08:50.223 回答