Module Name:    src
Committed By:   pooka
Date:           Tue Dec 14 17:46:21 UTC 2010

Modified Files:
        src/sbin/cgdconfig: Makefile cgdconfig.c
Added Files:
        src/sbin/cgdconfig: cgdconfig_hostops.c cgdconfig_rumpops.c prog_ops.h
Removed Files:
        src/sbin/cgdconfig: Makefile.cgdconfig cgd_kernelops.c cgd_kernelops.h
            cgd_rumpops.c

Log Message:
Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG.  Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sbin/cgdconfig/Makefile
cvs rdiff -u -r1.3 -r0 src/sbin/cgdconfig/Makefile.cgdconfig \
    src/sbin/cgdconfig/cgd_kernelops.h
cvs rdiff -u -r1.2 -r0 src/sbin/cgdconfig/cgd_kernelops.c
cvs rdiff -u -r1.1 -r0 src/sbin/cgdconfig/cgd_rumpops.c
cvs rdiff -u -r1.31 -r1.32 src/sbin/cgdconfig/cgdconfig.c
cvs rdiff -u -r0 -r1.1 src/sbin/cgdconfig/cgdconfig_hostops.c \
    src/sbin/cgdconfig/cgdconfig_rumpops.c src/sbin/cgdconfig/prog_ops.h

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

Modified files:

Index: src/sbin/cgdconfig/Makefile
diff -u src/sbin/cgdconfig/Makefile:1.13 src/sbin/cgdconfig/Makefile:1.14
--- src/sbin/cgdconfig/Makefile:1.13	Sat Dec 19 15:03:34 2009
+++ src/sbin/cgdconfig/Makefile	Tue Dec 14 17:46:21 2010
@@ -1,8 +1,20 @@
-# $NetBSD: Makefile,v 1.13 2009/12/19 15:03:34 pooka Exp $
+# $NetBSD: Makefile,v 1.14 2010/12/14 17:46:21 pooka Exp $
 
-PROG=	cgdconfig
+RUMPPRG=cgdconfig
 MAN=	cgdconfig.8
 
-.include "${.CURDIR}/Makefile.cgdconfig"
+SRCS+=	cgdconfig.c		\
+	cgdlex.l		\
+	cgdparse.y		\
+	pkcs5_pbkdf2.c		\
+	params.c		\
+	utils.c
+
+CPPFLAGS+= -I${.CURDIR} -I. -DYY_NO_INPUT
+
+YHEADER=1
+
+DPADD=  ${LIBUTIL} ${LIBCRYPTO} ${LIBCRYPT} ${LIBY} ${LIBL}
+LDADD=  -lutil -lcrypto -lcrypt -ly -ll
 
 .include <bsd.prog.mk>

Index: src/sbin/cgdconfig/cgdconfig.c
diff -u src/sbin/cgdconfig/cgdconfig.c:1.31 src/sbin/cgdconfig/cgdconfig.c:1.32
--- src/sbin/cgdconfig/cgdconfig.c:1.31	Thu Dec  2 18:02:58 2010
+++ src/sbin/cgdconfig/cgdconfig.c	Tue Dec 14 17:46:21 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.31 2010/12/02 18:02:58 elric Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.32 2010/12/14 17:46:21 pooka Exp $ */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 2002, 2003\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.31 2010/12/02 18:02:58 elric Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.32 2010/12/14 17:46:21 pooka Exp $");
 #endif
 
 #include <err.h>
@@ -59,8 +59,8 @@
 #include "params.h"
 #include "pkcs5_pbkdf2.h"
 #include "utils.h"
-#include "cgd_kernelops.h"
 #include "cgdconfig.h"
+#include "prog_ops.h"
 
 #define CGDCONFIG_DIR		"/etc/cgd"
 #define CGDCONFIG_CFILE		CGDCONFIG_DIR "/cgd.conf"
@@ -170,18 +170,9 @@
 	*action = value;
 }
 
-#ifndef CGDCONFIG_AS_LIB
 int
 main(int argc, char **argv)
 {
-
-	return cgdconfig(argc, argv);
-}
-#endif
-
-int
-cgdconfig(int argc, char *argv[])
-{
 	struct params *p;
 	struct params *tp;
 	struct keygen *kg;
@@ -278,6 +269,9 @@
 	if (!cfile)
 		cfile = "";
 
+	if (prog_init && prog_init() == -1)
+		err(1, "init failed");
+
 	/* validate the consistency of the arguments */
 
 	switch (action) {
@@ -458,7 +452,7 @@
 	if (flags == CONFIG_FLAGS_FROMALL && (argc < 2 || argc > 3))
 		return -1;
 
-	fd = opendisk1(*argv, O_RDWR, buf, sizeof(buf), 1, cgd_kops.ko_open);
+	fd = opendisk1(*argv, O_RDWR, buf, sizeof(buf), 1, prog_open);
 	if (fd == -1) {
 		int saved_errno = errno;
 
@@ -475,7 +469,7 @@
 		return 0;
 
 	ret = unconfigure_fd(fd);
-	(void)cgd_kops.ko_close(fd);
+	(void)prog_close(fd);
 	return ret;
 }
 
@@ -484,7 +478,7 @@
 {
 	struct	cgd_ioctl ci;
 
-	if (cgd_kops.ko_ioctl(fd, CGDIOCCLR, &ci) == -1) {
+	if (prog_ioctl(fd, CGDIOCCLR, &ci) == -1) {
 		warn("ioctl");
 		return -1;
 	}
@@ -583,7 +577,7 @@
 			break;
 
 		(void)unconfigure_fd(fd);
-		(void)cgd_kops.ko_close(fd);
+		(void)prog_close(fd);
 
 		if (!loop) {
 			warnx("verification failed permanently");
@@ -594,11 +588,11 @@
 	}
 
 	params_free(p);
-	(void)cgd_kops.ko_close(fd);
+	(void)prog_close(fd);
 	return 0;
 bail_err:
 	params_free(p);
-	(void)cgd_kops.ko_close(fd);
+	(void)prog_close(fd);
 	return -1;
 }
 
@@ -657,7 +651,7 @@
 		return 0;
 	}
 
-	fd = opendisk1(cgd, O_RDWR, buf, buflen, 0, cgd_kops.ko_open);
+	fd = opendisk1(cgd, O_RDWR, buf, buflen, 0, prog_open);
 	if (fd == -1)
 		warnx("can't open cgd \"%s\", \"%s\"", cgd, buf);
 
@@ -691,7 +685,7 @@
 	if (nflag)
 		return 0;
 
-	if (cgd_kops.ko_ioctl(fd, CGDIOCSET, &ci) == -1) {
+	if (prog_ioctl(fd, CGDIOCSET, &ci) == -1) {
 		int saved_errno = errno;
 		warn("ioctl");
 		return saved_errno;
@@ -739,7 +733,7 @@
 	 * partition information.
 	 */
 
-	ret = cgd_kops.ko_pread(fd, buf, 8192, 0);
+	ret = prog_pread(fd, buf, 8192, 0);
 	if (ret < 0) {
 		warn("can't read disklabel area");
 		return -1;
@@ -764,7 +758,7 @@
 		} u;
 		ssize_t ret;
 
-		ret = cgd_kops.ko_pread(fd, &u, sizeof(u), sblock_try[i]);
+		ret = prog_pread(fd, &u, sizeof(u), sblock_try[i]);
 		if (ret < 0) {
 			warn("pread");
 			break;

Added files:

Index: src/sbin/cgdconfig/cgdconfig_hostops.c
diff -u /dev/null src/sbin/cgdconfig/cgdconfig_hostops.c:1.1
--- /dev/null	Tue Dec 14 17:46:21 2010
+++ src/sbin/cgdconfig/cgdconfig_hostops.c	Tue Dec 14 17:46:21 2010
@@ -0,0 +1,47 @@
+/*	$NetBSD: cgdconfig_hostops.c,v 1.1 2010/12/14 17:46:21 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2009 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: cgdconfig_hostops.c,v 1.1 2010/12/14 17:46:21 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+	.op_open = open,
+	.op_ioctl = ioctl,
+	.op_pread = pread,
+	.op_close = close,
+};
Index: src/sbin/cgdconfig/cgdconfig_rumpops.c
diff -u /dev/null src/sbin/cgdconfig/cgdconfig_rumpops.c:1.1
--- /dev/null	Tue Dec 14 17:46:21 2010
+++ src/sbin/cgdconfig/cgdconfig_rumpops.c	Tue Dec 14 17:46:21 2010
@@ -0,0 +1,49 @@
+/*	$NetBSD: cgdconfig_rumpops.c,v 1.1 2010/12/14 17:46:21 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2009 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: cgdconfig_rumpops.c,v 1.1 2010/12/14 17:46:21 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/ioctl.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_open =	rump_sys_open,
+	.op_ioctl =	rump_sys_ioctl,
+	.op_pread =	rump_sys_pread,
+	.op_close =	rump_sys_close,
+};
Index: src/sbin/cgdconfig/prog_ops.h
diff -u /dev/null src/sbin/cgdconfig/prog_ops.h:1.1
--- /dev/null	Tue Dec 14 17:46:21 2010
+++ src/sbin/cgdconfig/prog_ops.h	Tue Dec 14 17:46:21 2010
@@ -0,0 +1,59 @@
+/*      $NetBSD: prog_ops.h,v 1.1 2010/12/14 17:46:21 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2009 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>
+
+#include <fcntl.h>
+
+#ifndef CRUNCHOPS
+struct prog_ops {
+	int (*op_init)(void);
+	int (*op_open)(const char *, int, ...);
+	int (*op_ioctl)(int, unsigned long, ...);
+	int (*op_close)(int);
+	ssize_t (*op_pread)(int, void *, size_t, off_t);
+};
+extern const struct prog_ops prog_ops;
+
+#define prog_init prog_ops.op_init
+#define prog_open prog_ops.op_open
+#define prog_ioctl prog_ops.op_ioctl
+#define prog_close prog_ops.op_close
+#define prog_pread prog_ops.op_pread
+#else
+#define prog_init ((int (*)(void))NULL)
+#define prog_open open
+#define prog_ioctl ioctl
+#define prog_close close
+#define prog_pread pread
+#endif
+
+#endif /* _PROG_OPS_H_ */

Reply via email to