Commit Graph

28 Commits

Author SHA1 Message Date
Andrew Bettison
64286bd5e6 Absorb ENOTRECOVERABLE in read_nonblock()
Already absorbs EINTR and EAGAIN.  The monitor interface ignores this
error code for reasons unexplained, and now that it uses read_nonblock()
instead of read(), this preserves its behaviour.
2016-09-06 12:07:00 +09:30
Jeremy Lakeman
64eb4f426b Handle stream EOF without entering an infinite poll loop 2016-01-27 16:27:02 +10:30
Andrew Bettison
21f51965c1 Overhaul Makefile and header files
Make .o files in separate subdirectories for servald and library
Factor struct __sourceloc and __WHENCE__ from "log.h" into "whence.h"
Factor sid_t etc from "serval.h" into "serval_types.h"
Factor rhizome_bid_t etc from "rhizome.h" into "rhizome_types.h"
Do not include "serval.h" in library sources
Add log_stderr.c and logMessage.c for stand-alone executables
2014-05-26 15:36:26 +09:30
Andrew Bettison
4428a76379 Use ssize_t for read(2) and write(2) return value
Test for errors using == -1 not < 0, and cast to (size_t) subsequently

Fixes some -Wsign-compare warnings
2013-12-10 17:21:35 +10:30
Andrew Bettison
42ab9aec4c Merge branch 'development' into 'naf4'
Remove two redundant calls to rhizome_retrieve_manifest() in meshms.c,
revealed by an assert() in the stricter manifest parsing code

Fix header files included by socket.h
2013-12-02 17:17:47 +10:30
Andrew Bettison
8db5f9c14a Merge branch 'anyservice' into 'development'
Allows any valid "service" manifest field in the "rhizome add file"
command

Many improvements in Rhizome manifest parsing; stricter manifest syntax
rules (no comment or blank lines, field names must be alphanumeric
identifiers), faster preliminary manifest inspection when receiving
manifest advertisements or syncing manifests

The 'development' branch introduces "struct socket_address" which
coincidentally fixed the recently encountered Linux kernel 3.12
recvmsg(2) EINVAL problem, so that 'rhizomeprotocol' tests which fail on
the 'anyservice' branch will pass after this merge
2013-12-01 05:44:01 +10:30
Andrew Bettison
72482b3427 Better error logging for recvwithttl() 2013-12-01 05:13:33 +10:30
Andrew Bettison
dafa1fc186 Improve struct socket_address
Add struct sockaddr_in 'inet' union field, rename 'addr_un' union field
to 'local'

Replace recvwithttl()'s (struct sockaddr *) and socklen_t pair of args
with single (struct socket_address *) arg
2013-11-29 12:56:59 +10:30
Andrew Bettison
92253ca97d Revive config_test.c
Move config-dependent code (recvwithttl) from net.c to mdp_net.c (new)

Move log-implementation-independent code from log.c to log_util.c (new)

Build config_test binary in Makefile
2013-11-21 16:05:17 +10:30
Andrew Bettison
ba0ab14c69 Clean up inclusion of <netinet/in.h>
Make all #include <netinet/in.h> conditional upon HAVE_NETINET_IN_H

Remove unnecessary #include <netinet/in.h> from source files

Reformat include block in "serval.h" for readability
2013-11-12 11:39:06 +10:30
Andrew Bettison
0437e4adbb Add writev_all() function
Use it in rhizome_write_manifest_file() instead of two separate write(2)
system calls or buffered stdio.
2013-10-12 03:54:18 +10:30
Andrew Bettison
97cbebc91e Issue #11: improve types in file i/o functions
Use open(2)/read(2)/write(2) instead of fopen(3)/fread(3)/fwrite(3) in
several places to avoid unnecessary buffering

Fix a bug in Rhizome HTTP add's handling of unconfigured manifest
template file

Improve some debug and error logging for file i/o
2013-10-11 16:24:51 +10:30
Andrew Bettison
ae61a4f35c Issue #20: Make abstract sockets work
Finish the work started by Daniel in 2012, by using abstract local
AF_UNIX sockets on platforms that support them (Linux, Android).

Fix all sorts of bugs and issues that prevented the existing MDP and
Monitor client and server code from working with abstract socket names.
2013-09-19 17:26:06 +09:30
Jeremy Lakeman
3855ff35c4 Clean up string formatting for 64bit compilation 2013-07-15 09:59:24 +09:30
Andrew Bettison
cfe4da687c New hton_in_addr() function
To silence warnings in struct in_addr assignments on Solaris, whose struct
in_addr definition is a monstrosity.
2013-02-05 16:56:37 +10:30
Andrew Bettison
5985df751d Overhaul debug flags
Replace debugflags_t and DEBUG_XXX bit masks with config schema "debug.xxx"
entries.

No more support for "debug.all".
2012-12-11 15:59:46 +10:30
Andrew Bettison
d3c2205d44 Add os.c and "os.h", replacing mkdirs.c
The new header "os.h" defines a supplemental API around existing basic
operating system services (system calls and standard library functions).

Moved some function prototypes from serval.h and net.h into os.h.

This allows non-servald executables to take advantage of this API without
having to include serval.h and bringing in all the other servald link-time
baggage.
2012-12-04 10:12:35 +10:30
Andrew Bettison
0e435683f7 Move toprint functions from log.h to str.h
Move alloca_sockaddr() to strbuf_helpers.h

So that stand-alone executables can use them without pulling in the entire
logging framework.
2012-11-20 18:10:08 +10:30
Andrew Bettison
259b9a9d24 Logging/debug improvements: __WHENCE__, __whence
Introduce __WHENCE__ macro and a block comment in log.h explaining it.

In "primitive" kinds of functions, rename 'whence' arguments to '__whence' and
use WHYF(), WARNF(), DEBUGF() macros instead of calling logMessage() directly.
2012-10-16 17:00:03 +10:30
Jeremy Lakeman
7c73ca7a78 Finish test and implementation of directory service 2012-09-18 12:30:15 +09:30
Jeremy Lakeman
6483d9e0ae Split client mdp functions so they can be built separately 2012-09-14 11:47:48 +09:30
Andrew Bettison
27a0a6eeb5 Introduce struct __sourceloc
Replaces (const char *file, unsigned int line, const char *function) arguments
to all logging functions, simplifies malloc/free tracking code in
overlay_buffer.c and Rhizome manifest alloc/free tracking in rhizome_bundle.c.

Use __HERE__ macro instead of (__FILE__, __LINE__, __FUNCTION__) everywhere.

Special __NOWHERE__ macro is equivalent to (NULL, 0, NULL).

Declare net.c functions in new "net.h" header, so log.c doesn't have to pull
in the entire "serval.h" just to use write_str().

Facilitates progress on issue #2.
2012-08-23 12:31:07 +09:30
Andrew Bettison
3b44bb6e58 More progress on dnahelper 2012-07-19 17:59:45 +09:30
Andrew Bettison
dcf7209304 Add read_nonblock() function
Deal with platforms where EWOULDBLOCK != EAGAIN
2012-07-13 11:04:50 +09:30
Andrew Bettison
a15a9146c3 Improve toprint() and alloca_toprint() 2012-07-11 14:17:53 +09:30
Andrew Bettison
e8eab5b27e Improve diagnostics from write_all(), write_nonblock() etc.
Add toprint() function and alloca_toprint() macro.
2012-07-10 19:57:56 +09:30
Andrew Bettison
7c2090e61c Improve error reports for write_str() etc.
Now write_str(), write_nonblock(), write_all(), set_nonblock() etc. report the
file/line/function of their caller, rather than the function in net.c.  Done
using macros, similar in style to WHY() etc.
2012-07-10 18:51:41 +09:30
Andrew Bettison
86eb482ed9 Replace macros with functions
SET_NONBLOCKING(), SET_BLOCKING(), WRITE_STR() are now set_nonblock(),
set_block() and write_str() respectively, all of which log an error before
returning -1.  There are other useful methods: write_all() treats anything less
than all bytes written as an error; write_nonblock() treats EAGAIN and EINTR as
zero bytes written, and a combination: write_all_nonblock().
2012-07-10 16:33:39 +09:30