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

【问题描述】 使用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);
 

猜你喜欢

转载自blog.csdn.net/weixin_43094346/article/details/82599063