我正在开发一个包含多个服务器套接字的应用程序,每个服务器套接字都运行在一个独特的线程
其中一个线程调用外部实用程序(脚本).此脚本调用将消息发送到其中一个服务器套接字的实用程序(客户端).
最初,我system()用来执行这个外部脚本,但我们无法使用它,因为我们必须确保服务器套接字在分叉执行外部脚本的子代中关闭.
我现在请fork()和execvp()我自己.我fork()然后在孩子中关闭所有服务器套接字然后调用execvp()以执行脚本.
现在,所有这一切都很好.问题是脚本有时会向服务器应用程序报告错误.该脚本通过调用另一个打开TCP套接字并发送相应数据的应用程序(客户端)来发送这些错误.我的问题是客户端应用程序获取系统调用0返回的值socket().
注意:仅当使用我的forkExec()函数调用脚本/客户端应用程序时才会发生此问题.如果手动socket()调用脚本/客户端应用程序,则调用会正常执行,并且工作正常.
基于这些信息,我怀疑它是我的fork()execvp()代码中的一些东西......有什么想法吗?
void forkExec()
{
int stat;
stat = fork();
if (stat < 0)
{
printf("Error forking child: %s", strerror(errno));
}
else if (stat == 0)
{
char *progArgs[3];
/*
* First, close the file descriptors that the child
* shouldn't keep open
*/
close(ServerFd);
close(XMLSocket);
close(ClientFd);
close(EventSocket);
close(monitorSocket);
/* build the arguments for script */
progArgs[0] = calloc(1, …Run Code Online (Sandbox Code Playgroud) 我一定做错了...否则这可能是YAJL中的错误,但我对此表示高度怀疑。我无法从json对象中检索第一个元素。我回到YAJL源,使用示例parse_config.c对此进行了测试,但它也失败了。
使用sample.config
/*
* The configuration file for Yahoo! BrowserPlus, included in the YAJL
* tree as a sample configuration file for parsing.
*
* This is the configuration file for BrowserPlus
*/
{
// The type of build this is, which is accessible to JavaScript via
// BrowserPlus.getPlatformInfo();
// Different build types should only differ in signatures accepted
// (BrowserPlus.crt) and configured distribution servers.
"BuildType": "ephemeral",
// the base url for the "primary" distribution server. This server will
// …Run Code Online (Sandbox Code Playgroud)