rump: import librumpclient

This commit is contained in:
Jean-Baptiste Boric 2016-11-26 12:07:53 +01:00
parent dc0601aab4
commit 377739cc06
10 changed files with 1648 additions and 1 deletions

View File

@ -872,6 +872,9 @@
./usr/lib/librump.so.0.0 minix-base rump
./usr/lib/librump.so.0 minix-base rump
./usr/lib/librump.so minix-base rump
./usr/lib/librumpclient.so.0.0 minix-base rump
./usr/lib/librumpclient.so.0 minix-base rump
./usr/lib/librumpclient.so minix-base rump
./usr/lib/librumpdev.so.0.0 minix-base rump
./usr/lib/librumpdev.so.0 minix-base rump
./usr/lib/librumpdev.so minix-base rump

View File

@ -1724,6 +1724,7 @@
./usr/include/rump/rump_namei.h minix-comp rump
./usr/include/rump/rump_syscalls.h minix-comp rump
./usr/include/rump/rump_syscalls_compat.h minix-comp rump
./usr/include/rump/rumpclient.h minix-comp rump
./usr/include/rump/rumpdefs.h minix-comp rump
./usr/include/rump/rumperr.h minix-comp rump
./usr/include/rump/rumperrno2host.h minix-comp rump
@ -2304,6 +2305,8 @@
./usr/lib/librmt.a minix-comp
./usr/lib/librump.a minix-comp rump
./usr/lib/librump_pic.a minix-comp rump
./usr/lib/librumpclient.a minix-comp rump
./usr/lib/librumpclient_pic.a minix-comp rump
./usr/lib/librumpdev.a minix-comp rump
./usr/lib/librumpdev_audio.a minix-comp rump
./usr/lib/librumpdev_audio_pic.a minix-comp rump

View File

@ -2716,6 +2716,7 @@
./usr/man/man3/rump.3 minix-man rump
./usr/man/man3/rump_etfs.3 minix-man rump
./usr/man/man3/rump_lwproc.3 minix-man rump
./usr/man/man3/rumpclient.3 minix-man rump
./usr/man/man3/ruserok.3 minix-man
./usr/man/man3/saslc.d.3 minix-man crypto
./usr/man/man3/saslc_alloc.3 minix-man crypto

View File

@ -99,7 +99,7 @@ SUBDIR+= libc_vfp
.endif
.endif
.if (${MKRUMP} != "no")
#SUBDIR+= librumpclient
SUBDIR+= librumpclient
.endif
.if (${MKSKEY} != "no")
SUBDIR+= libskey

View File

@ -0,0 +1,40 @@
# $NetBSD: Makefile,v 1.10 2013/09/10 17:39:10 pooka Exp $
#
.PATH: ${.CURDIR}/../../sys/rump/librump/rumpkern
LIB= rumpclient
USE_SHLIBDIR= yes
MAN= rumpclient.3
.if defined(__MINIX)
RUMPUSER_THREADS=fiber
.endif
.include <bsd.own.mk>
INCS= rumpclient.h
INCSDIR= /usr/include/rump
.for lib in ${RUMPCLIENT_EXTERNAL_DPLIBS}
LIBDO.${lib}= _external
LIBDPLIBS+= ${lib} lib
.endfor
CPPFLAGS+= -DRUMP_CLIENT
CPPFLAGS+= -I${.OBJDIR} -I${.CURDIR}
CPPFLAGS+= -I${.CURDIR}/../librumpuser
SRCS= rumpclient.c
SRCS+= rump_syscalls.c
CLEANFILES+= srcsys
COPTS.rump_syscalls.c+= -fno-strict-aliasing
.if !make(obj) && !make(clean) && !make(cleandir)
.BEGIN:
@rm -f srcsys
@ln -s ${NETBSDSRCDIR}/sys/sys srcsys
.endif
.include <bsd.lib.mk>

View File

@ -0,0 +1,204 @@
.\" $NetBSD: rumpclient.3,v 1.3 2013/03/08 08:30:44 wiz Exp $
.\"
.\" Copyright (c) 2011 Antti Kantee. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd February 16, 2011
.Dt RUMPCLIENT 3
.Os
.Sh NAME
.Nm rumpclient
.Nd rump client library
.Sh LIBRARY
.Lb rumpclient
.Sh SYNOPSIS
.In rump/rumpclient.h
.In rump/rump_syscalls.h
.Ft int
.Fn rumpclient_init
.Ft pid_t
.Fn rumpclient_fork
.Ft pid_t
.Fn rumpclient_vfork
.Ft struct rumpclient_fork *
.Fn rumpclient_prefork
.Ft int
.Fn rumpclient_fork_init "struct rumpclient_fork *rfp"
.Ft void
.Fn rumpclient_fork_cancel "struct rumpclient_fork *rfp"
.Ft int
.Fn rumpclient_exec "const char *path" "char *const argv[]" "char *const envp[]"
.Ft int
.Fn rumpclient_daemon "int nochdir" "int noclose"
.Ft void
.Fn rumpclient_setconnretry "time_t retrytime"
.Ft int
.Fo rumpclient_syscall
.Fa "int num" "const void *sysarg" "size_t argsize" "register_t *retval"
.Fc
.Sh DESCRIPTION
.Nm
is the clientside implementation of the
.Xr rump_sp 7
facility.
It can be used to connect to a rump kernel server and make system call
style requests.
.Pp
Every connection to a rump kernel server creates a new process
context in the rump kernel.
By default a process is inherited from init, but through existing
connections and the forking facility offered by
.Nm
it is possible to form process trees.
.Bl -tag -width xxxx
.It Fn rumpclient_init
Initialize
.Nm .
The server address is determined from the environment variable
.Ev RUMP_SERVER
according to syntax described in
.Xr rump_sp 7 .
The new process is registered to the rump kernel with the command
name from
.Xr getprogname 3 .
.It Fn rumpclient_fork
Fork a rump client process.
This also causes a host process fork via
.Xr fork 2 .
The child will have a copy of the parent's rump kernel file descriptors.
.It Fn rumpclient_vfork
Like above, but the host uses
.Xr vfork 2 .
.It Fn rumpclient_prefork
Low-level routine which instructs the rump kernel that the current
process is planning to fork.
The routine returns a
.Pf non- Dv NULL
cookie if successful.
.It Fn rumpclient_fork_init rfp
Low-level routine which works like
.Fn rumpclient_init ,
with the exception that it uses the
.Ar rfp
context created by a call to
.Fn rumpclient_prefork .
This is typically called from the child of a
.Xr fork 2
call.
.It Fn rumpclient_fork_cancel rfp
Cancel previously initiated prefork context.
This is useful for error handling in case a full fork could not
be carried through.
.It Fn rumpclient_exec path argv envp
This call is a
.Nm
wrapper around
.Xr execve 2 .
The wrapper makes sure that the rump kernel process context stays
the same in the newly executed program.
This means that the rump kernel PID remains the same and the same
rump file descriptors are available (apart from ones which
were marked with
.Dv FD_CLOEXEC ) .
.Pp
It should be noted that the newly executed program must call
.Fn rumpclient_init
before any other rump kernel communication can take place.
The wrapper cannot do it because it no longer has program control.
However, since all rump clients call the init routine,
this should not be a problem.
.It Fn rumpclient_daemon noclose nochdir
This function performs the equivalent of
.Xr daemon 3 ,
but also ensures that the internal call to
.Xr fork 2
is handled properly.
This routine is provided for convenience.
.It Fn rumpclient_setconnretry retrytime
Set the timeout for how long the client attempts to reconnect to
the server in case of a broken connection.
After the timeout expires the client will return a failure
for that particular request.
It is critical to note that after a restablished connection the
rump kernel context will be that of a newly connected client.
This means all previous kernel state such as file descriptors
will be lost.
It is largely up to a particular application if this has impact
or not.
For example, web browsers tend to recover fairly smoothly from a
kernel server reconnect, while
.Xr sshd 8
gets confused if its sockets go missing.
.Pp
If
.Ar retrytime
is a positive integer, it means the number of seconds for which
reconnection will be attempted.
The value 0 means that reconnection will not be attempted, and all
subsequent operations will return the errno
.Er ENOTCONN .
.Pp
Additionally, the following special values are accepted:
.Bl -tag -width xxxx
.It Dv RUMPCLIENT_RETRYCONN_INFTIME
Attempt reconnection indefinitely.
.It Dv RUMPCLIENT_RETRYCONN_ONCE
Attempt reconnect exactly once.
What this precisely means depends on the situation: e.g. getting
.Er EHOSTUNREACH
immediately or the TCP connection request timeouting are considered
to be one retry.
.It Dv RUMPCLIENT_RETRYCONN_DIE
In case of a broken connection is detected at runtime, call
.Xr exit 3 .
This is useful for example in testing.
It ensures that clients are killed immediately when they attempt
to communicate with a halted server.
.El
.It Fn rumpclient_syscall num sysarg argsize retval
Execute an "indirect" system call.
In the normal case system calls are executed through the interfaces in
.In rump/rump_syscalls.h
(for example
.Fn rump_sys_read fd buf nbytes ) .
This interface allows calling the server with pre-marshalled arguments.
.El
.Pp
Additionally, all of the supported rump system calls are available
through this library.
See
.In rump/rump_syscalls.h
for a list.
.Sh RETURN VALUES
.Nm
routines return \-1 in case of error and set errno.
In case of success a non-negative integer is returned, where applicable.
.Sh SEE ALSO
.Xr rump_server 1 ,
.Xr rump 3 ,
.Xr rump_sp 7
.Sh CAVEATS
Interfaces for a cryptographically authenticated client-server
handshake do not currently exist.
This can be worked around with e.g. host access control and an ssh
tunnel.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
/* $NetBSD: rumpclient.h,v 1.15 2013/01/20 15:23:21 pooka Exp $ */
/*-
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _RUMP_RUMPCLIENT_H_
#define _RUMP_RUMPCLIENT_H_
#include <sys/types.h>
#if !defined(__returns_twice)
#ifdef __GNUC__
#define __returns_twice __attribute__((__returns_twice__))
#else /* __GNUC__ */
#define __returns_twice
#endif /* !__GNUC__ */
#endif /* !__returns_twice */
#if defined(__sun__) && !defined(RUMP_REGISTER_T)
#define RUMP_REGISTER_T long
typedef RUMP_REGISTER_T register_t;
#endif
struct rumpclient_fork;
#define rumpclient_vfork() rumpclient__dofork(vfork)
#ifdef __BEGIN_DECLS
__BEGIN_DECLS
#elif defined(__cplusplus)
extern "C" {
#endif
int rumpclient_syscall(int, const void *, size_t, register_t *);
int rumpclient_init(void);
struct rumpclient_fork *rumpclient_prefork(void);
int rumpclient_fork_init(struct rumpclient_fork *);
void rumpclient_fork_cancel(struct rumpclient_fork *);
void rumpclient_fork_vparent(struct rumpclient_fork *);
pid_t rumpclient_fork(void);
int rumpclient_exec(const char *, char *const [], char *const[]);
int rumpclient_daemon(int, int);
#define RUMPCLIENT_RETRYCONN_INFTIME ((time_t)-1)
#define RUMPCLIENT_RETRYCONN_ONCE ((time_t)-2)
#define RUMPCLIENT_RETRYCONN_DIE ((time_t)-3)
void rumpclient_setconnretry(time_t);
enum rumpclient_closevariant {
RUMPCLIENT_CLOSE_CLOSE,
RUMPCLIENT_CLOSE_DUP2,
RUMPCLIENT_CLOSE_FCLOSEM
};
int rumpclient__closenotify(int *, enum rumpclient_closevariant);
/*
* vfork needs to be implemented as an inline to make everything
* run in the caller's stackframe.
*/
static __attribute__((__always_inline__)) __returns_twice inline pid_t
rumpclient__dofork(pid_t (*forkfn)(void))
{
struct rumpclient_fork *rf;
pid_t pid;
int childran = 0;
if (!(rf = rumpclient_prefork()))
return -1;
switch ((pid = forkfn())) {
case -1:
rumpclient_fork_cancel(rf);
break;
case 0:
childran = 1;
if (rumpclient_fork_init(rf) == -1)
pid = -1;
break;
default:
/* XXX: multithreaded vforker? do they exist? */
if (childran)
rumpclient_fork_vparent(rf);
break;
}
return pid;
}
#ifdef __END_DECLS
__END_DECLS
#elif defined(__cplusplus)
}
#endif
#endif /* _RUMP_RUMPCLIENT_H_ */

View File

@ -0,0 +1,4 @@
# $NetBSD: shlib_version,v 1.1 2010/11/04 21:01:29 pooka Exp $
#
major=0
minor=0

View File

@ -48,7 +48,12 @@
#include <inttypes.h>
#include <limits.h>
#include <poll.h>
#if defined(__minix)
#define _MTHREADIFY_PTHREADS
#include <minix/mthread.h>
#else
#include <pthread.h>
#endif
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>