我正在我的 qnx 系统上运行 mongoose 3.7 服务器。
我收到升级固件的http请求。根据要求,我使用 system()
调用请求处理程序来升级固件。
但是,奇怪的是,system()
返回 255。相同的调用之前在 mongoose 2.0 上也有效。
更奇怪的是,我通过 system()
发出的命令返回 255 后调用才起作用。
我正在使用WEXITSTATUS
知道错误是system()
返回
知道为什么会发生这种情况吗?
最佳答案
我发现了这个问题..
问题是发出 system() 命令的 Mongoose 回调线程不会等待返回状态,因为这一行:
在启动服务器线程的 mg_start() 函数中,他们包含了这一行:
mg_start()
第 5159 行:
(void) signal(SIGCHLD, SIG_IGN);
他们这样做是为了不创建僵尸进程。
引用号:http://www.win.tue.nl/~aeb/linux/lk/lk-5.html
但是,根据 QNX 文档,
“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 theSIGCHLD
signal toSIG_IGN
, the behavior is unspecified.”
在 SIGCHLD
上调用 SIG_IGN
会导致父进程忽略来自子进程的状态信号。
当我们进行 system()
调用时,它会阻止来自正在启动的 shell 的 SIGCHLD 信号。根据 UNIX 文档:
“Blocking
SIGCHLD
while waiting for the child to terminate prevents the application from catching the signal and obtaining status from system()'s child process beforesystem()
can get the status itself.”
但是,由于 mongoose 会丢弃该信号,因此它根本不会等待来自 system()
的信号。
它只是继续提供响应,而没有来自 system()
的有效返回状态。
我只是暂时注释掉了这一行。它正在发挥作用。
关于c++ - System() 调用返回 255,但随后执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18318521/