Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/route Convert from RUMP_ACTION to RUMPPRG.



details:   https://anonhg.NetBSD.org/src/rev/d9fd708553ef
branches:  trunk
changeset: 759602:d9fd708553ef
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Dec 13 17:39:47 2010 +0000

description:
Convert from RUMP_ACTION to RUMPPRG.

diffstat:

 sbin/route/Makefile        |  15 +---------
 sbin/route/prog_ops.h      |  60 ++++++++++++++++++++++++++++++++++++++++++++++
 sbin/route/route.c         |  48 +++++++++++++++++++-----------------
 sbin/route/route_hostops.c |  54 +++++++++++++++++++++++++++++++++++++++++
 sbin/route/route_rumpops.c |  58 ++++++++++++++++++++++++++++++++++++++++++++
 sbin/route/show.c          |   9 +++---
 6 files changed, 204 insertions(+), 40 deletions(-)

diffs (truncated from 413 to 300 lines):

diff -r 81f697df824b -r d9fd708553ef sbin/route/Makefile
--- a/sbin/route/Makefile       Mon Dec 13 17:35:31 2010 +0000
+++ b/sbin/route/Makefile       Mon Dec 13 17:39:47 2010 +0000
@@ -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>
diff -r 81f697df824b -r d9fd708553ef sbin/route/prog_ops.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/route/prog_ops.h     Mon Dec 13 17:39:47 2010 +0000
@@ -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_ */
diff -r 81f697df824b -r d9fd708553ef sbin/route/route.c
--- a/sbin/route/route.c        Mon Dec 13 17:35:31 2010 +0000
+++ b/sbin/route/route.c        Mon Dec 13 17:39:47 2010 +0000
@@ -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");
diff -r 81f697df824b -r d9fd708553ef sbin/route/route_hostops.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/route/route_hostops.c        Mon Dec 13 17:39:47 2010 +0000
@@ -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,



Home | Main Index | Thread Index | Old Index