我有以下代码:
int pfds[2], pid;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pfds) < 0) {
goto error;
}
if ((pid = fork()) == -1)
goto error;
if (pid == 0) {
/* child */
close(pfds[1]);
dup2(pfds[0], 1);
close(pfds[0]);
const char *argv[5];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = "/sbin/script.sh";
argv[i++] = NULL;
execvp(argv[0], (char **) argv);
exit(ESRCH);
}
close(pfds[0]);
s.stream.string_data = true;
s.stream.notify_read = client_read_cb;
ustream_fd_init(&s, pfds[1]);
该脚本返回一个字符串(用命令打印echo
),它标志着脚本加载的结束。
如何读取由返回的字符串/sbin/script.sh
?