Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在lxc(linux容器)中使用套接字作为stdin/stdout吗?_Linux_Virtualization_Lxc - Fatal编程技术网

我可以在lxc(linux容器)中使用套接字作为stdin/stdout吗?

我可以在lxc(linux容器)中使用套接字作为stdin/stdout吗?,linux,virtualization,lxc,Linux,Virtualization,Lxc,我感兴趣的是在lxc容器中启动一个守护进程,将其stdin/stdout作为从主机传递的套接字,即inetd样式。这可能吗?我认为LXC没有本机支持,但您可以在xinetd下运行LXC命令以获得所需的功能。或者编写自己的服务器,一边与套接字对话,另一边与LXC对话(通过popen()或其他方式)。inetd是一个守护进程,它启动(非守护进程)程序,使用stdin/stdout来听/说你的话 实用程序lxc start和lxc execute坚持关闭所有打开的文件描述符(包括stdin/stdou

我感兴趣的是在lxc容器中启动一个守护进程,将其stdin/stdout作为从主机传递的套接字,即inetd样式。这可能吗?

我认为LXC没有本机支持,但您可以在xinetd下运行LXC命令以获得所需的功能。或者编写自己的服务器,一边与套接字对话,另一边与LXC对话(通过popen()或其他方式)。

inetd
是一个守护进程,它启动(非守护进程)程序,使用stdin/stdout来听/说你的话

实用程序
lxc start
lxc execute
坚持关闭所有打开的文件描述符(包括stdin/stdout),使它们在
inetd
中无用。但是,它们最终会调用克隆(2),您也可以这样编写自己的C包装器:

#define STACKSIZE 409600
/* choose your favourite brand of isolationism below */
#define SPLENDID_ISOLATION (CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWNET)


int exec_command(void* arg) {
  /* don't close stdin/stdout here! */
  execl("command", "command", arg, NULL);
  return 1; 
}

void main(int  argc, char **argv) {
  void *stack = malloc(STACKSIZE) + STACKSIZE - 1; /* grows downwards */
  clone(&exec_command, stack, SIGCHLD|CLONE_VFORK|SPLENDID_ISOLATION, argv[1]);
  wait(NULL);
}

然后可以在
inetd
下运行此包装

请注意,如果使用LXC“快照”克隆和目录备份存储(因此使用overlayfs),则Unix FIFO管道当前已断开。见:


请随意要求澄清,因为我是在要求悬赏。你不能用netcat来解决这个问题吗?我在考虑unix套接字。我认为netcat不会这么做。那也是两年前的事了。我怎么能用netcat呢?我没有使用该命令的经验,但听起来很有趣