Commit Graph

31 Commits

Author SHA1 Message Date
Michael Santos
d425f54097 tcplxc: drain any pending stdio before exiting 2014-07-12 11:36:35 -04:00
Michael Santos
d426a1ef45 tcplxc: cleanup mounts 2014-05-26 11:04:48 -04:00
Michael Santos
80b1b84745 tcplxc: set temp directory 2014-05-23 10:33:43 -04:00
Michael Santos
844afd21d9 tcplxc: don't unmount pts in container 2014-05-23 09:54:53 -04:00
Michael Santos
0b97186624 tcplxc: mount /dev/pts
Allow ttys inside the container using /dev/pts.
2014-05-19 13:13:14 -04:00
Michael Santos
602046d536 tcplxc: set default environment variables
Default environment variables can be overriden by the user.

Rename the proplist keyword from 'env' to 'environ', since it clashes
with the 'env' option to alcove_drv:start/1. These options should be
namespaced or put into another proplist to prevent this.
2014-05-17 10:34:04 -04:00
Michael Santos
1255a32f93 tcplxc: allow creating system files
Mount /etc as a tmpfs filesystem. By default, create passwd and group
files. These can be overwritten by the user.

System files are created while running inside the read-only mount
namespace, so attempts to write the bind mounted system directories will
fail.
2014-05-17 10:34:03 -04:00
Michael Santos
a2b32f56f7 tcplxc: properly set the flags on bind mounts
Setting the mount flags on bind mounts requires 2 calls: 1 to perform
the mount, the second to remount the filesystem with the appropriate
flags. According to the man page, the bind flag is required in both
mounts:

    Note that behavior of the remount operation depends on the /etc/mtab
    file. The first command stores the 'bind' flag to the /etc/mtab
    file and the second command reads the flag from the file.  If you
    have a system without the /etc/mtab  file  or  if  you  explicitly
    define source and target for the remount command (then mount(8)
    does not read /etc/mtab), then you have to use bind flag (or option)
    for the remount command too. For example:

        mount --bind olddir newdir
        mount -o remount,ro,bind olddir newdir
2014-05-17 10:34:03 -04:00
Michael Santos
da221aa79c tcplxc: pass in files to write to the chroot 2014-05-16 11:08:00 -04:00
Michael Santos
5a6bbd5875 tcplxc: allowing running any executable 2014-05-16 11:08:00 -04:00
Michael Santos
1d3c9f1727 examples: exec bash, mount dirs for a full OS image 2014-05-14 10:56:32 -04:00
Michael Santos
74433b1ebd tcplxc: log the remote IP address/port 2014-05-11 15:55:05 -04:00
Michael Santos
d2060d9924 examples: #rlimit{} -> #alcove_rlimit{} 2014-05-09 14:15:36 -04:00
Michael Santos
6d3f13f8b4 tcplxc: close the socket if the shell exits 2014-05-06 08:21:02 -04:00
Michael Santos
d8af759ec5 tcplxc: remove cgroup on exit
Destroy the cgroup when the container exits. Use a constant name for the
container hostname ("alcove" + os pid). If leaking the pid is a concern,
the code could generate random bytes on startup and hash(pid, bytes).
2014-05-05 10:59:42 -04:00
Michael Santos
2f51b52b5e tcplxc: create a cgroup namespace per container 2014-05-04 09:53:05 -04:00
Michael Santos
b68086154f cgroup: use an iolist() for the namespace path
Use a list of binaries as the namespace:

    [<<"alcove">>, <<"guest1234">>] % <<"alcove/guest1234">>

is converted to:

    <<"/sys/fs/cgroup/blkio/alcove/guest1234">>
    <<"/sys/fs/cgroup/cpu/alcove/guest1234">>
    <<"/sys/fs/cgroup/cpuacct/alcove/guest1234">>
    <<"/sys/fs/cgroup/cpuset/alcove/guest1234">>
2014-05-04 09:53:05 -04:00
Michael Santos
6655928fda tcplxc: fix process leak on error 2014-05-03 12:23:47 -04:00
Michael Santos
8d1b387792 tcplxc: restrict the number of processes
With the current cgroup limits, a fork bomb causes the container cgroup
limit to be exceeded and the fork bomb is killed. Works well.

Add a resource limit on the number of processes. It is sort of redundant
given the cgroup limit but is useful on systems without cgroup support.
2014-05-03 11:50:17 -04:00
Michael Santos
53cb7a2ab8 tcplxc: allow cgroup limits to fail
Not all the cgroups may exist. For example, the stock raspbian doesn't
have cpuset. The cgroup code could be smarter about this, but it'd
complicate the example.
2014-05-02 11:03:02 -04:00
Michael Santos
828ba5c260 tcplxc: fix license 2014-05-01 11:40:12 -04:00
Michael Santos
a07e723d5c example: create a Linux container per connection
Rough working code for creating a Linux container, restricted by
cgroups:

    erl: tcplxc:start().

    shell: nc localhost 31337

Multiple containers are supervised by one port in this example.
2014-05-01 10:37:29 -04:00
Michael Santos
51c7f15e38 gpioled: pass the internal state using a record 2014-04-28 09:07:25 -04:00
Michael Santos
27b0416288 Revert "examples: clean up gpioled"
This reverts commit 999de650dc.

unexport vs export
2014-04-26 13:04:30 -04:00
Michael Santos
999de650dc examples: clean up gpioled 2014-04-26 11:42:26 -04:00
Michael Santos
e2c6582661 examples: tcpsh
Bind a shell, running in a namespace, to a socket. Runs one Erlang port
process per container (so a minimum of 2 Unix processes per connection).
2014-04-26 11:26:07 -04:00
Michael Santos
b62e73d2e3 Simplify uid generation 2014-04-24 08:18:50 -04:00
Michael Santos
26a207d876 Stream messages from port through a proxy process
Convert the binary format messages from the port into erlang terms using
a gen_server.
2014-04-22 14:16:06 -04:00
Michael Santos
78fa3f077a Add an example of interacting with GPIO
Tested on a beaglebone black and on a raspberry pi.
2014-04-21 11:26:03 -04:00
Michael Santos
32d5e5f98e Fix license 2014-04-21 11:07:43 -04:00
Michael Santos
882494c3bc Begin adding documentation and examples 2014-04-18 18:02:44 -04:00