Source-Changes-HG archive

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

[src/trunk]: src/sbin/luactl luactl(8) is a command to control lua(4)



details:   https://anonhg.NetBSD.org/src/rev/0848cdb34e22
branches:  trunk
changeset: 790539:0848cdb34e22
user:      mbalmer <mbalmer%NetBSD.org@localhost>
date:      Wed Oct 16 19:48:21 2013 +0000

description:
luactl(8) is a command to control lua(4)

diffstat:

 sbin/luactl/Makefile |    8 +
 sbin/luactl/luactl.8 |  126 +++++++++++++++++++++++++++
 sbin/luactl/luactl.c |  230 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 364 insertions(+), 0 deletions(-)

diffs (truncated from 376 to 300 lines):

diff -r bf96b897c56a -r 0848cdb34e22 sbin/luactl/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/luactl/Makefile      Wed Oct 16 19:48:21 2013 +0000
@@ -0,0 +1,8 @@
+#      $NetBSD: Makefile,v 1.1 2013/10/16 19:48:21 mbalmer Exp $
+
+PROG=  luactl
+SRCS=  luactl.c
+
+MAN=   luactl.8
+
+.include <bsd.prog.mk>
diff -r bf96b897c56a -r 0848cdb34e22 sbin/luactl/luactl.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/luactl/luactl.8      Wed Oct 16 19:48:21 2013 +0000
@@ -0,0 +1,126 @@
+.\" $NetBSD: luactl.8,v 1.1 2013/10/16 19:48:21 mbalmer Exp $
+.\"
+.\" Copyright (c) 2011 Marc Balmer <marc%msys.ch@localhost>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd August 26, 2011
+.Dt LUACTL 8
+.Os
+.Sh NAME
+.Nm luactl
+.Nd control kernel Lua states
+.Sh SYNOPSIS
+.Nm luactl
+.Op Fl cq
+.Nm luactl
+.Op Fl cq
+create
+.Ar name
+.Op desc
+.Nm luactl
+.Op Fl cq
+destroy
+.Ar name
+.Nm luactl
+.Op Fl cq
+require
+.Ar name module
+.Nm luactl
+.Op Fl cq
+load
+.Ar name path
+.Sh DESCRIPTION
+The
+.Nm
+program allows the manipulation of Lua states in the kernel.
+Lua states are created using the
+.Sq create
+command (see below),
+Lua bindings are provided as modules.
+To make a Lua binding available to a state, it must be
+.Sq required .
+If a kernel subsystem is to use a Lua state, a state has to be
+.Sq assigned
+to it.
+Once a module has been
+.Sq required
+by a state, it can not be unloaded from memory using the
+.Xr modunload 8
+command until the state using it has been destroyed.
+.Pp
+Lua code can be loaded from the filesystem into a state at anytime, please
+note that code loaded into a state is immediately executed.
+.Pp
+When executed without a command,
+.Nm
+reads information about the
+.Tn Lua
+states and displays it.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl c
+Create a Lua state before executing the command.
+This flag is used for the require, assing, and, load commands only, it
+is ignored for all other commands.
+.It Fl q
+Operate quietly i.e. nothing is printed to stdout.
+.El
+.Sh COMMANDS
+.Bl -tag -width Ds
+.It create Ar name Op Ar desc
+Create a Lua state with name
+.Ar name
+and optional description
+.Ar desc .
+.It destroy Ar name
+Destroy the Lua state
+.Ar name .
+.It require Ar name module
+Let the Lua state
+.Ar name
+use the bindings provided in module
+.Ar module .
+This is the equivalent of userland Lua code calling the
+.Sq require
+function.
+.It load Ar name Pa path
+Load Lua code in file
+.Pa path
+into the Lua state
+.Ar name .
+Note that the path name must contain at least one path separation character
+.Pq Sq / .
+.El
+.Sh FILES
+.Bl -tag -width "/dev/lua" -compact
+.It /dev/lua
+Lua device file.
+.El
+.Sh SEE ALSO
+.Xr lua 4 ,
+.Xr lua 9 ,
+.Xr modload 8 ,
+.Xr module 7 ,
+.Xr modunload 8
+.Sh HISTORY
+The
+.Nm
+command first appeared in
+.Nx 6.0 .
+.Sh AUTHORS
+The
+.Nm
+program was written by
+.An Marc Balmer Aq marc%msys.ch@localhost .
diff -r bf96b897c56a -r 0848cdb34e22 sbin/luactl/luactl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/luactl/luactl.c      Wed Oct 16 19:48:21 2013 +0000
@@ -0,0 +1,230 @@
+/*     $NetBSD: luactl.c,v 1.1 2013/10/16 19:48:21 mbalmer Exp $ */
+
+/*
+ * Copyright (c) 2011, Marc Balmer <mbalmer%NetBSD.org@localhost>.
+ * 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.
+ * 3. The name of the Author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 REGENTS 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.
+ */
+
+/*
+ * Program to control Lua devices.
+ */
+
+#include <stdbool.h>
+#include <sys/param.h>
+#include <sys/lua.h>
+#include <sys/ioctl.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int devfd = -1;
+int quiet = 0;
+int docreate = 0;
+
+static void getinfo(void);
+static void create(char *, char *);
+static void destroy(char *);
+
+static void require(char *, char *);
+static void load(char *, char *);
+
+static void usage(void);
+
+#define _PATH_DEV_LUA  "/dev/lua"
+
+int
+main(int argc, char *argv[])
+{
+       int ch;
+
+       while ((ch = getopt(argc, argv, "cq")) != -1)
+               switch (ch) {
+               case 'c':
+                       docreate = 1;
+                       break;
+               case 'q':
+                       quiet = 1;
+                       break;
+               default:
+                       usage();
+                       /* NOTREACHED */
+               }
+       argc -= optind;
+       argv += optind;
+
+       if ((devfd = open(_PATH_DEV_LUA, O_RDWR)) == -1)
+               err(EXIT_FAILURE, "%s", _PATH_DEV_LUA);
+
+       if (argc == 0)
+               getinfo();
+       else if (!strcmp(argv[0], "create")) {
+               if (argc == 2)
+                       create(argv[1], NULL);
+               else if (argc == 3)
+                       create(argv[1], argv[2]);
+               else
+                       usage();
+       } else if (!strcmp(argv[0], "destroy")) {
+               if (argc != 2)
+                       usage();
+               destroy(argv[1]);
+       } else if (!strcmp(argv[0], "require")) {
+               if (argc != 3)
+                       usage();
+               if (docreate)
+                       create(argv[1], NULL);
+               require(argv[1], argv[2]);
+       } else if (!strcmp(argv[0], "load")) {
+               if (argc != 3)
+                       usage();
+               if (docreate)
+                       create(argv[1], NULL);
+               load(argv[1], argv[2]);
+       } else
+               usage();
+
+       return EXIT_SUCCESS;
+}
+
+static void
+getinfo(void)
+{
+       struct lua_info info;
+       int n;
+
+       info.states = NULL;
+       if (ioctl(devfd, LUAINFO, &info) == -1)
+               err(EXIT_FAILURE, "LUAINFO");
+
+       if (info.num_states > 0) {
+               info.states = calloc(info.num_states,
+                   sizeof(struct lua_state_info));
+               if (info.states == NULL)
+                       err(EXIT_FAILURE, "calloc");
+               if (ioctl(devfd, LUAINFO, &info) == -1)
+                       err(EXIT_FAILURE, "LUAINFO");
+       }
+       printf("%d active state%s:\n", info.num_states,
+           info.num_states == 1 ? "" : "s");
+       if (info.num_states > 0)
+               printf("%-16s %-8s Description\n", "Name", "Creator");
+       for (n = 0; n < info.num_states; n++)
+               printf("%-16s %-8s %s\n", info.states[n].name,
+                   info.states[n].user == true ? "user" : "kernel",
+                   info.states[n].desc);
+}
+
+static void
+create(char *name, char *desc)
+{
+       struct lua_create cr;
+
+       strlcpy(cr.name, name, sizeof(cr.name));
+       if (desc != NULL)
+               strlcpy(cr.desc, desc, sizeof(cr.desc));



Home | Main Index | Thread Index | Old Index