Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librumphijack - implement pselect so that the ssh test h...
details: https://anonhg.NetBSD.org/src/rev/807b346f3e1a
branches: trunk
changeset: 1023482:807b346f3e1a
user: christos <christos%NetBSD.org@localhost>
date: Fri Sep 10 20:33:38 2021 +0000
description:
- implement pselect so that the ssh test has a chance to work
- 1 -> EXIT_FAILURE
- more info about fds
diffstat:
lib/librumphijack/hijack.c | 169 +++++++++++++++++++++++++-------------------
1 files changed, 97 insertions(+), 72 deletions(-)
diffs (truncated from 465 to 300 lines):
diff -r 893d5b45200e -r 807b346f3e1a lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c Fri Sep 10 20:02:50 2021 +0000
+++ b/lib/librumphijack/hijack.c Fri Sep 10 20:33:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hijack.c,v 1.131 2020/05/27 18:55:36 christos Exp $ */
+/* $NetBSD: hijack.c,v 1.132 2021/09/10 20:33:38 christos Exp $ */
/*-
* Copyright (c) 2011 Antti Kantee. All Rights Reserved.
@@ -34,7 +34,7 @@
#include <rump/rumpuser_port.h>
#if !defined(lint)
-__RCSID("$NetBSD: hijack.c,v 1.131 2020/05/27 18:55:36 christos Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.132 2021/09/10 20:33:38 christos Exp $");
#endif
#include <sys/param.h>
@@ -187,6 +187,7 @@
#if defined(__NetBSD__)
#if !__NetBSD_Prereq__(5,99,7)
+#define REALSELECT pselect
#define REALSELECT select
#define REALPOLLTS pollts
#define REALKEVENT kevent
@@ -199,6 +200,7 @@
#define REALMKNOD mknod
#define REALFHSTAT __fhstat40
#else /* >= 5.99.7 */
+#define REALPSELECT _sys___pselect50
#define REALSELECT _sys___select50
#define REALPOLLTS _sys___pollts50
#define REALKEVENT _sys___kevent50
@@ -248,6 +250,7 @@
#define REALREAD read
#define REALPREAD pread
#define REALPWRITE pwrite
+#define REALPSELECT pselect
#define REALSELECT select
#define REALPOLLTS ppoll
#define REALUTIMES utimes
@@ -262,6 +265,8 @@
#endif /* platform */
+int REALPSELECT(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
+ const sigset_t *);
int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *);
int REALPOLLTS(struct pollfd *, nfds_t,
const struct timespec *, const sigset_t *);
@@ -482,7 +487,7 @@
{
if (hostfd > DUP2HIGH) {
- _DIAGASSERT(0);
+ _DIAGASSERT(/*CONSTCOND*/0);
return;
}
@@ -494,7 +499,7 @@
{
if (hostfd > DUP2HIGH) {
- _DIAGASSERT(0);
+ _DIAGASSERT(/*CONSTCOND*/0);
return;
}
@@ -696,7 +701,7 @@
}
}
if (socketmap[i].name == NULL) {
- errx(1, "invalid socket specifier %s", p);
+ errx(EXIT_FAILURE, "invalid socket specifier %s", p);
}
}
}
@@ -707,16 +712,17 @@
/* sanity-check */
if (*buf != '/')
- errx(1, "hijack path specifier must begin with ``/''");
+ errx(EXIT_FAILURE,
+ "hijack path specifier must begin with ``/''");
rumpprefixlen = strlen(buf);
if (rumpprefixlen < 2)
- errx(1, "invalid hijack prefix: %s", buf);
+ errx(EXIT_FAILURE, "invalid hijack prefix: %s", buf);
if (buf[rumpprefixlen-1] == '/' && strspn(buf, "/") != rumpprefixlen)
- errx(1, "hijack prefix may end in slash only if pure "
- "slash, gave %s", buf);
+ errx(EXIT_FAILURE, "hijack prefix may end in slash only if "
+ "pure slash, gave %s", buf);
if ((rumpprefix = strdup(buf)) == NULL)
- err(1, "strdup");
+ err(EXIT_FAILURE, "strdup");
rumpprefixlen = strlen(rumpprefix);
}
@@ -737,19 +743,19 @@
blanket = malloc(nblanket * sizeof(*blanket));
if (blanket == NULL)
- err(1, "alloc blanket %d", nblanket);
+ err(EXIT_FAILURE, "alloc blanket %d", nblanket);
for (p = strtok_r(buf, ":", &l), i = 0; p;
p = strtok_r(NULL, ":", &l), i++) {
blanket[i].pfx = strdup(p);
if (blanket[i].pfx == NULL)
- err(1, "strdup blanket");
+ err(EXIT_FAILURE, "strdup blanket");
blanket[i].len = strlen(p);
if (blanket[i].len == 0 || *blanket[i].pfx != '/')
- errx(1, "invalid blanket specifier %s", p);
+ errx(EXIT_FAILURE, "invalid blanket specifier %s", p);
if (*(blanket[i].pfx + blanket[i].len-1) == '/')
- errx(1, "invalid blanket specifier %s", p);
+ errx(EXIT_FAILURE, "invalid blanket specifier %s", p);
}
}
@@ -780,7 +786,8 @@
fullmask = 0;
for (i = 0; vfscalls[i].name != NULL; i++) {
if (fullmask & vfscalls[i].bit)
- errx(1, "problem exists between vi and chair");
+ errx(EXIT_FAILURE,
+ "problem exists between vi and chair");
fullmask |= vfscalls[i].bit;
}
@@ -810,7 +817,7 @@
}
}
if (vfscalls[i].name == NULL) {
- errx(1, "invalid vfscall specifier %s", p);
+ errx(EXIT_FAILURE, "invalid vfscall specifier %s", p);
}
}
}
@@ -836,7 +843,7 @@
return;
}
- errx(1, "sysctl value should be y(es)/n(o), gave: %s", buf);
+ errx(EXIT_FAILURE, "sysctl value should be y(es)/n(o), gave: %s", buf);
}
static bool rumpmodctl = false;
@@ -860,7 +867,7 @@
return;
}
- errx(1, "modctl value should be y(es)/n(o), gave: %s", buf);
+ errx(EXIT_FAILURE, "modctl value should be y(es)/n(o), gave: %s", buf);
}
static void
@@ -870,14 +877,14 @@
char *ep;
if (*buf == '-') {
- errx(1, "fdoff must not be negative");
+ errx(EXIT_FAILURE, "fdoff must not be negative");
}
fdoff = strtoul(buf, &ep, 10);
if (*ep != '\0')
- errx(1, "invalid fdoff specifier \"%s\"", buf);
+ errx(EXIT_FAILURE, "invalid fdoff specifier \"%s\"", buf);
if (fdoff >= INT_MAX/2 || fdoff < 3)
- errx(1, "fdoff out of range");
- hijack_fdoff = fdoff;
+ errx(EXIT_FAILURE, "fdoff out of range");
+ hijack_fdoff = (int)fdoff;
}
static struct {
@@ -904,7 +911,7 @@
int i;
if ((hijackcopy = strdup(hijack)) == NULL)
- err(1, "strdup");
+ err(EXIT_FAILURE, "strdup");
/* disable everything explicitly */
for (i = 0; i < PF_MAX; i++)
@@ -922,7 +929,7 @@
if (strncmp(hijackparse[i].name, p,
(size_t)(p2-p)) == 0) {
if (nop2 && hijackparse[i].needvalues)
- errx(1, "invalid hijack specifier: %s",
+ errx(EXIT_FAILURE, "invalid hijack specifier: %s",
hijackcopy);
hijackparse[i].parsefn(nop2 ? NULL : p2+1);
break;
@@ -930,12 +937,13 @@
}
if (hijackparse[i].parsefn == NULL)
- errx(1, "invalid hijack specifier name in %s", p);
+ errx(EXIT_FAILURE,
+ "invalid hijack specifier name in %s", p);
}
}
-static void __attribute__((constructor))
+static void __attribute__((__constructor__))
rcinit(void)
{
char buf[1024];
@@ -960,23 +968,29 @@
}
if (j == __arraycount(syscnames))
- errx(1, "rumphijack error: syscall pos %d missing", i);
+ errx(EXIT_FAILURE,
+ "rumphijack error: syscall pos %d missing", i);
syscalls[i].bs_host = dlsym(RTLD_NEXT,
syscnames[j].scm_hostname);
if (syscalls[i].bs_host == NULL)
- errx(1, "hostcall %s not found!",
+ errx(EXIT_FAILURE, "hostcall %s not found!",
syscnames[j].scm_hostname);
syscalls[i].bs_rump = dlsym(RTLD_NEXT,
syscnames[j].scm_rumpname);
if (syscalls[i].bs_rump == NULL)
- errx(1, "rumpcall %s not found!",
+ errx(EXIT_FAILURE, "rumpcall %s not found!",
syscnames[j].scm_rumpname);
+#if 0
+ fprintf(stderr, "%s %p %s %p\n",
+ syscnames[j].scm_hostname, syscalls[i].bs_host,
+ syscnames[j].scm_rumpname, syscalls[i].bs_rump);
+#endif
}
if (rumpclient_init() == -1)
- err(1, "rumpclient init");
+ err(EXIT_FAILURE, "rumpclient init");
/* check which syscalls we're supposed to hijack */
if (getenv_r("RUMPHIJACK", buf, sizeof(buf)) == -1) {
@@ -998,7 +1012,8 @@
timeout = (time_t)strtoll(buf, &ep, 10);
if (timeout <= 0 || ep != buf + strlen(buf))
- errx(1, "RUMPHIJACK_RETRYCONNECT must be "
+ errx(EXIT_FAILURE,
+ "RUMPHIJACK_RETRYCONNECT must be "
"keyword or integer, got: %s", buf);
rumpclient_setconnretry(timeout);
@@ -1171,9 +1186,9 @@
bool isrump;
va_list ap;
enum pathtype pt;
- int fd;
-
- DPRINTF(("open -> %s (%s)\n", path, whichpath(path)));
+ int fd, rfd;
+
+ DPRINTF(("open -> %s (%s)", path, whichpath(path)));
if ((pt = path_isrump(path)) != PATH_HOST) {
if (pt == PATH_RUMP)
@@ -1190,12 +1205,12 @@
va_end(ap);
if (isrump)
- fd = fd_rump2host(fd);
+ rfd = fd_rump2host(fd);
else
- fd = fd_host2host(fd);
-
- DPRINTF(("open <- %d (%s)\n", fd, whichfd(fd)));
- return fd;
+ rfd = fd_host2host(fd);
+
+ DPRINTF((" <- %d/%d (%s)\n", fd, rfd, whichfd(rfd)));
+ return rfd;
}
int
@@ -1391,7 +1406,7 @@
REALSOCKET(int domain, int type, int protocol)
{
int (*op_socket)(int, int, int);
- int fd;
+ int fd, rfd;
bool isrump;
isrump = domain < PF_MAX && rumpsockets[domain];
@@ -1403,19 +1418,19 @@
Home |
Main Index |
Thread Index |
Old Index