summaryrefslogtreecommitdiff
path: root/sys/modules/example/example.c
diff options
context:
space:
mode:
authorjmmv <jmmv@NetBSD.org>2008-03-02 11:19:30 +0000
committerjmmv <jmmv@NetBSD.org>2008-03-02 11:19:30 +0000
commitc062e0737663e5189695dcd227ff2a894fdc971c (patch)
tree5a40ef6605deddffdcb9cf7f8d64afbdd4cd35e1 /sys/modules/example/example.c
parent3fd8e29a1190e981c69e1e06bc1441ba121ae571 (diff)
Add an example on how to handle the incoming properties during module load.
Diffstat (limited to 'sys/modules/example/example.c')
-rw-r--r--sys/modules/example/example.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/sys/modules/example/example.c b/sys/modules/example/example.c
index 4eed2c9243d..923b8fdff57 100644
--- a/sys/modules/example/example.c
+++ b/sys/modules/example/example.c
@@ -1,4 +1,4 @@
-/* $NetBSD: example.c,v 1.1 2008/01/16 12:34:57 ad Exp $ */
+/* $NetBSD: example.c,v 1.2 2008/03/02 11:19:30 jmmv Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: example.c,v 1.1 2008/01/16 12:34:57 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: example.c,v 1.2 2008/03/02 11:19:30 jmmv Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -42,6 +42,26 @@ __KERNEL_RCSID(0, "$NetBSD: example.c,v 1.1 2008/01/16 12:34:57 ad Exp $");
MODULE(MODULE_CLASS_MISC, example, NULL);
+static
+void
+handle_props(prop_dictionary_t props)
+{
+ prop_string_t str;
+
+ str = prop_dictionary_get(props, "msg");
+ if (str == NULL)
+ printf("The 'msg' property was not given.\n");
+ else if (prop_object_type(str) != PROP_TYPE_STRING)
+ printf("The 'msg' property is not a string.\n");
+ else {
+ const char *msg = prop_string_cstring_nocopy(str);
+ if (msg == NULL)
+ printf("Failed to process the 'msg' property.\n");
+ else
+ printf("The 'msg' property is: %s\n", msg);
+ }
+}
+
static int
example_modcmd(modcmd_t cmd, void *arg)
{
@@ -49,6 +69,7 @@ example_modcmd(modcmd_t cmd, void *arg)
switch (cmd) {
case MODULE_CMD_INIT:
printf("Example module loaded.\n");
+ handle_props(arg);
break;
case MODULE_CMD_FINI: