Module Name: src
Committed By: pooka
Date: Mon Dec 13 17:39:47 UTC 2010
Modified Files:
src/sbin/route: Makefile route.c show.c
Added Files:
src/sbin/route: prog_ops.h route_hostops.c route_rumpops.c
Log Message:
Convert from RUMP_ACTION to RUMPPRG.
To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sbin/route/Makefile
cvs rdiff -u -r0 -r1.1 src/sbin/route/prog_ops.h \
src/sbin/route/route_hostops.c src/sbin/route/route_rumpops.c
cvs rdiff -u -r1.126 -r1.127 src/sbin/route/route.c
cvs rdiff -u -r1.41 -r1.42 src/sbin/route/show.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/route/Makefile
diff -u src/sbin/route/Makefile:1.24 src/sbin/route/Makefile:1.25
--- src/sbin/route/Makefile:1.24 Thu Nov 4 23:36:10 2010
+++ src/sbin/route/Makefile Mon Dec 13 17:39:47 2010
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.24 2010/11/04 23:36:10 pooka Exp $
+# $NetBSD: Makefile,v 1.25 2010/12/13 17:39:47 pooka Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
.include <bsd.own.mk>
-PROG= route
+RUMPPRG=route
MAN= route.8
SRCS= route.c show.c keywords.c
@@ -20,15 +20,4 @@
# keywords.c keywords.h : keywords.sh
# ${HOST_SH} keywords.sh
-#
-# Compile-time debug flag. If compiled with "make RUMP_ACTION=1",
-# make rump system calls.
-#
-.ifdef RUMP_ACTION
-CPPFLAGS+= -DRUMP_SYS_NETWORKING -DRUMP_SYS_READWRITE -DRUMP_SYS_CLOSE
-CPPFLAGS+= -DRUMP_ACTION -DSMALL -Dsysctl=rump_sys___sysctl
-LDADD+= -lrumpclient
-DBG= -g
-.endif
-
.include <bsd.prog.mk>
Index: src/sbin/route/route.c
diff -u src/sbin/route/route.c:1.126 src/sbin/route/route.c:1.127
--- src/sbin/route/route.c:1.126 Fri Nov 12 16:32:18 2010
+++ src/sbin/route/route.c Mon Dec 13 17:39:47 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.126 2010/11/12 16:32:18 roy Exp $ */
+/* $NetBSD: route.c,v 1.127 2010/12/13 17:39:47 pooka Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: route.c,v 1.126 2010/11/12 16:32:18 roy Exp $");
+__RCSID("$NetBSD: route.c,v 1.127 2010/12/13 17:39:47 pooka Exp $");
#endif
#endif /* not lint */
@@ -71,14 +71,13 @@
#include <paths.h>
#include <err.h>
-#ifdef RUMP_ACTION
#include <rump/rump.h>
#include <rump/rump_syscalls.h>
#include <rump/rumpclient.h>
-#endif
#include "keywords.h"
#include "extern.h"
+#include "prog_ops.h"
union sockunion {
struct sockaddr sa;
@@ -162,11 +161,6 @@
{
int ch;
-#ifdef RUMP_ACTION
- if (rumpclient_init() == -1)
- err(1, "rump client init");
-#endif
-
if (argc < 2)
usage(NULL);
@@ -204,11 +198,14 @@
argc -= optind;
argv += optind;
- pid = getpid();
+ if (prog_init && prog_init() == -1)
+ err(1, "init failed");
+
+ pid = prog_getpid();
if (tflag)
- sock = open("/dev/null", O_WRONLY, 0);
+ sock = prog_open("/dev/null", O_WRONLY, 0);
else
- sock = socket(PF_ROUTE, SOCK_RAW, 0);
+ sock = prog_socket(PF_ROUTE, SOCK_RAW, 0);
if (sock < 0)
err(EXIT_FAILURE, "socket");
@@ -269,7 +266,8 @@
flags = 0;
af = AF_UNSPEC;
- shutdown(sock, SHUT_RD); /* Don't want to read back our messages */
+ /* Don't want to read back our messages */
+ prog_shutdown(sock, SHUT_RD);
parse_show_opts(argc, argv, &af, &flags, &afname, false);
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
@@ -277,13 +275,13 @@
mib[3] = 0; /* wildcard address family */
mib[4] = NET_RT_DUMP;
mib[5] = 0; /* no flags */
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(EXIT_FAILURE, "route-sysctl-estimate");
buf = lim = NULL;
if (needed) {
if ((buf = malloc(needed)) == NULL)
err(EXIT_FAILURE, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
err(EXIT_FAILURE, "actual retrieval of routing table");
lim = buf + needed;
}
@@ -311,7 +309,8 @@
continue;
rtm->rtm_type = RTM_DELETE;
rtm->rtm_seq = seqno;
- if ((rlen = write(sock, next, rtm->rtm_msglen)) < 0) {
+ if ((rlen = prog_write(sock, next,
+ rtm->rtm_msglen)) < 0) {
warnx("writing to routing socket: %s",
route_strerror(errno));
return 1;
@@ -801,8 +800,10 @@
cmd = argv[0];
af = AF_UNSPEC;
- if (*cmd != 'g')
- shutdown(sock, SHUT_RD); /* Don't want to read back our messages */
+ if (*cmd != 'g') {
+ /* Don't want to read back our messages */
+ prog_shutdown(sock, SHUT_RD);
+ }
while (--argc > 0) {
if (**(++argv)== '-') {
switch (key = keyword(1 + *argv)) {
@@ -1419,12 +1420,12 @@
mib[3] = 0; /* wildcard address family */
mib[4] = NET_RT_IFLIST;
mib[5] = 0; /* no flags */
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(EXIT_FAILURE, "route-sysctl-estimate");
if (needed) {
if ((buf = malloc(needed)) == NULL)
err(EXIT_FAILURE, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
+ if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
err(EXIT_FAILURE,
"actual retrieval of interface table");
}
@@ -1453,7 +1454,7 @@
}
for(;;) {
time_t now;
- n = read(sock, &u, sizeof(u));
+ n = prog_read(sock, &u, sizeof(u));
now = time(NULL);
(void)printf("got message of size %d on %s", n, ctime(&now));
print_rtmsg(&u.hdr, n);
@@ -1529,7 +1530,7 @@
}
if (debugonly)
return 0;
- if ((rlen = write(sock, (char *)&m_rtmsg, l)) < 0) {
+ if ((rlen = prog_write(sock, (char *)&m_rtmsg, l)) < 0) {
warnx("writing to routing socket: %s", route_strerror(errno));
return -1;
}
@@ -1540,7 +1541,8 @@
#ifndef SMALL
if (cmd == RTM_GET) {
do {
- l = read(sock, (char *)&m_rtmsg, sizeof(m_rtmsg));
+ l = prog_read(sock,
+ (char *)&m_rtmsg, sizeof(m_rtmsg));
} while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid));
if (l < 0)
err(EXIT_FAILURE, "read from routing socket");
Index: src/sbin/route/show.c
diff -u src/sbin/route/show.c:1.41 src/sbin/route/show.c:1.42
--- src/sbin/route/show.c:1.41 Sat Jun 26 14:29:36 2010
+++ src/sbin/route/show.c Mon Dec 13 17:39:47 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.41 2010/06/26 14:29:36 kefren Exp $ */
+/* $NetBSD: show.c,v 1.42 2010/12/13 17:39:47 pooka Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-__RCSID("$NetBSD: show.c,v 1.41 2010/06/26 14:29:36 kefren Exp $");
+__RCSID("$NetBSD: show.c,v 1.42 2010/12/13 17:39:47 pooka Exp $");
#endif
#endif /* not lint */
@@ -63,6 +63,7 @@
#include "keywords.h"
#include "extern.h"
+#include "prog_ops.h"
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
@@ -188,13 +189,13 @@
mib[3] = 0;
mib[4] = NET_RT_DUMP;
mib[5] = 0;
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(EXIT_FAILURE, "route-sysctl-estimate");
buf = lim = NULL;
if (needed) {
if ((buf = malloc(needed)) == 0)
err(EXIT_FAILURE, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
err(EXIT_FAILURE, "sysctl of routing table");
lim = buf + needed;
}
Added files:
Index: src/sbin/route/prog_ops.h
diff -u /dev/null src/sbin/route/prog_ops.h:1.1
--- /dev/null Mon Dec 13 17:39:47 2010
+++ src/sbin/route/prog_ops.h Mon Dec 13 17:39:47 2010
@@ -0,0 +1,60 @@
+/* $NetBSD: prog_ops.h,v 1.1 2010/12/13 17:39:47 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PROG_OPS_H_
+#define _PROG_OPS_H_
+
+#include <sys/types.h>
+
+struct prog_ops {
+ int (*op_init)(void);
+
+ int (*op_socket)(int, int, int);
+ int (*op_open)(const char *, int, ...);
+ pid_t (*op_getpid)(void);
+
+ ssize_t (*op_read)(int, void *, size_t);
+ ssize_t (*op_write)(int, const void *, size_t);
+
+ int (*op_sysctl)(const int *, u_int, void *, size_t *,
+ const void *, size_t);
+
+ int (*op_shutdown)(int, int);
+};
+extern const struct prog_ops prog_ops;
+
+#define prog_init prog_ops.op_init
+#define prog_socket prog_ops.op_socket
+#define prog_open prog_ops.op_open
+#define prog_getpid prog_ops.op_getpid
+#define prog_read prog_ops.op_read
+#define prog_write prog_ops.op_write
+#define prog_sysctl prog_ops.op_sysctl
+#define prog_shutdown prog_ops.op_shutdown
+
+#endif /* _PROG_OPS_H_ */
Index: src/sbin/route/route_hostops.c
diff -u /dev/null src/sbin/route/route_hostops.c:1.1
--- /dev/null Mon Dec 13 17:39:47 2010
+++ src/sbin/route/route_hostops.c Mon Dec 13 17:39:47 2010
@@ -0,0 +1,54 @@
+/* $NetBSD: route_hostops.c,v 1.1 2010/12/13 17:39:47 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: route_hostops.c,v 1.1 2010/12/13 17:39:47 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+ .op_socket = socket,
+ .op_open = open,
+ .op_getpid = getpid,
+
+ .op_read = read,
+ .op_write = write,
+
+ .op_sysctl = sysctl,
+
+ .op_shutdown = shutdown,
+};
Index: src/sbin/route/route_rumpops.c
diff -u /dev/null src/sbin/route/route_rumpops.c:1.1
--- /dev/null Mon Dec 13 17:39:47 2010
+++ src/sbin/route/route_rumpops.c Mon Dec 13 17:39:47 2010
@@ -0,0 +1,58 @@
+/* $NetBSD: route_rumpops.c,v 1.1 2010/12/13 17:39:47 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: route_rumpops.c,v 1.1 2010/12/13 17:39:47 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <unistd.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+#include <rump/rumpclient.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+ .op_init = rumpclient_init,
+
+ .op_socket = rump_sys_socket,
+ .op_open = rump_sys_open,
+ .op_getpid = rump_sys_getpid,
+
+ .op_read = rump_sys_read,
+ .op_write = rump_sys_write,
+
+ .op_sysctl = rump_sys___sysctl,
+
+ .op_shutdown = rump_sys_shutdown,
+};