532 Commits

Author SHA1 Message Date
Dubiously Moral Majority
86d96f5b00 Merge pull request #2 from msantos/master
sync with upstream alcove again
2015-08-09 00:53:00 -04:00
Michael Santos
0fe9e6c15e unshare: remove debug printf 2015-08-08 15:43:58 -04:00
Michael Santos
b3f09ed397 alcove_drv: Packet -> Buf 2015-08-05 12:08:34 -04:00
Michael Santos
9eda1ce49a badpid: use error exception instead of exit
A badpid exception should be an error:

    OSPid = try alcove:getpid(Drv, [1,2,3])
    catch
        error:badpid -> handle_error(...)
    end.
2015-08-04 09:34:07 -04:00
Michael Santos
2379cd04a2 Change 'badpid' to a control message
Sending data to the stdin of a non-existent process will also return
'badpid'. Mark the type as a control message rather than the result of
a call.

Probably there only needs to be 2 types of messages: sync (calls) and
async (events). The control message type might be removed and these
events labelled as events.
2015-08-03 09:36:30 -04:00
Michael Santos
45ac02a03b stop/2: return ok if the gen_server has exited 2015-08-02 16:01:24 -04:00
Michael Santos
572742b376 alcove_cgroup:set/6: return value
Make the result of alcove_cgroup:set/6 more consistent:

* return ok on success
* return an errno tuple if open() or write() fails
* return {error,enoent} if the cgroup does not exist, instead of []

In the case of a partial write, currently the code will crash, taking
care to close the fd in the unix child process first. The code could
select on the fd and attempt another write.
2015-07-29 11:47:44 -04:00
Michael Santos
f9ac18d0c1 examples: set MS_PRIVATE on container mounts
Ubuntu 15.04 sets the MS_SHARED flag on system mounts. Since this flag
is inherited by container mounts and the container filesystem is visible
to the global namespace.

Use the MS_PRIVATE flag on container mounts to prevent this issue.
2015-07-28 07:55:32 -04:00
Michael Santos
535eeb9530 readdir: do not filter paths
Return the result of readdir(3) without removing the magic "." and ".."
directories.
2015-07-25 11:54:39 -04:00
Michael Santos
d5e80fac33 setns/4: supporting setting namespace 2015-07-24 10:52:06 -04:00
Michael Santos
b85c5d2fdf Add optional timeout
Experiment with adding an optional timeout to each call. The default is
still infinity.
2015-07-23 09:39:57 -04:00
Michael Santos
9e80c663c7 rebar3: convert the top level Makefile 2015-07-22 16:11:39 -04:00
Michael Santos
aa306a6ab2 Be explicit with checks
I go back and forth with this: be explicit or brief. Especially with
strcmp() where I always WTF.

The code is simpler and easier to read when the checks are explicit. For
example:

    // NULL pointer or integer?
    if (!x) return;
2015-07-20 10:41:46 -04:00
Michael Santos
d755ada152 Remove function versions with optional fork path
Enforce the use of the fork path. Having an optional fork path was nice
when working in the shell:

    {ok, Child} = alcove:fork(Drv).

Instead of:

    {ok, Child} = alcove:fork(Drv, []). % port process forks

However it introduced a few problems:

* made the interface inconsistent and ambiguous

    alcove:kill(Drv, Pid, 9)
    % vs
    alcove:kill(Drv, [], Pid, 9) % the port process is sending the signal

* calls could not have optional arguments

  Whether or not calls should have optional arguments is an open question
  but the optional fork path would have conflicting arities:

  For example, the last argument to mount/8 is used only by Solaris:

  % arity 6
  -spec mount(alcove_drv:ref(),iodata(),iodata(),iodata(),uint64_t() | [constant()],iodata()) -> 'ok' | {'error', file:posix() | 'unsupported'}.
  % arity 7
  -spec mount(alcove_drv:ref(),iodata(),iodata(),iodata(),uint64_t() | [constant()],iodata(),iodata()) -> 'ok' | {'error', file:posix() | 'unsupported'}.
  % arity 7
  -spec mount(alcove_drv:ref(),fork_path(),iodata(),iodata(),iodata(),uint64_t() | [constant()],iodata()) -> 'ok' | {'error', file:posix() | 'unsupported'}.
  % arity 8
  -spec mount(alcove_drv:ref(),fork_path(),iodata(),iodata(),iodata(),uint64_t() | [constant()],iodata(),iodata()) -> 'ok' | {'error', file:posix() | 'unsupported'}.

* because of the ambiguity in arity, each call can't have an optional
  timeout

  call/5 sets a timeout of 'infinity'. The timeout isn't accessible from
  the "named" functions (e.g., fork, chdir, ...), which means that users
  who need the timeout will have to resort to using the call/5
  interface. An unfortunate side effect of using call/5 is that dialzyer
  won't be able to type check the arguments.

The result of removing the functions without the fork path is that the
code ends up being simpler and more consistent.
2015-07-19 09:41:51 -04:00
Michael Santos
8c83784bc2 Fix tests on Solaris, FreeBSD and OpenBSD 2015-07-18 10:50:50 -04:00
Michael Santos
ca0d6f12b4 constants: return {error, unuspported}
Return {error, unsupported} if an atom is used as an argument and the
constant the atom represents does not exist on the current platform.

The previous behaviour was inconsistent and non-deterministic. The
constant might:

* return {error,einval}. System return values could not be distinguished
  from alcove return values.

* cause an exception

* be silently ignored
2015-07-18 10:09:41 -04:00
Michael Santos
6a400730c6 alloc: call per file 2015-07-17 06:58:34 -04:00
Michael Santos
2c9633ff27 limit: call per file 2015-07-16 09:36:09 -04:00
Michael Santos
5d88ec52a0 exec: call per file 2015-07-15 09:39:05 -04:00
Michael Santos
07cc6f79dd mount: call per file 2015-07-14 05:34:57 -04:00
Dubiously Moral Majority
c2b449ceca Merge pull request #1 from msantos/master
sync with upstream alcove
2015-07-13 22:01:04 -04:00
Michael Santos
5984f08dd2 signal: call per file
c_src/sys/alcove_signal.c has a function to map signal numbers to
constants used by the signal handler in the event loop.
2015-07-13 10:13:04 -04:00
Michael Santos
eebe8ccc7d proc: call per file 2015-07-12 08:58:48 -04:00
Michael Santos
a5bf4e282a alcove_file: call per file 2015-07-11 09:57:06 -04:00
Michael Santos
014411ba34 syscalls: rename files 2015-07-10 10:04:46 -04:00
Michael Santos
2650d22c4d utsname: calls per file 2015-07-09 08:57:19 -04:00
Michael Santos
8a2f876f7d alcove_env: call per file 2015-07-08 09:36:50 -04:00
Michael Santos
8f5c6d8550 alcove_fork.h: remove alcove_clone_constants 2015-07-06 13:48:03 -04:00
Michael Santos
5d03da9a2c Fix clone_define/2,3
Move out the clone constants to a header since fork() does not need
them. Include sched.h with the constants to ensure the CLONE_ constants
are defined.
2015-07-06 10:12:30 -04:00
Michael Santos
c7bd453e68 fork: individuals calls per file
Leave common utility functions in c_src/sys/alcove_fork.(c|h). Maybe
these files should be renamed "fork_common.c" or "alcove_fork_common.c".

Move alcove_setfd() to alcove.c since the pid_foreach() is also there.
These common functions should also eventually be moved out to another
file.
2015-07-05 11:59:55 -04:00
Michael Santos
bded978e4b mkdir: add missing header 2015-07-04 07:27:48 -04:00
Michael Santos
97fa5d5379 alcove_dir: separate files for each call 2015-07-04 07:19:48 -04:00
Michael Santos
febe77b585 cred: split out calls into separate files
Begin code re-organization by moving functions to one call per file.
2015-07-03 10:40:41 -04:00
Michael Santos
672af8a39f Port to rebar3
Support building with rebar3 and rebar2 using the makefile generated
from "rebar3 new cmake".

Do a straightforward port of the compiler options from the rebar port
compiler. The optimizations/warnings can be re-enabled later.

Use the fancy pants incremental building of each compilation unit from
the template. It's a lot slower than compiling in one go but is slightly
faster when running any rebar command (rebar runs make on each command
which recreates the target. The Makefile needs to be fixed).
2015-07-02 10:23:08 -04:00
Michael Santos
3127db7223 alcove_drv:start/1: remove maxforkdepth
maxforkdepth can be set at runtime using alcove:setopt/3,4.
2015-06-27 13:17:18 -04:00
Michael Santos
f060d44937 errno_id/2,3: convert errno integer to atom 2015-06-16 16:54:13 -04:00
Michael Santos
c6d1b9c9b5 alcove_drv: use exported fork_path() type 2015-05-28 11:03:05 -04:00
Michael Santos
c2a28e6c3c Update type specs
Improving the readability of the types by making them more specific.
2015-04-25 10:05:01 -04:00
Michael Santos
d81dcb688a Fix compilation errors on Solaris
Use POSIX 200112L/C99 mode on Solaris to suppress compilation warnings.

"-D__EXTENSIONS__=1" is required for NSIG (max number of signals). This
also pulls in an ERR macro which necessitates renaming the goto label
from ERR -> ERROR.
2015-02-21 09:21:48 -05:00
Michael Santos
3b15781433 Use a new message type for stdio events
Make a new message type (alcove_ctl) for informing the erlang process
when a stdio descriptor has been closed.
2015-01-01 17:09:48 -05:00
Michael Santos
4ec936d5d7 Add synch/async sends into port
Messages sent to stdin are asynchronous since a response can be sent
back at any time.
2014-12-29 10:26:38 -05:00
Michael Santos
804316629d Crash if the port exits
If the alcove port exits, cause the gen_server to crash.

The reason for crashing:

1. The type specs for all calls was implictly extended to include
   {error,closed} on port failure.

2. There is no error recovery the calling process could do (except
   cleaning up state). The caller can still catch errors, just like when
   dealing with a normal port.

3. Asynchronous messages into the port (stdin) had to be handled as calls,
   rather than casts.
2014-12-29 10:26:38 -05:00
Michael Santos
a664397868 Track ownership of the port in the dict 2014-12-29 10:26:38 -05:00
Michael Santos
5ea775fced badpid: event -> call
Although badpid may be returned by any process in the the fork chain,
it is a synchronous response to a call like badarg and undef.
2014-12-28 10:38:38 -05:00
Michael Santos
63ae5b1b37 Remove test to make dialyzer happy 2014-12-28 10:23:47 -05:00
Michael Santos
2ba7caaf76 Exit with badpid for invalid OS PID in fork path
A message sent to a non-existent Unix PID would be discarded, causing
the calling erlang process to block forever in receive.

This change modifies the behaviour of the port to return "badpid" if an
element in the fork path is not found. Since any element of the path may
be invalid, an event (as opposed to a call reply) is generated.
Currently any "badpid" event will cause the erlang process to exit.
Since only one call can be active at a time, it shouldn't interfere with
other operations but the mailbox should pattern match on the list
prefix (i.e., a call to [1,2,3,-1,4] would generate badpid for
[1,2,3,-1]).

Also define the behaviour when writing to invalid PIDs (<= 0). Since 0
is used to initialize the list of child PIDs in the port, passing in a
PID of 0 would match the first available slot in the PID table, causing
the port to write to fd 0.
2014-12-27 15:42:10 -05:00
Michael Santos
0f9c27d5d4 prctl: update types and docs 2014-12-24 11:25:11 -05:00
Michael Santos
97df96a7ba alcove_drv: consistently enforce positive PIDs
The port will accept negative PIDs. A PID is usually defined as a signed
32-bit integer.

For fork paths, values will always be positive (as returned by fork;
fork errors will return a tuple rather than -1). If the user passes a
negative number as a component of the fork path, the message will be
discared.
2014-12-23 09:50:34 -05:00
Michael Santos
ce8d642791 Enforce precedence in macros 2014-12-22 07:31:17 -05:00
Michael Santos
17c7277a1a Include all args to call in the stack trace 2014-12-21 15:16:53 -05:00