CVS commit: src/lib/librumpclient

2017-05-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu May 11 18:44:50 UTC 2017

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
make it the same as rump.h


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.16 src/lib/librumpclient/rumpclient.h:1.17
--- src/lib/librumpclient/rumpclient.h:1.16	Thu May 11 13:47:22 2017
+++ src/lib/librumpclient/rumpclient.h	Thu May 11 14:44:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.16 2017/05/11 17:47:22 christos Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.17 2017/05/11 18:44:50 christos Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -39,8 +39,11 @@
 #endif /* !__returns_twice */
 
 #if !defined(RUMP_REGISTER_T)
-#define RUMP_REGISTER_T long
+# define RUMP_REGISTER_T long
+# if !defined(_KERNEL) && !defined(_KMEMUSER) &&  \
+!defined(_KERNTYPES) && !defined(_STANDALONE)
 typedef RUMP_REGISTER_T register_t;
+# endif
 #endif
 
 struct rumpclient_fork;



CVS commit: src/lib/librumpclient

2017-05-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu May 11 17:47:22 UTC 2017

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
Don't depend on stars in order to define things.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.15 src/lib/librumpclient/rumpclient.h:1.16
--- src/lib/librumpclient/rumpclient.h:1.15	Sun Jan 20 10:23:21 2013
+++ src/lib/librumpclient/rumpclient.h	Thu May 11 13:47:22 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.15 2013/01/20 15:23:21 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.16 2017/05/11 17:47:22 christos Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -38,7 +38,7 @@
 #endif /* !__GNUC__ */
 #endif /* !__returns_twice */
 
-#if defined(__sun__) && !defined(RUMP_REGISTER_T)
+#if !defined(RUMP_REGISTER_T)
 #define RUMP_REGISTER_T long
 typedef RUMP_REGISTER_T register_t;
 #endif



CVS commit: src/lib/librumpclient

2016-09-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep  6 07:12:48 UTC 2016

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Fix DPRINTF format


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.65 src/lib/librumpclient/rumpclient.c:1.66
--- src/lib/librumpclient/rumpclient.c:1.65	Sat Jan 17 19:34:50 2015
+++ src/lib/librumpclient/rumpclient.c	Tue Sep  6 07:12:48 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.65 2015/01/17 19:34:50 justin Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.66 2016/09/06 07:12:48 martin Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -50,7 +50,7 @@
 #define USE_SIGNALFD
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.65 2015/01/17 19:34:50 justin Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.66 2016/09/06 07:12:48 martin Exp $");
 
 #include 
 #include 
@@ -590,8 +590,9 @@ rumpclient_syscall(int sysnum, const voi
 		goto out;
 
 	resp = rdata;
-	DPRINTF(("rumpsp syscall_resp: syscall %d error %d, rv: %d/%d\n",
-	sysnum, rv, resp->rsys_retval[0], resp->rsys_retval[1]));
+	DPRINTF(("rumpsp syscall_resp: syscall %d error %d, rv: %ld/%ld\n",
+	sysnum, rv, (unsigned long)resp->rsys_retval[0],
+	(unsigned long)resp->rsys_retval[1]));
 
 	memcpy(retval, &resp->rsys_retval, sizeof(resp->rsys_retval));
 	rv = resp->rsys_error;



CVS commit: src/lib/librumpclient

2015-01-17 Thread Justin Cormack
Module Name:src
Committed By:   justin
Date:   Sat Jan 17 19:34:50 UTC 2015

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Modern Android SDK does not need special cases


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.64 src/lib/librumpclient/rumpclient.c:1.65
--- src/lib/librumpclient/rumpclient.c:1.64	Sat Dec 13 17:18:55 2014
+++ src/lib/librumpclient/rumpclient.c	Sat Jan 17 19:34:50 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.64 2014/12/13 17:18:55 justin Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.65 2015/01/17 19:34:50 justin Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -46,11 +46,11 @@
 defined(__DragonFly__) || defined(__OpenBSD__)
 #define USE_KQUEUE
 #endif
-#if defined(__linux__) && !defined(__ANDROID__)
+#if defined(__linux__)
 #define USE_SIGNALFD
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.64 2014/12/13 17:18:55 justin Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.65 2015/01/17 19:34:50 justin Exp $");
 
 #include 
 #include 
@@ -86,17 +86,9 @@ int	(*host_socket)(int, int, int);
 int	(*host_close)(int);
 int	(*host_connect)(int, const struct sockaddr *, socklen_t);
 int	(*host_fcntl)(int, int, ...);
-#ifdef __ANDROID__
-int	(*host_poll)(struct pollfd *, nfds_t, long);
-#else
 int	(*host_poll)(struct pollfd *, nfds_t, int);
-#endif
 ssize_t	(*host_read)(int, void *, size_t);
-#ifdef __ANDROID__
-int	(*host_sendmsg)(int, const struct msghdr *, unsigned int);
-#else
 ssize_t (*host_sendmsg)(int, const struct msghdr *, int);
-#endif
 int	(*host_setsockopt)(int, int, int, const void *, socklen_t);
 int	(*host_dup)(int);
 



CVS commit: src/lib/librumpclient

2014-12-13 Thread Justin Cormack
Module Name:src
Committed By:   justin
Date:   Sat Dec 13 17:18:55 UTC 2014

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Always use kqueue for BSDs in librumpclient

Tested now on the others


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.63 src/lib/librumpclient/rumpclient.c:1.64
--- src/lib/librumpclient/rumpclient.c:1.63	Mon Dec  8 01:10:07 2014
+++ src/lib/librumpclient/rumpclient.c	Sat Dec 13 17:18:55 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.63 2014/12/08 01:10:07 justin Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.64 2014/12/13 17:18:55 justin Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -32,8 +32,7 @@
 #include 
 
 /*
- * We use kqueue on NetBSD and FreeBSD, poll elsewhere.  We could
- * use kqueue on other BSD's too, but I haven't tested those.  We
+ * We use kqueue on the BSDs, poll elsewhere.  We
  * want to use kqueue because it will give us the ability to get signal
  * notifications but defer their handling to a stage where we do not
  * hold the communication lock.  Taking a signal while holding on to
@@ -43,14 +42,15 @@
  * response from the server.
  */
 
-#if defined(__NetBSD__) || defined(__FreeBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || \
+defined(__DragonFly__) || defined(__OpenBSD__)
 #define USE_KQUEUE
 #endif
 #if defined(__linux__) && !defined(__ANDROID__)
 #define USE_SIGNALFD
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.63 2014/12/08 01:10:07 justin Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.64 2014/12/13 17:18:55 justin Exp $");
 
 #include 
 #include 



CVS commit: src/lib/librumpclient

2014-12-07 Thread Justin Cormack
Module Name:src
Committed By:   justin
Date:   Mon Dec  8 01:10:07 UTC 2014

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Use kqueue in librumpclient for FreeBSD too


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.62 src/lib/librumpclient/rumpclient.c:1.63
--- src/lib/librumpclient/rumpclient.c:1.62	Fri Apr 25 12:20:12 2014
+++ src/lib/librumpclient/rumpclient.c	Mon Dec  8 01:10:07 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.62 2014/04/25 12:20:12 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.63 2014/12/08 01:10:07 justin Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -32,7 +32,7 @@
 #include 
 
 /*
- * We use kqueue on NetBSD, poll elsewhere.  Theoretically we could
+ * We use kqueue on NetBSD and FreeBSD, poll elsewhere.  We could
  * use kqueue on other BSD's too, but I haven't tested those.  We
  * want to use kqueue because it will give us the ability to get signal
  * notifications but defer their handling to a stage where we do not
@@ -43,14 +43,14 @@
  * response from the server.
  */
 
-#ifdef __NetBSD__
+#if defined(__NetBSD__) || defined(__FreeBSD__)
 #define USE_KQUEUE
 #endif
 #if defined(__linux__) && !defined(__ANDROID__)
 #define USE_SIGNALFD
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.62 2014/04/25 12:20:12 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.63 2014/12/08 01:10:07 justin Exp $");
 
 #include 
 #include 
@@ -102,8 +102,13 @@ int	(*host_dup)(int);
 
 #ifdef USE_KQUEUE
 int	(*host_kqueue)(void);
+#ifdef __NetBSD__
 int	(*host_kevent)(int, const struct kevent *, size_t,
 		   struct kevent *, size_t, const struct timespec *);
+#else
+int	(*host_kevent)(int, const struct kevent *, int,
+		   struct kevent *, int, const struct timespec *);
+#endif
 #endif
 
 #ifdef USE_SIGNALFD
@@ -925,11 +930,15 @@ rumpclient_init(void)
 
 #ifdef USE_KQUEUE
 	FINDSYM(kqueue)
+#ifdef __NetBSD__
 #if !__NetBSD_Prereq__(5,99,7)
 	FINDSYM(kevent)
 #else
 	FINDSYM2(kevent,_sys___kevent50)
 #endif
+#else
+	FINDSYM(kevent)
+#endif
 #endif /* USE_KQUEUE */
 
 #ifdef USE_SIGNALFD



CVS commit: src/lib/librumpclient

2014-04-25 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Apr 25 12:20:12 UTC 2014

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
pretend to handle the poll return value for -Wunused-but-set


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.61 src/lib/librumpclient/rumpclient.c:1.62
--- src/lib/librumpclient/rumpclient.c:1.61	Thu Apr  3 17:11:35 2014
+++ src/lib/librumpclient/rumpclient.c	Fri Apr 25 12:20:12 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.61 2014/04/03 17:11:35 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.62 2014/04/25 12:20:12 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -50,7 +50,7 @@
 #define USE_SIGNALFD
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.61 2014/04/03 17:11:35 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.62 2014/04/25 12:20:12 pooka Exp $");
 
 #include 
 #include 
@@ -292,7 +292,7 @@ cliwaitresp(struct spclient *spc, struct
 pfd[1].events = POLLIN;
 
 rv = host_poll(pfd, 2, -1);
-if (pfd[1].revents & POLLIN) {
+if (rv >= 1 && pfd[1].revents & POLLIN) {
 	dosig = 1;
 	goto cleanup;
 }



CVS commit: src/lib/librumpclient

2014-04-03 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Apr  3 17:11:35 UTC 2014

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Make sure holyfd is -1 when rumpclient_init() is called for
the first time after fork to prevent fd 0 from being closed.

should fix test failures, thanks to martin for the prod


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.60 src/lib/librumpclient/rumpclient.c:1.61
--- src/lib/librumpclient/rumpclient.c:1.60	Wed Apr  2 17:09:23 2014
+++ src/lib/librumpclient/rumpclient.c	Thu Apr  3 17:11:35 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.60 2014/04/02 17:09:23 justin Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.61 2014/04/03 17:11:35 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -50,7 +50,7 @@
 #define USE_SIGNALFD
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.60 2014/04/02 17:09:23 justin Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.61 2014/04/03 17:11:35 pooka Exp $");
 
 #include 
 #include 
@@ -121,7 +121,7 @@ static struct spclient clispc = {
 	.spc_fd = -1,
 };
 
-static int holyfd;
+static int holyfd = -1;
 static sigset_t fullset;
 
 static int doconnect(void);
@@ -878,10 +878,9 @@ rumpclient_init(void)
 	if (init_done == (mypid = getpid()))
 		return 0;
 
-	/* kq does not traverse fork() */
 #ifdef USE_KQUEUE
-	if (init_done != 0)
-		holyfd = -1;
+	/* kq does not traverse fork() */
+	holyfd = -1;
 #endif
 	init_done = mypid;
 



CVS commit: src/lib/librumpclient

2014-04-02 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Apr  2 15:04:19 UTC 2014

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
fix build on NetBSD.  also, prevent fd leak in error path


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.58 src/lib/librumpclient/rumpclient.c:1.59
--- src/lib/librumpclient/rumpclient.c:1.58	Wed Apr  2 14:48:03 2014
+++ src/lib/librumpclient/rumpclient.c	Wed Apr  2 15:04:19 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.58 2014/04/02 14:48:03 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.59 2014/04/02 15:04:19 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -50,7 +50,7 @@
 #define USE_SIGNALFD
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.58 2014/04/02 14:48:03 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.59 2014/04/02 15:04:19 pooka Exp $");
 
 #include 
 #include 
@@ -712,7 +712,9 @@ makeholyfd(void)
 	EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
 	if (host_kevent(fd, kev, NSIG+1, NULL, 0, NULL) == -1) {
 		ERRLOG(("rump_sp: kevent() failed"));
+		host_close(fd);
 		return -1;
+	}
 
 	return fd;
 }



CVS commit: src/lib/librumpclient

2014-04-02 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Apr  2 14:48:04 UTC 2014

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
On Linux, poll signalfd() when waiting for a kernel response.
This allows the same type of race-free handling of signals as kqueue()
allows on NetBSD.  One of the noticeable things is that you can now
interrupt rumprun ping mid-interval on Linux.

per suggestion from Justin Cormack


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.57 src/lib/librumpclient/rumpclient.c:1.58
--- src/lib/librumpclient/rumpclient.c:1.57	Wed Feb 26 02:03:40 2014
+++ src/lib/librumpclient/rumpclient.c	Wed Apr  2 14:48:03 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.57 2014/02/26 02:03:40 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.58 2014/04/02 14:48:03 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -38,17 +38,19 @@
  * notifications but defer their handling to a stage where we do not
  * hold the communication lock.  Taking a signal while holding on to
  * that lock may cause a deadlock.  Therefore, block signals throughout
- * the RPC when using poll.  This unfortunately means that the normal
- * SIGINT way of stopping a process while it is undergoing rump kernel
- * RPC will not work.  If anyone know which Linux system call handles
- * the above scenario correctly, I'm all ears.
+ * the RPC when using poll.  On Linux, we use signalfd in the same role
+ * as kqueue on NetBSD to be able to take signals while waiting for a
+ * response from the server.
  */
 
 #ifdef __NetBSD__
 #define USE_KQUEUE
 #endif
+#ifdef __linux__
+#define USE_SIGNALFD
+#endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.57 2014/02/26 02:03:40 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.58 2014/04/02 14:48:03 pooka Exp $");
 
 #include 
 #include 
@@ -96,6 +98,12 @@ int	(*host_kevent)(int, const struct kev
 		   struct kevent *, size_t, const struct timespec *);
 #endif
 
+#ifdef USE_SIGNALFD
+#include 
+
+int	(*host_signalfd)(int, const sigset_t *, int);
+#endif
+
 int	(*host_execve)(const char *, char *const[], char *const[]);
 
 #include "sp_common.c"
@@ -105,7 +113,7 @@ static struct spclient clispc = {
 	.spc_fd = -1,
 };
 
-static int kq = -1;
+static int holyfd;
 static sigset_t fullset;
 
 static int doconnect(void);
@@ -237,7 +245,7 @@ cliwaitresp(struct spclient *spc, struct
  * typically we don't have a frame waiting
  * when we come in here, so call kevent now
  */
-rv = host_kevent(kq, NULL, 0,
+rv = host_kevent(holyfd, NULL, 0,
 kev, __arraycount(kev), NULL);
 
 if (__predict_false(rv == -1)) {
@@ -267,13 +275,19 @@ cliwaitresp(struct spclient *spc, struct
  * determine what happens next.
  */
  activity:
-#else /* USE_KQUEUE */
-struct pollfd pfd;
-
-pfd.fd = clispc.spc_fd;
-pfd.events = POLLIN;
+#else /* !USE_KQUEUE */
+struct pollfd pfd[2];
 
-rv = host_poll(&pfd, 1, -1);
+pfd[0].fd = clispc.spc_fd;
+pfd[0].events = POLLIN;
+pfd[1].fd = holyfd;
+pfd[1].events = POLLIN;
+
+rv = host_poll(pfd, 2, -1);
+if (pfd[1].revents & POLLIN) {
+	dosig = 1;
+	goto cleanup;
+}
 #endif /* !USE_KQUEUE */
 
 switch (readframe(spc)) {
@@ -677,6 +691,52 @@ dupgood(int myfd, int mustchange)
 	return myfd;
 }
 
+#if defined(USE_KQUEUE)
+
+static int
+makeholyfd(void)
+{
+	struct kevent kev[NSIG+1];
+	int i, fd;
+
+	/* setup kqueue, we want all signals and the fd */
+	if ((fd = dupgood(host_kqueue(), 0)) == -1) {
+		ERRLOG(("rump_sp: cannot setup kqueue"));
+		return -1;
+	}
+
+	for (i = 0; i < NSIG; i++) {
+		EV_SET(&kev[i], i+1, EVFILT_SIGNAL, EV_ADD|EV_ENABLE, 0, 0, 0);
+	}
+	EV_SET(&kev[NSIG], clispc.spc_fd,
+	EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
+	if (host_kevent(fd, kev, NSIG+1, NULL, 0, NULL) == -1) {
+		ERRLOG(("rump_sp: kevent() failed"));
+		return -1;
+
+	return fd;
+}
+
+#elif defined(USE_SIGNALFD) /* !USE_KQUEUE */
+
+static int
+makeholyfd(void)
+{
+
+	return host_signalfd(-1, &fullset, 0);
+}
+
+#else /* !USE_KQUEUE && !USE_SIGNALFD */
+
+static int
+makeholyfd(void)
+{
+
+	return -1;
+}
+
+#endif
+
 static int
 doconnect(void)
 {
@@ -686,9 +746,9 @@ doconnect(void)
 	int s, error, flags;
 	ssize_t n;
 
-	if (kq != -1)
-		host_close(kq);
-	kq = -1;
+	if (holyfd != -1)
+		host_close(holyfd);
+	holyfd = -1;
 	s = -1;
 
 	if (clispc.spc_fd != -1)
@@ -759,29 +819,7 @@ doconnect(void)
 	clispc.spc_fd = s;
 	clispc.spc_state = SPCSTATE_RUNNING;
 	clispc.spc_reconnecting = 0;
-
-#ifdef USE_KQUEUE
-{
-	struct kevent kev[NSIG+1];
-	int i;
-
-	/* setup kqueue, we want all signals and the fd */
-	if ((kq = dupgood(host_kqueue(), 0)) == -1) {
-		ERRLOG(("rump_sp: canno

CVS commit: src/lib/librumpclient

2014-02-25 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Feb 26 02:03:40 UTC 2014

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Use MAP_ANON|MAP_PRIVATE for anonymous memory mapping,
e.g. Linux gets upset if just MAP_ANON.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.56 src/lib/librumpclient/rumpclient.c:1.57
--- src/lib/librumpclient/rumpclient.c:1.56	Thu Feb 20 00:42:27 2014
+++ src/lib/librumpclient/rumpclient.c	Wed Feb 26 02:03:40 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.56 2014/02/20 00:42:27 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.57 2014/02/26 02:03:40 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -48,7 +48,7 @@
 #define USE_KQUEUE
 #endif
 
-__RCSID("$NetBSD: rumpclient.c,v 1.56 2014/02/20 00:42:27 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.57 2014/02/26 02:03:40 pooka Exp $");
 
 #include 
 #include 
@@ -618,7 +618,7 @@ handlereq(struct spclient *spc)
 		/*LINTED*/
 		maplen = *(size_t *)spc->spc_buf;
 		mapaddr = mmap(NULL, maplen, PROT_READ|PROT_WRITE,
-		MAP_ANON, -1, 0);
+		MAP_ANON|MAP_PRIVATE, -1, 0);
 		if (mapaddr == MAP_FAILED)
 			mapaddr = NULL;
 		DPRINTF(("rump_sp handlereq: anonmmap: %p\n", mapaddr));



CVS commit: src/lib/librumpclient

2013-09-10 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Sep 10 17:39:10 UTC 2013

Modified Files:
src/lib/librumpclient: Makefile

Log Message:
-I../librumpuser is still required for sp_common.c


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/librumpclient/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/Makefile
diff -u src/lib/librumpclient/Makefile:1.9 src/lib/librumpclient/Makefile:1.10
--- src/lib/librumpclient/Makefile:1.9	Tue Sep 10 16:53:06 2013
+++ src/lib/librumpclient/Makefile	Tue Sep 10 17:39:10 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.9 2013/09/10 16:53:06 pooka Exp $
+#	$NetBSD: Makefile,v 1.10 2013/09/10 17:39:10 pooka Exp $
 #
 
 .PATH:	${.CURDIR}/../../sys/rump/librump/rumpkern
@@ -19,6 +19,7 @@ LIBDPLIBS+=	${lib} lib
 
 CPPFLAGS+=	-DRUMP_CLIENT
 CPPFLAGS+=	-I${.OBJDIR} -I${.CURDIR}
+CPPFLAGS+=	-I${.CURDIR}/../librumpuser
 SRCS=		rumpclient.c
 SRCS+=		rump_syscalls.c
 



CVS commit: src/lib/librumpclient

2013-03-08 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Mar  8 08:30:44 UTC 2013

Modified Files:
src/lib/librumpclient: rumpclient.3

Log Message:
Standardize Lb argument.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/librumpclient/rumpclient.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.3
diff -u src/lib/librumpclient/rumpclient.3:1.2 src/lib/librumpclient/rumpclient.3:1.3
--- src/lib/librumpclient/rumpclient.3:1.2	Thu Feb 17 17:03:17 2011
+++ src/lib/librumpclient/rumpclient.3	Fri Mar  8 08:30:44 2013
@@ -1,4 +1,4 @@
-.\" $NetBSD: rumpclient.3,v 1.2 2011/02/17 17:03:17 wiz Exp $
+.\" $NetBSD: rumpclient.3,v 1.3 2013/03/08 08:30:44 wiz Exp $
 .\"
 .\" Copyright (c) 2011 Antti Kantee.  All rights reserved.
 .\"
@@ -30,7 +30,7 @@
 .Nm rumpclient
 .Nd rump client library
 .Sh LIBRARY
-.Lb rumpclient (librumpclient, \-lrumpclient)
+.Lb rumpclient
 .Sh SYNOPSIS
 .In rump/rumpclient.h
 .In rump/rump_syscalls.h



CVS commit: src/lib/librumpclient

2013-01-20 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Jan 20 15:23:21 UTC 2013

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
Provide register_t compat on solarisa.
(would be nice to handle register_t compat internally instead, but the
interface was already exposed in a release)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.14 src/lib/librumpclient/rumpclient.h:1.15
--- src/lib/librumpclient/rumpclient.h:1.14	Thu Jan 17 22:16:59 2013
+++ src/lib/librumpclient/rumpclient.h	Sun Jan 20 15:23:21 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.14 2013/01/17 22:16:59 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.15 2013/01/20 15:23:21 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -38,6 +38,11 @@
 #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)



CVS commit: src/lib/librumpclient

2013-01-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Jan 17 22:16:59 UTC 2013

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
fix the extern "C" stuff


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.13 src/lib/librumpclient/rumpclient.h:1.14
--- src/lib/librumpclient/rumpclient.h:1.13	Thu Jan 17 20:47:44 2013
+++ src/lib/librumpclient/rumpclient.h	Thu Jan 17 22:16:59 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.13 2013/01/17 20:47:44 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.14 2013/01/17 22:16:59 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -44,7 +44,7 @@ struct rumpclient_fork;
 
 #ifdef __BEGIN_DECLS
 __BEGIN_DECLS
-#else
+#elif defined(__cplusplus)
 extern "C" {
 #endif
 
@@ -108,7 +108,7 @@ rumpclient__dofork(pid_t (*forkfn)(void)
 
 #ifdef __END_DECLS
 __END_DECLS
-#else
+#elif defined(__cplusplus)
 }
 #endif
 



CVS commit: src/lib/librumpclient

2013-01-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Jan 17 20:47:44 UTC 2013

Modified Files:
src/lib/librumpclient: rumpclient.c rumpclient.h

Log Message:
Solaris 10 fixes


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/lib/librumpclient/rumpclient.c
cvs rdiff -u -r1.12 -r1.13 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.53 src/lib/librumpclient/rumpclient.c:1.54
--- src/lib/librumpclient/rumpclient.c:1.53	Thu Jan 17 16:29:44 2013
+++ src/lib/librumpclient/rumpclient.c	Thu Jan 17 20:47:44 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.53 2013/01/17 16:29:44 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.54 2013/01/17 20:47:44 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -48,8 +48,7 @@
 #define USE_KQUEUE
 #endif
 
-#include 
-__RCSID("$NetBSD: rumpclient.c,v 1.53 2013/01/17 16:29:44 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.54 2013/01/17 20:47:44 pooka Exp $");
 
 #include 
 #include 
@@ -66,7 +65,6 @@ __RCSID("$NetBSD: rumpclient.c,v 1.53 20
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -159,11 +157,13 @@ send_with_recon(struct spclient *spc, st
 
 			/* check that we aren't over the limit */
 			if (retrytimo > 0) {
-struct timeval tmp;
+time_t tdiff;
 
 gettimeofday(&curtime, NULL);
-timersub(&curtime, &starttime, &tmp);
-if (tmp.tv_sec >= retrytimo) {
+tdiff = curtime.tv_sec - starttime.tv_sec;
+if (starttime.tv_usec > curtime.tv_usec)
+	tdiff--;
+if (tdiff >= retrytimo) {
 	fprintf(stderr, "rump_sp: reconnect "
 	"failed, %lld second timeout\n",
 	(long long)retrytimo);
@@ -844,9 +844,11 @@ rumpclient_init(void)
 	#_syscall_)) == NULL) {	\
 		if (rumphijack_dlsym == rumpclient__dlsym)		\
 			host_##_name_ = _name_; /* static fallback */	\
-		if (host_##_name_ == NULL)\
-			errx(1, "cannot find %s: %s", #_syscall_,	\
+		if (host_##_name_ == NULL) {\
+			fprintf(stderr,"cannot find %s: %s", #_syscall_,\
 			dlerror());	\
+			exit(1);	\
+		}			\
 	}
 #else
 #define FINDSYM2(_name_,_syscall)	\
@@ -1150,6 +1152,10 @@ rumpclient_exec(const char *path, char *
 	return rv;
 }
 
+/*
+ * daemon() is handwritten for the benefit of platforms which
+ * do not support daemon().
+ */
 int
 rumpclient_daemon(int nochdir, int noclose)
 {
@@ -1159,15 +1165,37 @@ rumpclient_daemon(int nochdir, int noclo
 	if ((rf = rumpclient_prefork()) == NULL)
 		return -1;
 
-	if (daemon(nochdir, noclose) == -1) {
-		sverrno = errno;
-		rumpclient_fork_cancel(rf);
-		errno = sverrno;
-		return -1;
+	switch (fork()) {
+	case 0:
+		break;
+	case -1:
+		goto daemonerr;
+	default:
+		_exit(0);
 	}
 
+	if (setsid() == -1)
+		goto daemonerr;
+	if (!nochdir && chdir("/") == -1)
+		goto daemonerr;
+	if (!noclose) {
+		int fd = open("/dev/null", O_RDWR);
+		dup2(fd, 0);
+		dup2(fd, 1);
+		dup2(fd, 2);
+		if (fd > 2)
+			close(fd);
+	}
+
+	/* note: fork is either completed or cancelled by the call */
 	if (rumpclient_fork_init(rf) == -1)
 		return -1;
 
 	return 0;
+
+ daemonerr:
+	sverrno = errno;
+	rumpclient_fork_cancel(rf);
+	errno = sverrno;
+	return -1;
 }

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.12 src/lib/librumpclient/rumpclient.h:1.13
--- src/lib/librumpclient/rumpclient.h:1.12	Fri Aug  3 11:31:34 2012
+++ src/lib/librumpclient/rumpclient.h	Thu Jan 17 20:47:44 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.12 2012/08/03 11:31:34 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.13 2013/01/17 20:47:44 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -42,7 +42,11 @@ struct rumpclient_fork;
 
 #define rumpclient_vfork() rumpclient__dofork(vfork)
 
+#ifdef __BEGIN_DECLS
 __BEGIN_DECLS
+#else
+extern "C" {
+#endif
 
 int rumpclient_syscall(int, const void *, size_t, register_t *);
 int rumpclient_init(void);
@@ -102,6 +106,10 @@ rumpclient__dofork(pid_t (*forkfn)(void)
 	return pid;
 }
 
+#ifdef __END_DECLS
 __END_DECLS
+#else
+}
+#endif
 
 #endif /* _RUMP_RUMPCLIENT_H_ */



CVS commit: src/lib/librumpclient

2013-01-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Jan 17 16:29:44 UTC 2013

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
If the host doesn't support RTLD_NEXT, don't play the dynamic linking game.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.52 src/lib/librumpclient/rumpclient.c:1.53
--- src/lib/librumpclient/rumpclient.c:1.52	Wed Sep 12 12:38:16 2012
+++ src/lib/librumpclient/rumpclient.c	Thu Jan 17 16:29:44 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.52 2012/09/12 12:38:16 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.53 2013/01/17 16:29:44 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -49,7 +49,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.52 2012/09/12 12:38:16 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.53 2013/01/17 16:29:44 pooka Exp $");
 
 #include 
 #include 
@@ -69,7 +69,6 @@ __RCSID("$NetBSD: rumpclient.c,v 1.52 20
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -795,6 +794,7 @@ doinit(void)
 	return 0;
 }
 
+#ifdef RTLD_NEXT
 void *rumpclient__dlsym(void *, const char *);
 void *
 rumpclient__dlsym(void *handle, const char *symbol)
@@ -804,6 +804,7 @@ rumpclient__dlsym(void *handle, const ch
 }
 void *rumphijack_dlsym(void *, const char *)
 __attribute__((__weak__, alias("rumpclient__dlsym")));
+#endif
 
 static pid_t init_done = 0;
 
@@ -837,6 +838,7 @@ rumpclient_init(void)
 	 * sag mir, wo die symbols sind.  zogen fort, der krieg beginnt.
 	 * wann wird man je verstehen?  wann wird man je verstehen?
 	 */
+#ifdef RTLD_NEXT
 #define FINDSYM2(_name_,_syscall_)	\
 	if ((host_##_name_ = rumphijack_dlsym(RTLD_NEXT,		\
 	#_syscall_)) == NULL) {	\
@@ -846,6 +848,10 @@ rumpclient_init(void)
 			errx(1, "cannot find %s: %s", #_syscall_,	\
 			dlerror());	\
 	}
+#else
+#define FINDSYM2(_name_,_syscall)	\
+	host_##_name_ = _name_;
+#endif
 #define FINDSYM(_name_) FINDSYM2(_name_,_name_)
 #ifdef __NetBSD__
 	FINDSYM2(socket,__socket30)



CVS commit: src/lib/librumpclient

2012-09-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Sep 12 12:38:17 UTC 2012

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
attempt to inform user of what the error means


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.51 src/lib/librumpclient/rumpclient.c:1.52
--- src/lib/librumpclient/rumpclient.c:1.51	Wed Aug 29 10:38:53 2012
+++ src/lib/librumpclient/rumpclient.c	Wed Sep 12 12:38:16 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.51 2012/08/29 10:38:53 msaitoh Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.52 2012/09/12 12:38:16 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -49,7 +49,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.51 2012/08/29 10:38:53 msaitoh Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.52 2012/09/12 12:38:16 pooka Exp $");
 
 #include 
 #include 
@@ -877,6 +877,7 @@ rumpclient_init(void)
 
 	if ((p = getenv("RUMP__PARSEDSERVER")) == NULL) {
 		if ((p = getenv("RUMP_SERVER")) == NULL) {
+			fprintf(stderr, "error: RUMP_SERVER not set\n");
 			errno = ENOENT;
 			goto out;
 		}



CVS commit: src/lib/librumpclient

2012-08-29 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Aug 29 10:38:53 UTC 2012

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Remove unused variable. Approved by pooka.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.50 src/lib/librumpclient/rumpclient.c:1.51
--- src/lib/librumpclient/rumpclient.c:1.50	Fri Aug  3 14:52:31 2012
+++ src/lib/librumpclient/rumpclient.c	Wed Aug 29 10:38:53 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.50 2012/08/03 14:52:31 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.51 2012/08/29 10:38:53 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -49,7 +49,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.50 2012/08/03 14:52:31 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.51 2012/08/29 10:38:53 msaitoh Exp $");
 
 #include 
 #include 
@@ -681,7 +681,6 @@ doconnect(void)
 	struct respwait rw;
 	struct rsp_hdr rhdr;
 	char banner[MAXBANNER];
-	struct pollfd pfd;
 	int s, error, flags;
 	ssize_t n;
 
@@ -725,8 +724,6 @@ doconnect(void)
 	if (s == -1)
 		return -1;
 
-	pfd.fd = s;
-	pfd.events = POLLIN;
 	while (host_connect(s, serv_sa, parsetab[ptab_idx].slen) == -1) {
 		if (errno == EINTR)
 			continue;



CVS commit: src/lib/librumpclient

2012-08-03 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Aug  3 14:52:31 UTC 2012

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
force-terminate commname


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.49 src/lib/librumpclient/rumpclient.c:1.50
--- src/lib/librumpclient/rumpclient.c:1.49	Fri Aug  3 11:31:34 2012
+++ src/lib/librumpclient/rumpclient.c	Fri Aug  3 14:52:31 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.49 2012/08/03 11:31:34 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.50 2012/08/03 14:52:31 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -49,7 +49,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.49 2012/08/03 11:31:34 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.50 2012/08/03 14:52:31 pooka Exp $");
 
 #include 
 #include 
@@ -390,6 +390,7 @@ handshake_req(struct spclient *spc, int 
 		} else {
 			static char commname[128];
 
+			memset(commname, 0, sizeof(commname));
 			if (read(fd, commname, sizeof(commname)) > 0) {
 char *n;
 



CVS commit: src/lib/librumpclient

2011-12-16 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Dec 16 23:19:28 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
Request always_inline for rumpclient__dofork, it won't work correctly
for vfork otherwise. Also give it the returns twice attribute to ensure
that the stack tainting is done recursively.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.10 src/lib/librumpclient/rumpclient.h:1.11
--- src/lib/librumpclient/rumpclient.h:1.10	Wed Feb 16 22:35:41 2011
+++ src/lib/librumpclient/rumpclient.h	Fri Dec 16 23:19:28 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.10 2011/02/16 22:35:41 tron Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.11 2011/12/16 23:19:28 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -65,7 +65,7 @@ int rumpclient__closenotify(int *, enum 
  * vfork needs to be implemented as an inline to make everything
  * run in the caller's stackframe.
  */
-static inline pid_t
+static __attribute__((__always_inline__)) __returns_twice inline pid_t
 rumpclient__dofork(pid_t (*forkfn)(void))
 {
 	struct rumpclient_fork *rf;



CVS commit: src/lib/librumpclient

2011-12-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Dec 12 16:53:53 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Mark rumphijack_dlsym explicitly as weak to prevent optimisations based
on pointer (non-)identity of it and rumpclient__dlsym.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.46 src/lib/librumpclient/rumpclient.c:1.47
--- src/lib/librumpclient/rumpclient.c:1.46	Mon Dec 12 15:21:32 2011
+++ src/lib/librumpclient/rumpclient.c	Mon Dec 12 16:53:53 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.46 2011/12/12 15:21:32 joerg Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.47 2011/12/12 16:53:53 joerg Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.46 2011/12/12 15:21:32 joerg Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.47 2011/12/12 16:53:53 joerg Exp $");
 
 #include 
 #include 
@@ -733,7 +733,7 @@ doinit(void)
 }
 
 void *rumpclient__dlsym(void *, const char *);
-void *rumphijack_dlsym(void *, const char *);
+void *rumphijack_dlsym(void *, const char *) __attribute__((__weak__));
 void *
 rumpclient__dlsym(void *handle, const char *symbol)
 {



CVS commit: src/lib/librumpclient

2011-12-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Dec 12 15:21:33 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Don't use K&R syntax


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.45 src/lib/librumpclient/rumpclient.c:1.46
--- src/lib/librumpclient/rumpclient.c:1.45	Sat Apr 30 12:25:05 2011
+++ src/lib/librumpclient/rumpclient.c	Mon Dec 12 15:21:32 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.45 2011/04/30 12:25:05 alnsn Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.46 2011/12/12 15:21:32 joerg Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.45 2011/04/30 12:25:05 alnsn Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.46 2011/12/12 15:21:32 joerg Exp $");
 
 #include 
 #include 
@@ -745,7 +745,7 @@ __weak_alias(rumphijack_dlsym,rumpclient
 static pid_t init_done = 0;
 
 int
-rumpclient_init()
+rumpclient_init(void)
 {
 	char *p;
 	int error;
@@ -995,7 +995,7 @@ rumpclient__closenotify(int *fdp, enum r
 }
 
 pid_t
-rumpclient_fork()
+rumpclient_fork(void)
 {
 
 	return rumpclient__dofork(fork);



CVS commit: src/lib/librumpclient

2011-04-30 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Apr 30 12:25:05 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Save/restore errno in error path in dupgood. Check that n>0 before
accessing banner[n-1].

Approved a while ago by pooka@


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.44 src/lib/librumpclient/rumpclient.c:1.45
--- src/lib/librumpclient/rumpclient.c:1.44	Tue Mar 15 09:35:05 2011
+++ src/lib/librumpclient/rumpclient.c	Sat Apr 30 12:25:05 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.44 2011/03/15 09:35:05 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.45 2011/04/30 12:25:05 alnsn Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.44 2011/03/15 09:35:05 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.45 2011/04/30 12:25:05 alnsn Exp $");
 
 #include 
 #include 
@@ -589,6 +589,7 @@
 {
 	int ofds[4];
 	int i;
+	int sverrno;
 
 	for (i = 0; (myfd <= 2 || mustchange) && myfd != -1; i++) {
 		assert(i < __arraycount(ofds));
@@ -600,10 +601,17 @@
 		}
 	}
 
+	sverrno = 0;
+	if (myfd == -1 && i > 0)
+		sverrno = errno;
+
 	for (i--; i >= 0; i--) {
 		host_close(ofds[i]);
 	}
 
+	if (sverrno)
+		errno = sverrno;
+
 	return myfd;
 }
 
@@ -673,7 +681,7 @@
 		return -1;
 	}
 
-	if ((n = host_read(s, banner, sizeof(banner)-1)) < 0) {
+	if ((n = host_read(s, banner, sizeof(banner)-1)) <= 0) {
 		ERRLOG(("rump_sp: failed to read banner\n"));
 		return -1;
 	}
@@ -683,7 +691,7 @@
 		return -1;
 	}
 	banner[n] = '\0';
-	/* parse the banner some day */
+	/* XXX parse the banner some day */
 
 	flags = host_fcntl(s, F_GETFL, 0);
 	if (host_fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1) {



CVS commit: src/lib/librumpclient

2011-03-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Mar 15 09:35:05 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
don't spam connection errors to stderr by default


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.43 src/lib/librumpclient/rumpclient.c:1.44
--- src/lib/librumpclient/rumpclient.c:1.43	Wed Mar  9 15:09:21 2011
+++ src/lib/librumpclient/rumpclient.c	Tue Mar 15 09:35:05 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.43 2011/03/09 15:09:21 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.44 2011/03/15 09:35:05 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.43 2011/03/09 15:09:21 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.44 2011/03/15 09:35:05 pooka Exp $");
 
 #include 
 #include 
@@ -85,7 +85,7 @@
 static int kq = -1;
 static sigset_t fullset;
 
-static int doconnect(bool);
+static int doconnect(void);
 static int handshake_req(struct spclient *, int, void *, int, bool);
 
 /*
@@ -94,6 +94,9 @@
  */
 static time_t retrytimo = 0;
 
+/* always defined to nothingness for now */
+#define ERRLOG(a)
+
 static int
 send_with_recon(struct spclient *spc, struct iovec *iov, size_t iovlen)
 {
@@ -152,7 +155,7 @@
 			}
 			reconretries++;
 
-			if ((rv = doconnect(false)) != 0)
+			if ((rv = doconnect()) != 0)
 continue;
 			if ((rv = handshake_req(&clispc, HANDSHAKE_GUEST,
 			NULL, 0, true)) != 0)
@@ -605,7 +608,7 @@
 }
 
 static int
-doconnect(bool noisy)
+doconnect(void)
 {
 	struct respwait rw;
 	struct rsp_hdr rhdr;
@@ -660,34 +663,23 @@
 	while (host_connect(s, serv_sa, (socklen_t)serv_sa->sa_len) == -1) {
 		if (errno == EINTR)
 			continue;
-		error = errno;
-		if (noisy)
-			fprintf(stderr, "rump_sp: client connect failed: %s\n",
-			strerror(errno));
-		errno = error;
+		ERRLOG(("rump_sp: client connect failed: %s\n",
+		strerror(errno)));
 		return -1;
 	}
 
 	if ((error = parsetab[ptab_idx].connhook(s)) != 0) {
-		error = errno;
-		if (noisy)
-			fprintf(stderr, "rump_sp: connect hook failed\n");
-		errno = error;
+		ERRLOG(("rump_sp: connect hook failed\n"));
 		return -1;
 	}
 
 	if ((n = host_read(s, banner, sizeof(banner)-1)) < 0) {
-		error = errno;
-		if (noisy)
-			fprintf(stderr, "rump_sp: failed to read banner\n");
-		errno = error;
+		ERRLOG(("rump_sp: failed to read banner\n"));
 		return -1;
 	}
 
 	if (banner[n-1] != '\n') {
-		if (noisy)
-			fprintf(stderr, "rump_sp: invalid banner\n");
-		errno = EINVAL;
+		ERRLOG(("rump_sp: invalid banner\n"));
 		return -1;
 	}
 	banner[n] = '\0';
@@ -695,10 +687,7 @@
 
 	flags = host_fcntl(s, F_GETFL, 0);
 	if (host_fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1) {
-		if (noisy)
-			fprintf(stderr, "rump_sp: socket fd NONBLOCK: %s\n",
-			strerror(errno));
-		errno = EINVAL;
+		ERRLOG(("rump_sp: socket fd NONBLOCK: %s\n", strerror(errno)));
 		return -1;
 	}
 	clispc.spc_fd = s;
@@ -707,10 +696,7 @@
 
 	/* setup kqueue, we want all signals and the fd */
 	if ((kq = dupgood(host_kqueue(), 0)) == -1) {
-		error = errno;
-		if (noisy)
-			fprintf(stderr, "rump_sp: cannot setup kqueue");
-		errno = error;
+		ERRLOG(("rump_sp: cannot setup kqueue"));
 		return -1;
 	}
 
@@ -720,10 +706,7 @@
 	EV_SET(&kev[NSIG], clispc.spc_fd,
 	EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
 	if (host_kevent(kq, kev, NSIG+1, NULL, 0, NULL) == -1) {
-		error = errno;
-		if (noisy)
-			fprintf(stderr, "rump_sp: kevent() failed");
-		errno = error;
+		ERRLOG(("rump_sp: kevent() failed"));
 		return -1;
 	}
 
@@ -832,7 +815,7 @@
 		unsetenv("RUMPCLIENT__EXECFD");
 		hstype = HANDSHAKE_EXEC;
 	} else {
-		if (doconnect(true) == -1)
+		if (doconnect() == -1)
 			goto out;
 		hstype = HANDSHAKE_GUEST;
 	}
@@ -905,7 +888,7 @@
 
 	if (doinit() == -1)
 		return -1;
-	if (doconnect(false) == -1)
+	if (doconnect() == -1)
 		return -1;
 
 	error = handshake_req(&clispc, HANDSHAKE_FORK, rpf->fork_auth,



CVS commit: src/lib/librumpclient

2011-03-09 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Mar  9 15:09:21 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
* use _exit() instead of exit() in retryconn=die: atexit() handlers
  may hang if the server is dead
* consistent use of data


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.42 src/lib/librumpclient/rumpclient.c:1.43
--- src/lib/librumpclient/rumpclient.c:1.42	Tue Mar  8 18:28:01 2011
+++ src/lib/librumpclient/rumpclient.c	Wed Mar  9 15:09:21 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.42 2011/03/08 18:28:01 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.43 2011/03/09 15:09:21 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.42 2011/03/08 18:28:01 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.43 2011/03/09 15:09:21 pooka Exp $");
 
 #include 
 #include 
@@ -111,7 +111,7 @@
 break;
 			}
 			if (retrytimo == RUMPCLIENT_RETRYCONN_DIE)
-exit(1);
+_exit(1);
 
 			if (!prevreconmsg) {
 prevreconmsg = time(NULL);
@@ -329,7 +329,7 @@
 	int cancel, bool haslock)
 {
 	struct handshake_fork rf;
-	const char *myprogname;
+	const char *myprogname = NULL; /* XXXgcc */
 	struct rsp_hdr rhdr;
 	struct respwait rw;
 	sigset_t omask;
@@ -362,7 +362,7 @@
 		rf.rf_cancel = cancel;
 		IOVPUT(iov[1], rf);
 	} else {
-		IOVPUT_WITHSIZE(iov[1], __UNCONST(getprogname()), bonus);
+		IOVPUT_WITHSIZE(iov[1], __UNCONST(myprogname), bonus);
 	}
 	rv = send_with_recon(spc, iov, __arraycount(iov));
 	if (rv || cancel) {



CVS commit: src/lib/librumpclient

2011-03-08 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Mar  8 19:11:27 UTC 2011

Modified Files:
src/lib/librumpclient: Makefile

Log Message:
need -I${.OBJDIR} now


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/librumpclient/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/Makefile
diff -u src/lib/librumpclient/Makefile:1.6 src/lib/librumpclient/Makefile:1.7
--- src/lib/librumpclient/Makefile:1.6	Tue Mar  8 18:30:24 2011
+++ src/lib/librumpclient/Makefile	Tue Mar  8 19:11:27 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.6 2011/03/08 18:30:24 pooka Exp $
+#	$NetBSD: Makefile,v 1.7 2011/03/08 19:11:27 pooka Exp $
 #
 
 .PATH:	${.CURDIR}/../../sys/rump/librump/rumpkern
@@ -12,7 +12,8 @@
 INCS=		rumpclient.h
 INCSDIR=	/usr/include/rump
 
-CPPFLAGS+=	-DRUMP_CLIENT -I${.CURDIR} -I${.CURDIR}/../librumpuser
+CPPFLAGS+=	-DRUMP_CLIENT
+CPPFLAGS+=	-I${.OBJDIR} -I${.CURDIR} -I${.CURDIR}/../librumpuser
 SRCS=		rumpclient.c
 SRCS+=		rump_syscalls.c
 



CVS commit: src/lib/librumpclient

2011-03-08 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Mar  8 18:30:24 UTC 2011

Modified Files:
src/lib/librumpclient: Makefile

Log Message:
create srcsys symlink


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/librumpclient/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/Makefile
diff -u src/lib/librumpclient/Makefile:1.5 src/lib/librumpclient/Makefile:1.6
--- src/lib/librumpclient/Makefile:1.5	Tue Feb 22 17:32:49 2011
+++ src/lib/librumpclient/Makefile	Tue Mar  8 18:30:24 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.5 2011/02/22 17:32:49 tron Exp $
+#	$NetBSD: Makefile,v 1.6 2011/03/08 18:30:24 pooka Exp $
 #
 
 .PATH:	${.CURDIR}/../../sys/rump/librump/rumpkern
@@ -16,6 +16,14 @@
 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 



CVS commit: src/lib/librumpclient

2011-03-08 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Mar  8 18:28:02 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
and for my next trick, i'm going to spell ARGSUSED correctly


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.41 src/lib/librumpclient/rumpclient.c:1.42
--- src/lib/librumpclient/rumpclient.c:1.41	Tue Mar  8 18:25:16 2011
+++ src/lib/librumpclient/rumpclient.c	Tue Mar  8 18:28:01 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.41 2011/03/08 18:25:16 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.42 2011/03/08 18:28:01 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.41 2011/03/08 18:25:16 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.42 2011/03/08 18:28:01 pooka Exp $");
 
 #include 
 #include 
@@ -920,7 +920,7 @@
 	return 0;
 }
 
-/*ARGUSED*/
+/*ARGSUSED*/
 void
 rumpclient_fork_cancel(struct rumpclient_fork *rpf)
 {



CVS commit: src/lib/librumpclient

2011-03-08 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Mar  8 18:25:16 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
lint love


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.40 src/lib/librumpclient/rumpclient.c:1.41
--- src/lib/librumpclient/rumpclient.c:1.40	Tue Mar  8 15:55:12 2011
+++ src/lib/librumpclient/rumpclient.c	Tue Mar  8 18:25:16 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.40 2011/03/08 15:55:12 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.41 2011/03/08 18:25:16 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.40 2011/03/08 15:55:12 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.41 2011/03/08 18:25:16 pooka Exp $");
 
 #include 
 #include 
@@ -920,6 +920,7 @@
 	return 0;
 }
 
+/*ARGUSED*/
 void
 rumpclient_fork_cancel(struct rumpclient_fork *rpf)
 {



CVS commit: src/lib/librumpclient

2011-03-08 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Mar  8 15:55:12 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Since we ~never have a frame waiting on the initial call to waitresp,
call kevent before readframe.  Doesn't really affect performance,
but makes ktraces shorter ;)


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.39 src/lib/librumpclient/rumpclient.c:1.40
--- src/lib/librumpclient/rumpclient.c:1.39	Tue Mar  8 15:34:37 2011
+++ src/lib/librumpclient/rumpclient.c	Tue Mar  8 15:55:12 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.39 2011/03/08 15:34:37 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.40 2011/03/08 15:55:12 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.39 2011/03/08 15:34:37 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.40 2011/03/08 15:55:12 pooka Exp $");
 
 #include 
 #include 
@@ -202,37 +202,48 @@
 
 			dosig = 0;
 			for (gotresp = 0; !gotresp; ) {
-switch (readframe(spc)) {
-case 0:
-	rv = host_kevent(kq, NULL, 0,
-	kev, __arraycount(kev), NULL);
+/*
+ * typically we don't have a frame waiting
+ * when we come in here, so call kevent now
+ */
+rv = host_kevent(kq, NULL, 0,
+kev, __arraycount(kev), NULL);
+
+if (__predict_false(rv == -1)) {
+	goto activity;
+}
 
-	if (__predict_false(rv == -1)) {
-		goto cleanup;
-	}
-
-	/*
-	 * XXX: don't know how this can
-	 * happen (timeout cannot expire
-	 * since there isn't one), but
-	 * it does happen
-	 */
-	if (__predict_false(rv == 0))
-		continue;
-
-	for (i = 0; i < rv; i++) {
-		if (kev[i].filter
-		== EVFILT_SIGNAL)
-			dosig++;
-	}
-	if (dosig)
-		goto cleanup;
+/*
+ * XXX: don't know how this can happen
+ * (timeout cannot expire since there
+ * isn't one), but it does happen.
+ * treat it as an expectional condition
+ * and go through tryread to determine
+ * alive status.
+ */
+if (__predict_false(rv == 0))
+	goto activity;
+
+for (i = 0; i < rv; i++) {
+	if (kev[i].filter == EVFILT_SIGNAL)
+		dosig++;
+}
+if (dosig)
+	goto cleanup;
 
+/*
+ * ok, activity.  try to read a frame to
+ * determine what happens next.
+ */
+ activity:
+switch (readframe(spc)) {
+case 0:
 	continue;
 case -1:
 	imalive = false;
 	goto cleanup;
 default:
+	/* case 1 */
 	break;
 }
 



CVS commit: src/lib/librumpclient

2011-02-27 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Feb 27 12:58:29 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Take reasonable precautions against init in a parent process
which did a rump-transparent host-only fork().


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.37 src/lib/librumpclient/rumpclient.c:1.38
--- src/lib/librumpclient/rumpclient.c:1.37	Fri Feb 25 15:12:06 2011
+++ src/lib/librumpclient/rumpclient.c	Sun Feb 27 12:58:29 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.37 2011/02/25 15:12:06 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.38 2011/02/27 12:58:29 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: rumpclient.c,v 1.37 2011/02/25 15:12:06 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.38 2011/02/27 12:58:29 pooka Exp $");
 
 #include 
 #include 
@@ -727,7 +727,7 @@
 }
 __weak_alias(rumphijack_dlsym,rumpclient__dlsym);
 
-static int init_done = 0;
+static pid_t init_done = 0;
 
 int
 rumpclient_init()
@@ -736,10 +736,22 @@
 	int error;
 	int rv = -1;
 	int hstype;
+	pid_t mypid;
 
-	if (init_done)
+	/*
+	 * Make sure we're not riding the context of a previous
+	 * host fork.  Note: it's *possible* that after n>1 forks
+	 * we have the same pid as one of our exited parents, but
+	 * I'm pretty sure there are 0 practical implications, since
+	 * it means generations would have to skip rumpclient init.
+	 */
+	if (init_done == (mypid = getpid()))
 		return 0;
-	init_done = 1;
+
+	/* kq does not traverse fork() */
+	if (init_done != 0)
+		kq = -1;
+	init_done = mypid;
 
 	sigfillset(&fullset);
 



CVS commit: src/lib/librumpclient

2011-02-25 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Feb 25 15:12:06 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
fix __RCSID


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.36 src/lib/librumpclient/rumpclient.c:1.37
--- src/lib/librumpclient/rumpclient.c:1.36	Thu Feb 24 14:22:04 2011
+++ src/lib/librumpclient/rumpclient.c	Fri Feb 25 15:12:06 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.36 2011/02/24 14:22:04 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.37 2011/02/25 15:12:06 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD");
+__RCSID("$NetBSD: rumpclient.c,v 1.37 2011/02/25 15:12:06 pooka Exp $");
 
 #include 
 #include 



CVS commit: src/lib/librumpclient

2011-02-24 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Feb 24 14:22:04 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Fix static fallback path.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.35 src/lib/librumpclient/rumpclient.c:1.36
--- src/lib/librumpclient/rumpclient.c:1.35	Thu Feb 24 12:25:44 2011
+++ src/lib/librumpclient/rumpclient.c	Thu Feb 24 14:22:04 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.35 2011/02/24 12:25:44 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.36 2011/02/24 14:22:04 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -750,9 +750,9 @@
 #define FINDSYM2(_name_,_syscall_)	\
 	if ((host_##_name_ = rumphijack_dlsym(RTLD_NEXT,		\
 	#_syscall_)) == NULL) {	\
-		if (rumphijack_dlsym == dlsym)\
+		if (rumphijack_dlsym == rumpclient__dlsym)		\
 			host_##_name_ = _name_; /* static fallback */	\
-		else			\
+		if (host_##_name_ == NULL)\
 			errx(1, "cannot find %s: %s", #_syscall_,	\
 			dlerror());	\
 	}



CVS commit: src/lib/librumpclient

2011-02-24 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Feb 24 09:52:35 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Die with a sensible error message if a symbol cannot be found.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.33 src/lib/librumpclient/rumpclient.c:1.34
--- src/lib/librumpclient/rumpclient.c:1.33	Fri Feb 18 16:22:10 2011
+++ src/lib/librumpclient/rumpclient.c	Thu Feb 24 09:52:34 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.33 2011/02/18 16:22:10 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.34 2011/02/24 09:52:34 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -43,6 +43,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -743,24 +744,29 @@
 	 */
 #define FINDSYM2(_name_,_syscall_)	\
 	if ((host_##_name_ = rumpclient_dlsym(RTLD_NEXT,		\
-	#_syscall_)) == NULL)	\
-		/* host_##_name_ = _syscall_ */;
+	#_syscall_)) == NULL) {	\
+		if (rumpclient_dlsym == dlsym)\
+			host_##_name_ = _name_; /* static fallback */	\
+		else			\
+			errx(1, "cannot find %s: %s", #_syscall_,	\
+			dlerror());	\
+	}
 #define FINDSYM(_name_) FINDSYM2(_name_,_name_)
-	FINDSYM2(socket,__socket30);
-	FINDSYM(close);
-	FINDSYM(connect);
-	FINDSYM(fcntl);
-	FINDSYM(poll);
-	FINDSYM(read);
-	FINDSYM(sendto);
-	FINDSYM(setsockopt);
-	FINDSYM(dup);
-	FINDSYM(kqueue);
-	FINDSYM(execve);
+	FINDSYM2(socket,__socket30)
+	FINDSYM(close)
+	FINDSYM(connect)
+	FINDSYM(fcntl)
+	FINDSYM(poll)
+	FINDSYM(read)
+	FINDSYM(sendto)
+	FINDSYM(setsockopt)
+	FINDSYM(dup)
+	FINDSYM(kqueue)
+	FINDSYM(execve)
 #if !__NetBSD_Prereq__(5,99,7)
-	FINDSYM(kevent);
+	FINDSYM(kevent)
 #else
-	FINDSYM2(kevent,_sys___kevent50);
+	FINDSYM2(kevent,_sys___kevent50)
 #endif
 #undef	FINDSYM
 #undef	FINDSY2



CVS commit: src/lib/librumpclient

2011-02-22 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Tue Feb 22 17:32:49 UTC 2011

Modified Files:
src/lib/librumpclient: Makefile

Log Message:
Remove "NOLINT" setting that was apparently committed by accident and
breaks the build.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/librumpclient/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/Makefile
diff -u src/lib/librumpclient/Makefile:1.4 src/lib/librumpclient/Makefile:1.5
--- src/lib/librumpclient/Makefile:1.4	Tue Feb 22 14:02:54 2011
+++ src/lib/librumpclient/Makefile	Tue Feb 22 17:32:49 2011
@@ -1,8 +1,7 @@
-#	$NetBSD: Makefile,v 1.4 2011/02/22 14:02:54 pooka Exp $
+#	$NetBSD: Makefile,v 1.5 2011/02/22 17:32:49 tron Exp $
 #
 
 .PATH:	${.CURDIR}/../../sys/rump/librump/rumpkern
-NOLINT= 	# syscalls are evil
 
 LIB=		rumpclient
 USE_SHLIBDIR=	yes



CVS commit: src/lib/librumpclient

2011-02-22 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Feb 22 14:02:55 UTC 2011

Modified Files:
src/lib/librumpclient: Makefile

Log Message:
Disable string aliasing for rump_syscalls.c.  I can't figure out
how to otherwise make the kernel's register_t coreography to work
with the return value here in a MI fashion.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/librumpclient/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/Makefile
diff -u src/lib/librumpclient/Makefile:1.3 src/lib/librumpclient/Makefile:1.4
--- src/lib/librumpclient/Makefile:1.3	Wed Feb 16 23:45:40 2011
+++ src/lib/librumpclient/Makefile	Tue Feb 22 14:02:54 2011
@@ -1,7 +1,8 @@
-#	$NetBSD: Makefile,v 1.3 2011/02/16 23:45:40 pooka Exp $
+#	$NetBSD: Makefile,v 1.4 2011/02/22 14:02:54 pooka Exp $
 #
 
 .PATH:	${.CURDIR}/../../sys/rump/librump/rumpkern
+NOLINT= 	# syscalls are evil
 
 LIB=		rumpclient
 USE_SHLIBDIR=	yes
@@ -16,4 +17,6 @@
 SRCS=		rumpclient.c
 SRCS+=		rump_syscalls.c
 
+COPTS.rump_syscalls.c+= -fno-strict-aliasing
+
 .include 



CVS commit: src/lib/librumpclient

2011-02-18 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Feb 18 16:22:10 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
I think I skipped the class where they taught that multiplication
is done before addition...


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.32 src/lib/librumpclient/rumpclient.c:1.33
--- src/lib/librumpclient/rumpclient.c:1.32	Wed Feb 16 19:26:58 2011
+++ src/lib/librumpclient/rumpclient.c	Fri Feb 18 16:22:10 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.32 2011/02/16 19:26:58 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.33 2011/02/18 16:22:10 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -1002,7 +1002,7 @@
 	for (nelem = 0; envp && envp[nelem]; nelem++)
 		continue;
 
-	newenv = malloc(sizeof(*newenv) * nelem+3);
+	newenv = malloc(sizeof(*newenv) * (nelem+3));
 	if (newenv == NULL) {
 		free(envstr2);
 		free(envstr);



CVS commit: src/lib/librumpclient

2011-02-17 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Feb 17 17:03:18 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.3

Log Message:
Use more appropriate markup. Fix a typo.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/librumpclient/rumpclient.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.3
diff -u src/lib/librumpclient/rumpclient.3:1.1 src/lib/librumpclient/rumpclient.3:1.2
--- src/lib/librumpclient/rumpclient.3:1.1	Wed Feb 16 23:45:40 2011
+++ src/lib/librumpclient/rumpclient.3	Thu Feb 17 17:03:17 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: rumpclient.3,v 1.1 2011/02/16 23:45:40 pooka Exp $
+.\" $NetBSD: rumpclient.3,v 1.2 2011/02/17 17:03:17 wiz Exp $
 .\"
 .\" Copyright (c) 2011 Antti Kantee.  All rights reserved.
 .\"
@@ -75,7 +75,7 @@
 Initialize
 .Nm .
 The server address is determined from the environment variable
-.Dv RUMP_SERVER
+.Ev RUMP_SERVER
 according to syntax described in
 .Xr rump_sp 7 .
 The new process is registered to the rump kernel with the command
@@ -92,14 +92,16 @@
 .It Fn rumpclient_prefork
 Low-level routine which instructs the rump kernel that the current
 process is planning to fork.
-The routine returns a non-NULL cookie if succesful.
+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
-.Xr rumpclient_prefork .
+.Fn rumpclient_prefork .
 This is typically called from the child of a
 .Xr fork 2
 call.
@@ -154,7 +156,7 @@
 reconnection will be attempted.
 The value 0 means that reconnection will not be attempted, and all
 subsequent operations will return the errno
-.Dv ENOTCONN .
+.Er ENOTCONN .
 .Pp
 Additionally, the following special values are accepted:
 .Bl -tag -width 
@@ -163,7 +165,7 @@
 .It Dv RUMPCLIENT_RETRYCONN_ONCE
 Attempt reconnect exactly once.
 What this precisely means depends on the situation: e.g. getting
-.Dv EHOSTUNREACH
+.Er EHOSTUNREACH
 immediately or the TCP connection request timeouting are considered
 to be one retry.
 .It Dv RUMPCLIENT_RETRYCONN_DIE



CVS commit: src/lib/librumpclient

2011-02-16 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Feb 16 23:45:40 UTC 2011

Modified Files:
src/lib/librumpclient: Makefile
Added Files:
src/lib/librumpclient: rumpclient.3

Log Message:
add some excuse of a manpage for librumpclient


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/librumpclient/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/librumpclient/rumpclient.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/Makefile
diff -u src/lib/librumpclient/Makefile:1.2 src/lib/librumpclient/Makefile:1.3
--- src/lib/librumpclient/Makefile:1.2	Tue Nov 23 12:41:47 2010
+++ src/lib/librumpclient/Makefile	Wed Feb 16 23:45:40 2011
@@ -1,10 +1,11 @@
-#	$NetBSD: Makefile,v 1.2 2010/11/23 12:41:47 pooka Exp $
+#	$NetBSD: Makefile,v 1.3 2011/02/16 23:45:40 pooka Exp $
 #
 
 .PATH:	${.CURDIR}/../../sys/rump/librump/rumpkern
 
 LIB=		rumpclient
 USE_SHLIBDIR=	yes
+MAN=		rumpclient.3
 
 .include 
 

Added files:

Index: src/lib/librumpclient/rumpclient.3
diff -u /dev/null src/lib/librumpclient/rumpclient.3:1.1
--- /dev/null	Wed Feb 16 23:45:40 2011
+++ src/lib/librumpclient/rumpclient.3	Wed Feb 16 23:45:40 2011
@@ -0,0 +1,202 @@
+.\" $NetBSD: rumpclient.3,v 1.1 2011/02/16 23:45:40 pooka 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 (librumpclient, \-lrumpclient)
+.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 
+.It Fn rumpclient_init
+Initialize
+.Nm .
+The server address is determined from the environment variable
+.Dv 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 non-NULL cookie if succesful.
+.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
+.Xr rumpclient_prefork .
+This is typically called from the child of a
+.Xr fork 2
+call.
+

CVS commit: src/lib/librumpclient

2011-02-16 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Wed Feb 16 22:35:41 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
Include "sys/null.h" to get the definition of NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.9 src/lib/librumpclient/rumpclient.h:1.10
--- src/lib/librumpclient/rumpclient.h:1.9	Wed Feb 16 19:58:01 2011
+++ src/lib/librumpclient/rumpclient.h	Wed Feb 16 22:35:41 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.9 2011/02/16 19:58:01 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.10 2011/02/16 22:35:41 tron Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -29,6 +29,7 @@
 #define _RUMP_RUMPCLIENT_H_
 
 #include 
+#include 
 
 struct rumpclient_fork;
 



CVS commit: src/lib/librumpclient

2011-02-16 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Feb 16 19:58:01 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
fix signature of rumpclient_fork()


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.8 src/lib/librumpclient/rumpclient.h:1.9
--- src/lib/librumpclient/rumpclient.h:1.8	Wed Feb 16 17:56:46 2011
+++ src/lib/librumpclient/rumpclient.h	Wed Feb 16 19:58:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.8 2011/02/16 17:56:46 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.9 2011/02/16 19:58:01 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -44,7 +44,7 @@
 void			rumpclient_fork_cancel(struct rumpclient_fork *);
 void			rumpclient_fork_vparent(struct rumpclient_fork *);
 
-int rumpclient_fork(void);
+pid_t rumpclient_fork(void);
 int rumpclient_exec(const char *, char *const [], char *const[]);
 int rumpclient_daemon(int, int);
 



CVS commit: src/lib/librumpclient

2011-02-09 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Feb  9 14:29:58 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
The following happens when sending mail with mutt via a rump
TCP/IP stack:

* mutt prepares to exec the smtp client: it forks and closes all
  file descriptors
* when the next networking syscall is done, rumpclient detects that
  the communication fd returned EBADF and does a reconnect,
  gets descriptor 0 for the socket and descriptor 1 for kqueue
* mutt opens the mail file and implicitly assumes it'll get 0-2,
  but in fact gets 2-4
* mutt execs the smtp agent which tries to read the mail from
  stdin (rumpclient communication socket) and fails

Even if mutt correctly did dup2() things would go south when trying
to communicate with the kernel server the next time, since rumpclient
would actually be talking with some mail body instead (well, it
could work, but in that case you'd need to write *really* weird
mails ;).

Hence, prevent rumpclient from using the special fd's 0-2 for its
purposes.

Should fix mutt problem reported by Alexander Nasonov.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.26 src/lib/librumpclient/rumpclient.c:1.27
--- src/lib/librumpclient/rumpclient.c:1.26	Mon Feb  7 15:25:41 2011
+++ src/lib/librumpclient/rumpclient.c	Wed Feb  9 14:29:58 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.26 2011/02/07 15:25:41 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.27 2011/02/09 14:29:58 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -68,6 +68,7 @@
 ssize_t (*host_sendto)(int, const void *, size_t, int,
 		   const struct sockaddr *, socklen_t);
 int	(*host_setsockopt)(int, int, int, const void *, socklen_t);
+int	(*host_dup)(int);
 
 int	(*host_kqueue)(void);
 int	(*host_kevent)(int, const struct kevent *, size_t,
@@ -543,6 +544,26 @@
 static unsigned ptab_idx;
 static struct sockaddr *serv_sa;
 
+/* dup until we get a "good" fd which does not collide with stdio */
+static int
+dupgood(int myfd)
+{
+	int ofds[3];
+	int i;
+
+	for (i = 0; myfd <= 2 && myfd != -1; i++) {
+		assert(i < __arraycount(ofds));
+		ofds[i] = myfd;
+		myfd = host_dup(myfd);
+	}
+
+	for (i--; i >= 0; i--) {
+		host_close(ofds[i]);
+	}
+
+	return myfd;
+}
+
 static int
 doconnect(bool noisy)
 {
@@ -590,7 +611,7 @@
 	free(clispc.spc_buf);
 	clispc.spc_off = 0;
 
-	s = host_socket(parsetab[ptab_idx].domain, SOCK_STREAM, 0);
+	s = dupgood(host_socket(parsetab[ptab_idx].domain, SOCK_STREAM, 0));
 	if (s == -1)
 		return -1;
 
@@ -645,7 +666,7 @@
 	clispc.spc_reconnecting = 0;
 
 	/* setup kqueue, we want all signals and the fd */
-	if ((kq = host_kqueue()) == -1) {
+	if ((kq = dupgood(host_kqueue())) == -1) {
 		error = errno;
 		if (noisy)
 			fprintf(stderr, "rump_sp: cannot setup kqueue");
@@ -711,6 +732,7 @@
 	FINDSYM(read);
 	FINDSYM(sendto);
 	FINDSYM(setsockopt);
+	FINDSYM(dup);
 	FINDSYM(kqueue);
 #if !__NetBSD_Prereq__(5,99,7)
 	FINDSYM(kevent);



CVS commit: src/lib/librumpclient

2011-02-07 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Feb  7 15:25:41 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
malloc/free aren't async-signal-safe, so avoid calling them when
signals aren't blocked.

this bug made tests/rump/rumpkern/t_sp:sigsafe rarely deadlock


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.25 src/lib/librumpclient/rumpclient.c:1.26
--- src/lib/librumpclient/rumpclient.c:1.25	Mon Feb  7 14:49:53 2011
+++ src/lib/librumpclient/rumpclient.c	Mon Feb  7 15:25:41 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.25 2011/02/07 14:49:53 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.26 2011/02/07 15:25:41 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -267,12 +267,11 @@
 }
 
 static int
-syscall_req(struct spclient *spc, int sysnum,
+syscall_req(struct spclient *spc, sigset_t *omask, int sysnum,
 	const void *data, size_t dlen, void **resp)
 {
 	struct rsp_hdr rhdr;
 	struct respwait rw;
-	sigset_t omask;
 	int rv;
 
 	rhdr.rsp_len = sizeof(rhdr) + dlen;
@@ -280,7 +279,6 @@
 	rhdr.rsp_type = RUMPSP_SYSCALL;
 	rhdr.rsp_sysnum = sysnum;
 
-	pthread_sigmask(SIG_SETMASK, &fullset, &omask);
 	do {
 		putwait(spc, &rw, &rhdr);
 		if ((rv = send_with_recon(spc, &rhdr, sizeof(rhdr))) != 0) {
@@ -292,11 +290,10 @@
 			continue;
 		}
 
-		rv = cliwaitresp(spc, &rw, &omask, false);
+		rv = cliwaitresp(spc, &rw, omask, false);
 		if (rv == ENOTCONN)
 			rv = EAGAIN;
 	} while (rv == EAGAIN);
-	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 
 	*resp = rw.rw_data;
 	return rv;
@@ -346,28 +343,27 @@
 		else
 			unputwait(spc, &rw);
 		if (cancel) {
-			pthread_sigmask(SIG_SETMASK, &omask, NULL);
-			return rv;
+			goto out;
 		}
 	} else {
 		rv = cliwaitresp(spc, &rw, &omask, haslock);
 	}
-	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 	if (rv)
-		return rv;
+		goto out;
 
 	rv = *(int *)rw.rw_data;
 	free(rw.rw_data);
 
+ out:
+	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 	return rv;
 }
 
 static int
-prefork_req(struct spclient *spc, void **resp)
+prefork_req(struct spclient *spc, sigset_t *omask, void **resp)
 {
 	struct rsp_hdr rhdr;
 	struct respwait rw;
-	sigset_t omask;
 	int rv;
 
 	rhdr.rsp_len = sizeof(rhdr);
@@ -375,7 +371,6 @@
 	rhdr.rsp_type = RUMPSP_PREFORK;
 	rhdr.rsp_error = 0;
 
-	pthread_sigmask(SIG_SETMASK, &fullset, &omask);
 	do {
 		putwait(spc, &rw, &rhdr);
 		rv = send_with_recon(spc, &rhdr, sizeof(rhdr));
@@ -384,11 +379,10 @@
 			continue;
 		}
 
-		rv = cliwaitresp(spc, &rw, &omask, false);
+		rv = cliwaitresp(spc, &rw, omask, false);
 		if (rv == ENOTCONN)
 			rv = EAGAIN;
 	} while (rv == EAGAIN);
-	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 
 	*resp = rw.rw_data;
 	return rv;
@@ -463,15 +457,18 @@
 	register_t *retval)
 {
 	struct rsp_sysresp *resp;
+	sigset_t omask;
 	void *rdata;
 	int rv;
 
+	pthread_sigmask(SIG_SETMASK, &fullset, &omask);
+
 	DPRINTF(("rumpsp syscall_req: syscall %d with %p/%zu\n",
 	sysnum, data, dlen));
 
-	rv = syscall_req(&clispc, sysnum, data, dlen, &rdata);
+	rv = syscall_req(&clispc, &omask, sysnum, data, dlen, &rdata);
 	if (rv)
-		return rv;
+		goto out;
 
 	resp = rdata;
 	DPRINTF(("rumpsp syscall_resp: syscall %d error %d, rv: %d/%d\n",
@@ -481,6 +478,8 @@
 	rv = resp->rsys_error;
 	free(rdata);
 
+ out:
+	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 	return rv;
 }
 
@@ -757,22 +756,27 @@
 rumpclient_prefork(void)
 {
 	struct rumpclient_fork *rpf;
+	sigset_t omask;
 	void *resp;
 	int rv;
 
+	pthread_sigmask(SIG_SETMASK, &fullset, &omask);
 	rpf = malloc(sizeof(*rpf));
 	if (rpf == NULL)
 		return NULL;
 
-	if ((rv = prefork_req(&clispc, &resp)) != 0) {
+	if ((rv = prefork_req(&clispc, &omask, &resp)) != 0) {
 		free(rpf);
 		errno = rv;
-		return NULL;
+		rpf = NULL;
+		goto out;
 	}
 
 	memcpy(rpf->fork_auth, resp, sizeof(rpf->fork_auth));
 	free(resp);
 
+ out:
+	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 	return rpf;
 }
 



CVS commit: src/lib/librumpclient

2011-02-07 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Feb  7 14:49:53 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
make sure we don't use "fullset" before we init it


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.24 src/lib/librumpclient/rumpclient.c:1.25
--- src/lib/librumpclient/rumpclient.c:1.24	Sun Feb  6 15:43:20 2011
+++ src/lib/librumpclient/rumpclient.c	Mon Feb  7 14:49:53 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.24 2011/02/06 15:43:20 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.25 2011/02/07 14:49:53 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -689,6 +689,8 @@
 	char *p;
 	int error;
 
+	sigfillset(&fullset);
+
 	/* dlsym overrided by rumphijack? */
 	if (!rumpclient_dlsym)
 		rumpclient_dlsym = dlsym;
@@ -744,7 +746,6 @@
 		return -1;
 	}
 
-	sigfillset(&fullset);
 	return 0;
 }
 



CVS commit: src/lib/librumpclient

2011-02-07 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Feb  7 14:49:32 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.h

Log Message:
types.h for time_t


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.4 src/lib/librumpclient/rumpclient.h:1.5
--- src/lib/librumpclient/rumpclient.h:1.4	Sun Feb  6 15:43:20 2011
+++ src/lib/librumpclient/rumpclient.h	Mon Feb  7 14:49:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.4 2011/02/06 15:43:20 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.5 2011/02/07 14:49:32 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -28,6 +28,8 @@
 #ifndef _RUMP_RUMPCLIENT_H_
 #define _RUMP_RUMPCLIENT_H_
 
+#include 
+
 __BEGIN_DECLS
 
 int rumpclient_syscall(int, const void *, size_t, register_t *);



CVS commit: src/lib/librumpclient

2011-02-06 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Feb  6 15:43:20 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c rumpclient.h

Log Message:
Add another connection retry model which simply does exit(1) if
the connection is severed.
(mostly for tests so that everything can be hooked to rump_server's exit)


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/librumpclient/rumpclient.c
cvs rdiff -u -r1.3 -r1.4 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.23 src/lib/librumpclient/rumpclient.c:1.24
--- src/lib/librumpclient/rumpclient.c:1.23	Sun Feb  6 15:41:37 2011
+++ src/lib/librumpclient/rumpclient.c	Sun Feb  6 15:43:20 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.23 2011/02/06 15:41:37 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.24 2011/02/06 15:43:20 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -101,6 +101,8 @@
 			/* no persistent connections */
 			if (retrytimo == 0)
 break;
+			if (retrytimo == RUMPCLIENT_RETRYCONN_DIE)
+exit(1);
 
 			if (!prevreconmsg) {
 prevreconmsg = time(NULL);
@@ -805,7 +807,7 @@
 rumpclient_setconnretry(time_t timeout)
 {
 
-	if (timeout < RUMPCLIENT_RETRYCONN_ONCE)
+	if (timeout < RUMPCLIENT_RETRYCONN_DIE)
 		return; /* gigo */
 
 	retrytimo = timeout;

Index: src/lib/librumpclient/rumpclient.h
diff -u src/lib/librumpclient/rumpclient.h:1.3 src/lib/librumpclient/rumpclient.h:1.4
--- src/lib/librumpclient/rumpclient.h:1.3	Thu Jan 27 18:04:05 2011
+++ src/lib/librumpclient/rumpclient.h	Sun Feb  6 15:43:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.3 2011/01/27 18:04:05 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.4 2011/02/06 15:43:20 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -39,6 +39,7 @@
 
 #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);
 
 __END_DECLS



CVS commit: src/lib/librumpclient

2011-02-06 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Feb  6 15:41:38 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Make sure to close parent's server communication socket after fork.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.22 src/lib/librumpclient/rumpclient.c:1.23
--- src/lib/librumpclient/rumpclient.c:1.22	Sat Feb  5 12:38:19 2011
+++ src/lib/librumpclient/rumpclient.c	Sun Feb  6 15:41:37 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.22 2011/02/05 12:38:19 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.23 2011/02/06 15:41:37 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -777,10 +777,13 @@
 rumpclient_fork_init(struct rumpclient_fork *rpf)
 {
 	int error;
+	int osock;
 
+	osock = clispc.spc_fd;
 	memset(&clispc, 0, sizeof(clispc));
-	clispc.spc_fd = -1;
-	kq = -1;
+	clispc.spc_fd = osock;
+
+	kq = -1; /* kqueue descriptor is not copied over fork() */
 
 	if (doinit() == -1)
 		return -1;



CVS commit: src/lib/librumpclient

2011-01-27 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Jan 27 18:04:05 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c rumpclient.h

Log Message:
Allow to set a timeout for how long the client will attempt to
reconnect in case the connection to the server is lost.  Default
to exactly one reattempt.  This makes sense and additionally fixes
the dev/raidframe/smalldisk test which currently causes a server
panic when a certain raidctl command is run (without this fix the
test would timeout since the client kept attempting to reconnect).


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/librumpclient/rumpclient.c
cvs rdiff -u -r1.2 -r1.3 src/lib/librumpclient/rumpclient.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.19 src/lib/librumpclient/rumpclient.c:1.20
--- src/lib/librumpclient/rumpclient.c:1.19	Wed Jan 26 14:42:41 2011
+++ src/lib/librumpclient/rumpclient.c	Thu Jan 27 18:04:05 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.19 2011/01/26 14:42:41 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.20 2011/01/27 18:04:05 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -82,27 +82,83 @@
 static int kq = -1;
 static sigset_t fullset;
 
-static int doconnect(int);
+static int doconnect(bool);
 static int handshake_req(struct spclient *, uint32_t *, int, bool);
 
-int didrecon;
+time_t retrytimo = RUMPCLIENT_RETRYCONN_ONCE;
 
 static int
 send_with_recon(struct spclient *spc, const void *data, size_t dlen)
 {
+	struct timeval starttime, curtime;
+	time_t prevreconmsg;
+	unsigned reconretries;
 	int rv;
 
-	do {
+	for (prevreconmsg = 0, reconretries = 0;;) {
 		rv = dosend(spc, data, dlen);
 		if (__predict_false(rv == ENOTCONN || rv == EBADF)) {
-			if ((rv = doconnect(1)) != 0)
+			/* no persistent connections */
+			if (retrytimo == 0)
+break;
+
+			if (!prevreconmsg) {
+prevreconmsg = time(NULL);
+gettimeofday(&starttime, NULL);
+			}
+			if (reconretries == 1) {
+if (retrytimo == RUMPCLIENT_RETRYCONN_ONCE) {
+	rv = ENOTCONN;
+	break;
+}
+fprintf(stderr, "rump_sp: connection to "
+"kernel lost, trying to reconnect ...\n");
+			} else if (time(NULL) - prevreconmsg > 120) {
+fprintf(stderr, "rump_sp: still trying to "
+"reconnect ...\n");
+prevreconmsg = time(NULL);
+			}
+
+			/* check that we aren't over the limit */
+			if (retrytimo > 0) {
+struct timeval tmp;
+
+gettimeofday(&curtime, NULL);
+timersub(&curtime, &starttime, &tmp);
+if (tmp.tv_sec >= retrytimo) {
+	fprintf(stderr, "rump_sp: reconnect "
+	"failed, %lld second timeout\n",
+	(long long)retrytimo);
+	return ENOTCONN;
+}
+			}
+
+			/* adhoc backoff timer */
+			if (reconretries < 10) {
+usleep(10 * reconretries);
+			} else {
+sleep(MIN(10, reconretries-9));
+			}
+			reconretries++;
+
+			if ((rv = doconnect(false)) != 0)
 continue;
 			if ((rv = handshake_req(&clispc, NULL, 0, true)) != 0)
 continue;
-			rv = ENOTCONN;
+
+			/*
+			 * ok, reconnect succesful.  we need to return to
+			 * the upper layer to get the entire PDU resent.
+			 */
+			if (reconretries != 1)
+fprintf(stderr, "rump_sp: reconnected!\n");
+			rv = EAGAIN;
+			break;
+		} else {
+			_DIAGASSERT(errno != EAGAIN);
 			break;
 		}
-	} while (__predict_false(rv != 0));
+	}
 
 	return rv;
 }
@@ -235,7 +291,9 @@
 		}
 
 		rv = cliwaitresp(spc, &rw, &omask, false);
-	} while (rv == ENOTCONN || rv == EAGAIN);
+		if (rv == ENOTCONN)
+			rv = EAGAIN;
+	} while (rv == EAGAIN);
 	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 
 	*resp = rw.rw_data;
@@ -316,7 +374,9 @@
 		}
 
 		rv = cliwaitresp(spc, &rw, &omask, false);
-	} while (rv == ENOTCONN || rv == EAGAIN);
+		if (rv == ENOTCONN)
+			rv = EAGAIN;
+	} while (rv == EAGAIN);
 	pthread_sigmask(SIG_SETMASK, &omask, NULL);
 
 	*resp = rw.rw_data;
@@ -474,10 +534,8 @@
 static struct sockaddr *serv_sa;
 
 static int
-doconnect(int retry)
+doconnect(bool noisy)
 {
-	time_t prevreconmsg;
-	unsigned reconretries;
 	struct respwait rw;
 	struct rsp_hdr rhdr;
 	struct kevent kev[NSIG+1];
@@ -491,16 +549,9 @@
 	kq = -1;
 	s = -1;
 
-	prevreconmsg = 0;
-	reconretries = 0;
-
- again:
 	if (clispc.spc_fd != -1)
 		host_close(clispc.spc_fd);
 	clispc.spc_fd = -1;
-	if (s != -1)
-		close(s);
-	s = -1;
 
 	/*
 	 * for reconnect, gate everyone out of the receiver code
@@ -538,50 +589,33 @@
 	while (host_connect(s, serv_sa, (socklen_t)serv_sa->sa_len) == -1) {
 		if (errno == EINTR)
 			continue;
-		if (!retry) {
-			error = errno;
+		error = errno;
+		if (noisy)
 			fprintf(stderr, "rump_sp: client connect failed: %s\n",
 			strerror(errno));
-			errno = error;
-			return -1;
-		}
-
-		if (prevreconmsg == 0) {
-			fprintf(stderr, "rump_sp: connection to kern

CVS commit: src/lib/librumpclient

2011-01-26 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Jan 26 14:42:41 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
plug fd leak in reconnect code


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.18 src/lib/librumpclient/rumpclient.c:1.19
--- src/lib/librumpclient/rumpclient.c:1.18	Mon Jan 24 17:47:51 2011
+++ src/lib/librumpclient/rumpclient.c	Wed Jan 26 14:42:41 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.18 2011/01/24 17:47:51 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.19 2011/01/26 14:42:41 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -489,6 +489,7 @@
 	if (kq != -1)
 		host_close(kq);
 	kq = -1;
+	s = -1;
 
 	prevreconmsg = 0;
 	reconretries = 0;
@@ -497,6 +498,9 @@
 	if (clispc.spc_fd != -1)
 		host_close(clispc.spc_fd);
 	clispc.spc_fd = -1;
+	if (s != -1)
+		close(s);
+	s = -1;
 
 	/*
 	 * for reconnect, gate everyone out of the receiver code



CVS commit: src/lib/librumpclient

2011-01-21 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Jan 21 10:43:33 UTC 2011

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Forgot to commit this a few days ago: need to make sure we get the
right kqueue/kevent now that rumphijack hijacks them.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.16 src/lib/librumpclient/rumpclient.c:1.17
--- src/lib/librumpclient/rumpclient.c:1.16	Fri Jan 14 13:12:15 2011
+++ src/lib/librumpclient/rumpclient.c	Fri Jan 21 10:43:33 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.16 2011/01/14 13:12:15 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.17 2011/01/21 10:43:33 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -63,13 +63,15 @@
 int	(*host_connect)(int, const struct sockaddr *, socklen_t);
 int	(*host_fcntl)(int, int, ...);
 int	(*host_poll)(struct pollfd *, nfds_t, int);
-int	(*host_pollts)(struct pollfd *, nfds_t, const struct timespec *,
-		  const sigset_t *);
 ssize_t	(*host_read)(int, void *, size_t);
 ssize_t (*host_sendto)(int, const void *, size_t, int,
 		   const struct sockaddr *, socklen_t);
 int	(*host_setsockopt)(int, int, int, const void *, socklen_t);
 
+int	(*host_kqueue)(void);
+int	(*host_kevent)(int, const struct kevent *, size_t,
+		   struct kevent *, size_t, const struct timespec *);
+
 #include "sp_common.c"
 
 static struct spclient clispc = {
@@ -101,7 +103,7 @@
 			for (gotresp = 0; !gotresp; ) {
 switch (readframe(spc)) {
 case 0:
-	rv = kevent(kq, NULL, 0,
+	rv = host_kevent(kq, NULL, 0,
 	kev, __arraycount(kev), NULL);
 	assert(rv > 0);
 	for (i = 0; i < rv; i++) {
@@ -449,7 +451,7 @@
 	/* parse the banner some day */
 
 	/* setup kqueue, we want all signals and the fd */
-	if ((kq = kqueue()) == -1) {
+	if ((kq = host_kqueue()) == -1) {
 		error = errno;
 		fprintf(stderr, "rump_sp: cannot setup kqueue");
 		errno = error;
@@ -460,7 +462,7 @@
 		EV_SET(&kev[i], i+1, EVFILT_SIGNAL, EV_ADD|EV_ENABLE, 0, 0, 0);
 	}
 	EV_SET(&kev[NSIG], s, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
-	if (kevent(kq, kev, NSIG+1, NULL, 0, NULL) == -1) {
+	if (host_kevent(kq, kev, NSIG+1, NULL, 0, NULL) == -1) {
 		error = errno;
 		fprintf(stderr, "rump_sp: kevent() failed");
 		errno = error;
@@ -501,10 +503,11 @@
 	FINDSYM(connect);
 	FINDSYM(fcntl);
 	FINDSYM(poll);
-	FINDSYM(pollts);
 	FINDSYM(read);
 	FINDSYM(sendto);
 	FINDSYM(setsockopt);
+	FINDSYM(kqueue);
+	FINDSYM(kevent);
 #undef	FINDSYM
 #undef	FINDSY2
 



CVS commit: src/lib/librumpclient

2010-11-30 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Nov 30 22:30:44 UTC 2010

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
lintsquelch


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.7 src/lib/librumpclient/rumpclient.c:1.8
--- src/lib/librumpclient/rumpclient.c:1.7	Tue Nov 30 14:24:40 2010
+++ src/lib/librumpclient/rumpclient.c	Tue Nov 30 22:30:43 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.7 2010/11/30 14:24:40 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.8 2010/11/30 22:30:43 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -226,7 +226,7 @@
 	if (s == -1)
 		return -1;
 
-	if (connect(s, sap, sap->sa_len) == -1) {
+	if (connect(s, sap, (socklen_t)sap->sa_len) == -1) {
 		error = errno;
 		fprintf(stderr, "rump_sp: client connect failed\n");
 		errno = error;



CVS commit: src/lib/librumpclient

2010-11-30 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Nov 30 14:24:40 UTC 2010

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
Change RUMP_SP_CLIENT to RUMP_SERVER.  The former was, in addition
to being annoying to write, slightly misguiding, since it contains
the server url.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.6 src/lib/librumpclient/rumpclient.c:1.7
--- src/lib/librumpclient/rumpclient.c:1.6	Mon Nov 29 16:08:03 2010
+++ src/lib/librumpclient/rumpclient.c	Tue Nov 30 14:24:40 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.6 2010/11/29 16:08:03 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.7 2010/11/30 14:24:40 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -212,7 +212,7 @@
 	unsigned idx;
 	int error, s;
 
-	if ((p = getenv("RUMP_SP_CLIENT")) == NULL) {
+	if ((p = getenv("RUMP_SERVER")) == NULL) {
 		errno = ENOENT;
 		return -1;
 	}



CVS commit: src/lib/librumpclient

2010-11-24 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Nov 24 17:03:39 UTC 2010

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
update locking proto, use unputwait


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.3 src/lib/librumpclient/rumpclient.c:1.4
--- src/lib/librumpclient/rumpclient.c:1.3	Fri Nov 19 15:25:49 2010
+++ src/lib/librumpclient/rumpclient.c	Wed Nov 24 17:03:39 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.3 2010/11/19 15:25:49 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.4 2010/11/24 17:03:39 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -71,13 +71,12 @@
 	rhdr.rsp_sysnum = sysnum;
 
 	putwait(spc, &rw, &rhdr);
-
-	sendlock(spc);
 	rv = dosend(spc, &rhdr, sizeof(rhdr));
 	rv = dosend(spc, data, dlen);
-	sendunlock(spc);
-	if (rv)
-		return rv; /* XXX: unputwait */
+	if (rv) {
+		unputwait(spc, &rw);
+		return rv;
+	}
 
 	rv = waitresp(spc, &rw);
 	*resp = rw.rw_data;
@@ -224,6 +223,7 @@
 		errno = error;
 		return -1;
 	}
+
 	if ((error = parsetab[idx].connhook(s)) != 0) {
 		error = errno;
 		fprintf(stderr, "rump_sp: connect hook failed\n");



CVS commit: src/lib/librumpclient

2010-11-05 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Nov  5 13:50:48 UTC 2010

Modified Files:
src/lib/librumpclient: rumpclient.c

Log Message:
use -1/errno for failure: it's much more convenient for the users


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.1 src/lib/librumpclient/rumpclient.c:1.2
--- src/lib/librumpclient/rumpclient.c:1.1	Thu Nov  4 21:01:29 2010
+++ src/lib/librumpclient/rumpclient.c	Fri Nov  5 13:50:48 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpclient.c,v 1.1 2010/11/04 21:01:29 pooka Exp $	*/
+/*  $NetBSD: rumpclient.c,v 1.2 2010/11/05 13:50:48 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -186,25 +186,32 @@
 	unsigned idx;
 	int error, s;
 
-	if ((p = getenv("RUMP_SP_CLIENT")) == NULL)
-		return ENOENT;
+	if ((p = getenv("RUMP_SP_CLIENT")) == NULL) {
+		errno = ENOENT;
+		return -1;
+	}
 
-	if ((error = parseurl(p, &sap, &idx, 0)) != 0)
-		return error;
+	if ((error = parseurl(p, &sap, &idx, 0)) != 0) {
+		errno = error;
+		return -1;
+	}
 
 	s = socket(parsetab[idx].domain, SOCK_STREAM, 0);
 	if (s == -1)
-		return errno;
+		return -1;
 
 	if (connect(s, sap, sap->sa_len) == -1) {
+		error = errno;
 		fprintf(stderr, "rump_sp: client connect failed\n");
-		return errno;
+		errno = error;
+		return -1;
 	}
 	if ((error = parsetab[idx].connhook(s)) != 0) {
+		error = errno;
 		fprintf(stderr, "rump_sp: connect hook failed\n");
-		return error;
+		errno = error;
+		return -1;
 	}
-
 	clispc.spc_fd = s;
 
 	return 0;