I am interested in starting a daemon inside an lxc container with its stdin/stdout as a socket passed from the host, inetd style. Is this possible?
-
Feel free to ask for clarification since I am asking a bounty for the question. – alexyorke Jul 19 '13 at 01:47
-
Cant you just use netcat for this? – Geoffrey Jul 24 '13 at 14:25
-
I'm thinking unix sockets. I don't think netcat would do the trick. Also that was two years ago. – joeforker Jul 24 '13 at 18:32
-
How could I use netcat? I haven't had experience with that command but it sounds intriguing – alexyorke Jul 30 '13 at 13:49
3 Answers
Be advised, if using an LXC "snapshot" clone, with a directory backing store (which thus uses overlayfs), then Unix FIFO pipes are currently broken. See:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1214500

- 21
- 2
I don't think LXC has native support, but you could always just run your lxc command under xinetd to get what you want. Or write your own server that talks sockets on one side and talks LXC (via popen() or something) on the other side.

- 12,654
- 2
- 42
- 50
inetd
is a daemon that starts (non-daemonic) programs that use stdin/stdout to listen/talk to you
The LXC utilities lxc-start
and lxc-execute
insist on closing all open file descriptors (including stdin/stdout) making them useless with inetd
. They eventually call clone(2)
, however, and so can you, writing your own C wrapper like this:
#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);
}
This wrapper can then be run under inetd
.

- 5,513
- 1
- 23
- 43