Module Name: src
Committed By: pgoyette
Date: Sun Dec 19 22:52:08 UTC 2010
Modified Files:
src/usr.sbin/powerd: Makefile powerd.c
Added Files:
src/usr.sbin/powerd: powerd_hostops.c powerd_rumpops.c prog_ops.h
Log Message:
Rump-ify powerd.
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/powerd/Makefile
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/powerd/powerd.c
cvs rdiff -u -r0 -r1.1 src/usr.sbin/powerd/powerd_hostops.c \
src/usr.sbin/powerd/powerd_rumpops.c src/usr.sbin/powerd/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/usr.sbin/powerd/Makefile
diff -u src/usr.sbin/powerd/Makefile:1.5 src/usr.sbin/powerd/Makefile:1.6
--- src/usr.sbin/powerd/Makefile:1.5 Wed Apr 22 15:23:06 2009
+++ src/usr.sbin/powerd/Makefile Sun Dec 19 22:52:08 2010
@@ -1,8 +1,14 @@
-# $NetBSD: Makefile,v 1.5 2009/04/22 15:23:06 lukem Exp $
+# $NetBSD: Makefile,v 1.6 2010/12/19 22:52:08 pgoyette Exp $
PROG= powerd
SRCS= powerd.c
+RUMPPRG= powerd
+
+.PATH: ${.CURDIR}/../../common/lib/libprop
+CPPFLAGS+= -DRUMP_ACTION
+RUMPSRCS+= prop_kern.c
+
DPADD+= ${LIBPROP} ${LIBUTIL}
LDADD+= -lprop -lutil
Index: src/usr.sbin/powerd/powerd.c
diff -u src/usr.sbin/powerd/powerd.c:1.15 src/usr.sbin/powerd/powerd.c:1.16
--- src/usr.sbin/powerd/powerd.c:1.15 Wed Dec 15 17:12:40 2010
+++ src/usr.sbin/powerd/powerd.c Sun Dec 19 22:52:08 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: powerd.c,v 1.15 2010/12/15 17:12:40 pgoyette Exp $ */
+/* $NetBSD: powerd.c,v 1.16 2010/12/19 22:52:08 pgoyette Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -42,10 +42,12 @@
#define SYSLOG_NAMES
#include <sys/cdefs.h>
+#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/event.h>
#include <sys/power.h>
#include <sys/wait.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
@@ -59,6 +61,8 @@
#include <stdarg.h>
#include <string.h>
+#include "prog_ops.h"
+
int debug, no_scripts;
static int kq;
@@ -88,6 +92,9 @@
setprogname(*argv);
+ if (prog_init && prog_init() == -1)
+ err(1, "init failed");
+
while ((ch = getopt(argc, argv, "dn")) != -1) {
switch (ch) {
case 'd':
@@ -115,24 +122,24 @@
(void)pidfile(NULL);
}
- if ((kq = kqueue()) == -1) {
+ if ((kq = prog_kqueue()) == -1) {
powerd_log(LOG_ERR, "kqueue: %s", strerror(errno));
exit(EX_OSERR);
}
- if ((fd = open(_PATH_POWER, O_RDONLY|O_NONBLOCK, 0600)) == -1) {
+ if ((fd = prog_open(_PATH_POWER, O_RDONLY|O_NONBLOCK, 0600)) == -1) {
powerd_log(LOG_ERR, "open %s: %s", _PATH_POWER,
strerror(errno));
exit(EX_OSERR);
}
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
+ if (prog_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
powerd_log(LOG_ERR, "Cannot set close on exec in power fd: %s",
strerror(errno));
exit(EX_OSERR);
}
- if (ioctl(fd, POWER_IOC_GET_TYPE, &power_type) == -1) {
+ if (prog_ioctl(fd, POWER_IOC_GET_TYPE, &power_type) == -1) {
powerd_log(LOG_ERR, "POWER_IOC_GET_TYPE: %s", strerror(errno));
exit(EX_OSERR);
}
@@ -254,7 +261,7 @@
{
int rv;
- while ((rv = kevent(kq, nchanges ? changebuf : NULL, nchanges,
+ while ((rv = prog_kevent(kq, nchanges ? changebuf : NULL, nchanges,
events, nevents, NULL)) < 0) {
nchanges = 0;
if (errno != EINTR) {
@@ -278,7 +285,7 @@
ev->data, ev->data > 1 ? "s" : "");
again:
- if (read(fd, &pev, sizeof(pev)) != sizeof(pev)) {
+ if (prog_read(fd, &pev, sizeof(pev)) != sizeof(pev)) {
if (errno == EWOULDBLOCK)
return;
powerd_log(LOG_ERR, "read of %s: %s", _PATH_POWER,
Added files:
Index: src/usr.sbin/powerd/powerd_hostops.c
diff -u /dev/null src/usr.sbin/powerd/powerd_hostops.c:1.1
--- /dev/null Sun Dec 19 22:52:08 2010
+++ src/usr.sbin/powerd/powerd_hostops.c Sun Dec 19 22:52:08 2010
@@ -0,0 +1,51 @@
+/* $NetBSD: powerd_hostops.c,v 1.1 2010/12/19 22:52:08 pgoyette 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: powerd_hostops.c,v 1.1 2010/12/19 22:52:08 pgoyette Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/event.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_close = close,
+ .op_read = read,
+ .op_fcntl = fcntl,
+ .op_ioctl = ioctl,
+ .op_kevent = kevent,
+ .op_kqueue = kqueue,
+};
Index: src/usr.sbin/powerd/powerd_rumpops.c
diff -u /dev/null src/usr.sbin/powerd/powerd_rumpops.c:1.1
--- /dev/null Sun Dec 19 22:52:08 2010
+++ src/usr.sbin/powerd/powerd_rumpops.c Sun Dec 19 22:52:08 2010
@@ -0,0 +1,54 @@
+/* $NetBSD: powerd_rumpops.c,v 1.1 2010/12/19 22:52:08 pgoyette 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: powerd_rumpops.c,v 1.1 2010/12/19 22:52:08 pgoyette Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/event.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_close = rump_sys_close,
+ .op_read = rump_sys_read,
+ .op_fcntl = rump_sys_fcntl,
+ .op_ioctl = rump_sys_ioctl,
+ .op_kevent = rump_sys_kevent,
+ .op_kqueue = rump_sys_kqueue,
+};
Index: src/usr.sbin/powerd/prog_ops.h
diff -u /dev/null src/usr.sbin/powerd/prog_ops.h:1.1
--- /dev/null Sun Dec 19 22:52:08 2010
+++ src/usr.sbin/powerd/prog_ops.h Sun Dec 19 22:52:08 2010
@@ -0,0 +1,59 @@
+/* $NetBSD: prog_ops.h,v 1.1 2010/12/19 22:52:08 pgoyette 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>
+#include <sys/event.h>
+#include <sys/time.h>
+
+struct prog_ops {
+ int (*op_init)(void);
+
+ int (*op_open)(const char *, int, ...);
+ int (*op_close)(int);
+ ssize_t (*op_read)(int, void *, size_t);
+ int (*op_fcntl)(int, int, ...);
+ int (*op_ioctl)(int, unsigned long, ...);
+ int (*op_kqueue)(void);
+ int (*op_kevent)(int, const struct kevent *, size_t, struct kevent *,
+ size_t, const struct timespec *);
+};
+extern const struct prog_ops prog_ops;
+
+#define prog_init prog_ops.op_init
+#define prog_open prog_ops.op_open
+#define prog_close prog_ops.op_close
+#define prog_read prog_ops.op_read
+#define prog_kevent prog_ops.op_kevent
+#define prog_ioctl prog_ops.op_ioctl
+#define prog_fcntl prog_ops.op_fcntl
+#define prog_kqueue prog_ops.op_kqueue
+
+#endif /* _PROG_OPS_H_ */