全志Tina平台使用procd做为1号进程时printf阻塞线程问题解决方法

本文介绍了解决在使用Procd作为1号进程时遇到的应用程序阻塞问题。通过在启动配置文件中添加补丁,修改文件描述符属性以避免阻塞,并确保输出正确处理。

【问题描述】 使用procd做为1号进程,在rc.local中启动了一个应用程序,程序中使用了printf打印,发现会阻塞程序,在/proc/xxx/fd中查看文件描述符指向一个管道。

【解决方法】 将全志提供的一个patch放到tina/package/system/procd/patches目录下。 patch内容如下,也可以自己新建一个patch文件:

--- a/rcS.c
+++ b/rcS.c
@@ -26,7 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <glob.h>
-
+#include <fcntl.h>
 #include <libubox/ustream.h>
 
 #include "procd.h"
@@ -88,6 +88,7 @@
 
     if (pid) {
         close(pipefd[1]);
+        fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
         s->fd.stream.string_data = true,
         s->fd.stream.notify_read = pipe_cb,
         runqueue_process_add(q, &s->proc, pid);
--- a/service/instance.c
+++ b/service/instance.c
@@ -417,11 +417,13 @@
     if (opipe[0] > -1) {
         ustream_fd_init(&in->_stdout, opipe[0]);
         closefd(opipe[1]);
+        fcntl(opipe[0], F_SETFD, FD_CLOEXEC);
     }
 
     if (epipe[0] > -1) {
         ustream_fd_init(&in->_stderr, epipe[0]);
         closefd(epipe[1]);
+        fcntl(epipe[0], F_SETFD, FD_CLOEXEC);
     }
 
     service_event("instance.start", in->srv->name, in->name);
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值