Commit Graph

321 Commits

Author SHA1 Message Date
Michael Santos
a2b8e1742c lseek: fix copy/paste error in whence 0.6.1 erl_interface 2014-08-08 10:04:30 -04:00
Michael Santos
a53f4671fe Add sasl to dependencies 2014-08-06 10:05:39 -04:00
Michael Santos
62e06aaf95 readme: sudo for CentOS, remove completed todo's 2014-08-05 10:25:52 -04:00
Michael Santos
56857281f8 Crash if call/2,3,4,5 reaches the timeout
To ensure consistency, exit if a timeout is set and reached. Otherwise,
late messages may arrive in the queue, messing up subsequent calls:

    1> {ok,P} = alcove_drv:start().
    {ok,<0.45.0>}
    2> catch alcove:call(P, [], getpid, [], 0).
    {'EXIT',timeout}
    3> alcove:version(P).
    2897
    4> flush().
    Shell got {alcove_call,<0.45.0>,[],<<"0.6.1">>}
    ok

Using timeouts might be needed if it is not known whether is still
running in the event loop.

Remove the cast functions, since they are dangerous and can be emulated
by using call/5.
2014-08-04 16:26:18 -04:00
Michael Santos
a338021cce types: convert to using timeout() in type spec 2014-08-04 14:58:56 -04:00
Michael Santos
175c81046e Resume partial writes
Ensure the complete buffer is written to stdin of the child process. In
the case of failure, currently the error is ignored.
2014-08-03 10:39:03 -04:00
Michael Santos
bc84d869d3 Add test for writing to invalid PIDs 2014-08-03 10:23:18 -04:00
Michael Santos
7a07c8eec1 Add call/5: call with timeout
Fix the code to match the documentation and add a call with timeout.

Simplify the alcove_drv module by removing the versions of call with
defaults. The alcove module does the work of setting default values.
2014-08-03 10:09:58 -04:00
Michael Santos
7488c1737b Ignore failures writing to a process' stdin
Do not crash if the caller attempts to write to a non-existent process:

    {ok, Drv} = alcove_drv:start(),
    {ok, Fork} = alcove:fork(Drv),
    ok = alcove:execvp(Drv, [Fork], "/bin/echo", ["/bin/echo", "test"]),
    % will hang forever instead of crashing
    ok = alcove:execvp(Drv, [Fork], "/bin/echo", ["/bin/echo", "test"]).

There are 2 common failure cases are:

* the PID is not found, pid_foreach() returns 1

* the write fails because the child has exited (EPIPE)

write(2) on Linux documents the following errno values:

* EAGAIN, EINTR: should be dealt with by using completing partial writes

* EBADF, EINVAL: since the event loop manages the fd's and the fd's
  are not accessible by the caller, should be harmless to ignore errors

The issue is if the child process can end up in an inconsistent state.
If it is possible, then it is better for the parent process to crash.
2014-08-03 09:48:25 -04:00
Michael Santos
dc495fed9d Use a macro to calculate the iovec length 2014-07-31 17:06:55 -04:00
Michael Santos
c91307c102 alcove_write: fix end of array check
This code looked fishy to me but I couldn't pinpoint why and it worked on
Ubuntu 12.04/armv7l, Ubuntu 12.04/amd64, OpenBSD 5.5/amd64 and FreeBSD
10/amd64. I forgot to test on Ubuntu 14.04/amd64 of course and
thankfully it failed there.

The code compares the number of bytes written by writev against each of
the iov_len fields in the iovec array and decrements the value
accordingly. So an iovec array that looks like:

    iov[0].iov_len = 4
    iov[1].iov_len = 6

    number of bytes written = 10 bytes

Would be computed as follows:

    count = 2

    0: 10 >= iov[0].iov_len (4) -> 6
    1: 6 >= iov[1].iov_len (6) -> 0
    2: 0 >= iov[2].iov_len (undefined) -> ???
    3: ...

Limit iteration to the size of the iovec array. Although this commit fixes
this issue, this code should either be further simplified or re-written.
2014-07-30 14:29:01 -04:00
Michael Santos
4ec1a4640e Resume partial writev's
Handle partial writes as suggested here:

http://stackoverflow.com/questions/5853675/techniques-for-handling-short-reads-writes-with-scatter-gather
2014-07-29 17:12:11 -04:00
Michael Santos
7b5e34884b Move macros to header 2014-07-28 10:57:13 -04:00
Michael Santos
b29072022e Formatting, variable names 2014-07-27 09:24:15 -04:00
Michael Santos
895442cce1 Use a static buffer for the protocol headers 2014-07-26 20:04:04 -04:00
Michael Santos
c8b2061e5e Check length before retrieving 2 byte int 2014-07-26 15:23:00 -04:00
Michael Santos
5a18856fbd Consolidate message reads from stdin
Read the length header, then length bytes and parse the message in the
buffer.
2014-07-26 14:59:16 -04:00
Michael Santos
71bd692310 Clean up message parsing from stdin
Remove unnecessary memory allocation.
2014-07-26 11:20:32 -04:00
Michael Santos
bb94149c09 Use writev(2) for stdio
Begin cleanup of code by replacing usage of write + malloc with writev.
2014-07-26 10:27:35 -04:00
Michael Santos
bb700f1bdd Simplify stdin message parsing 2014-07-25 12:13:01 -04:00
Michael Santos
0fb0fee5f2 Really fix define/2,3 string comparison 2014-07-25 12:09:00 -04:00
Michael Santos
614841d9db define: fix string comparison of constants
SYS_writev != SYS_write
2014-07-24 11:27:29 -04:00
Michael Santos
ace0cd5724 Run chroot tests on openbsd
Skip tests on unsupported platforms.
2014-07-21 07:58:35 -04:00
Michael Santos
9149b4c1d4 tests: run alloc test on all platforms
Currently, alloc/2,3 tests functionality that only is needed for linux
(for seccomp mode). Run the tests on other plaforms like freebsd, so we
can catch any bugs.
2014-07-18 12:26:37 -04:00
Michael Santos
7a1c17bfd6 Specs for alcove_cgroup:destroy/1,2,3 2014-07-18 10:39:49 -04:00
Michael Santos
c569af73b7 Specs for alcove_cgroup:create/1,2,3 2014-07-17 18:04:15 -04:00
Michael Santos
9216014669 Specs for setsid/1,2 2014-07-16 13:49:45 -04:00
Michael Santos
1deadf3e90 Specs for call/2,3,4 2014-07-15 17:47:41 -04:00
Michael Santos
d38e617e7d Specs for cast/2,3,4 2014-07-14 16:31:24 -04:00
Michael Santos
ee0e213d29 Specs for event/1,2,3 2014-07-13 11:29:55 -04:00
Michael Santos
d425f54097 tcplxc: drain any pending stdio before exiting 2014-07-12 11:36:35 -04:00
Michael Santos
43c58773e8 Specs for stdin/2 2014-07-12 09:32:01 -04:00
Michael Santos
a20154553c Specs for stderr/1,2 2014-07-11 16:25:05 -04:00
Michael Santos
216d0e388f Correct specs for stdout/1,2 2014-07-10 17:03:54 -04:00
Michael Santos
f25c9377bb Correct type for version/1,2
Calls now have an infinite timeout.
2014-07-09 10:07:36 -04:00
Michael Santos
ec1a87b4f4 specs: add types for file descriptors
Distinguish fd's and sets of fd's from other lists of integers.
2014-07-08 18:00:31 -04:00
Michael Santos
ef3faf49ca Specify OS PID return values 2014-07-07 10:05:51 -04:00
Michael Santos
bc159a5902 Specify type for OS pids 2014-07-06 11:16:23 -04:00
Michael Santos
3b2299e08c Add a unique type for the port
Clarify the intent of the functions by creating a type for the PID
returned by the port gen_server.
2014-07-05 10:29:53 -04:00
Michael Santos
4fe70865fa spec: alcove_cgroup:supported/1,2 2014-07-04 10:01:52 -04:00
Michael Santos
58b5edcfe5 spec: audit_arch/0 2014-07-03 16:47:45 -04:00
Michael Santos
ea2eff19fe spec: syscall_define/2,3 2014-07-02 15:56:21 -04:00
Michael Santos
f7b3478e0b typespec: rmdir/2,3 2014-06-30 10:04:09 -04:00
Michael Santos
e4053c4482 spec: file_define/2,3 2014-06-29 10:25:09 -04:00
Michael Santos
4c61d9f025 spec: eof/2,3 2014-06-28 10:16:27 -04:00
Michael Santos
43030ab2a6 setopt/3,4: clean up
Cleanup of the setopt function:

* use an unsigned integer for holding the arg

* add a typespec for setopt/3,4.

* change the return value to true/false

Previously, if an unknown option was passed to setopt, the process would
crash with badarg. Reserve badarg for wrong types and return a value to
the caller.

inet:getopts/setopts take a list of options. If any of the options are
invalid, {error,einval} is returned to the caller. The valid options are
not changed.

alcove:getopt/2,3 returns an unsigned integer or false if the option is
not supported.

alcove:getopt,setopt will (should?) never fail if a valid argument is
used. So replying with an ok tuple, like the inet functions, is not necessary.

So setopt could more exactly return 'ok' and 'invalid' or 'not_found'
(diverging from getopt) or it could follow getopt and return ok/false,
which, to be more consistent, should be a boolean.
2014-06-27 10:25:29 -04:00
Michael Santos
2ea703cd2e typespec: getopt/2,3 2014-06-26 16:42:59 -04:00
Michael Santos
62c9795afa spec: signal_constant 2014-06-25 15:24:13 -04:00
Michael Santos
6187cae070 typespec: select 2014-06-24 16:37:13 -04:00
Michael Santos
dae8d5428e typespec: lseek 2014-06-23 16:23:45 -04:00