lua-users home
lua-l archive

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


It was thus said that the Great Gary V. Vaughan once stated:
> Hi Steve,
> 
> Thanks for the feedback :)
> 
> > On 27 Feb 2016, at 15:02, steve donovan <steve.j.donovan@gmail.com> wrote:
> > 
> > On Sat, Feb 27, 2016 at 4:44 PM, Gary V. Vaughan <gary@vaughan.pe> wrote:
> >>  - posix.curses has been split back out into its own separate
> >>    project again.
> > 
> > Gary, I think this is a good decision.  Most Lua people on Unix-y
> > systems need luaposix to interface with the system. Curses programming
> > is entertaining, but a minority pursuit.
> 
> I thinks so too. Also, it allows the lcurses binding not to be constrained
> by the POSIX curses API, so we can add ncurses mouse functions among others.
> 
> I’ve been on a simplify-and-separate binge of late, and have been wondering
> whether luaposix is more useful as one giant library that tries to cover the
> entire POSIX API, or whether it would be better to follow stdlib’s lead and
> break it into multiple rocks along some (yet-to-be-determined) boundaries,
> with a backwards compatibility luaposix rock that pulls in everything else?

  I have my own POSIX bindings [1] and they're split along functional lines,
file system calls, process calls, signals, clocks, polling (with select(),
poll() or epoll(), depending upon the Unix system) and syslog.  Some
thoughts from using these for several years now:

1) It's nice that I don't have to include a ton of code when all I want is
syslog(), or sleep() (actually org.conman.clock.sleep() by the way---more on
this odd decision later).

2) But it does mean that when I'm doing a heavy POSIX program, it's a lot
of:

	local process = require "org.conman.process" -- fork(), etc
	local signal  = require "org.conman.signal"  -- signals
	local getopt  = require "org.conman.getopt"  -- parse command line
	local syslog  = require "org.conman.syslog"  -- syslog
	local errno   = require "org.conman.errno"   -- defines for errors
	local fsys    = require "org.conman.fsys"    -- file system calls
	local net     = require "org.conman.net"     -- network code
	local sys     = require "org.conman.sys"     -- um ... [2]

Somewhat of a pain, but it does provide a measure of what the program does,
and the potential surface for an attack.  The above is from a daemon I'm
currently writing.  

3) Getting back to org.conman.clock.sleep() and why that isn't under the
process module---there are some functions that could easily live under
different modules.  org.conman.clock.sleep() is one.  In fact,
org.conman.clock is an interesting module since several functions could
easily live in other modules:

	get()
		Okay, this seems reasonable for org.conman.clock and not
		elsewhere.

	set()
		Same for this one.

	itimer()
		This sets up a repeating signal (SIGALRM), so it could also
		easily exist in the signal module.

	sleep()
		Puts the current process to sleep.  This could easily live
		in the process module.

Other functions that could live in multiple locations:

	org.conman.signal.raise()
		It deals with signals, but since it also deals with
		processes, it could be in org.conman.process as well.

	sock           = org.conman.net.socket('ip','tcp')
	sock.nonblock  = true -- this is cross purpose
	sock.closeexec = true -- so is this
		These two statements end up calling fcntl() [3] even though
		fcntl() also works on files.  I did a special case here
		because I use those two flags often in network programming
		and it didn't make sense to just include org.conman.fsys [4]
		just for this.

4) Separate modules have separate release dates.  At least in my case.  So
that means that org.conman.syslog is at 2.1.3, org.conman.sys is at 1.4.0
and org.conman.errno is at 1.0.1 (for my POSIX like modules that have been
released as LuaRocks).  So, *if* you split the POSIX module up, does an
upgrade of one module mean only that module gets a new version, or all
modules get a new version?  I have seperate versions, so I'm already going
down that road.

> It was surprising how much cruft I was able to eject by splitting up stdlib,
> and making a clean break from supporting older versions of the API — and
> luaposix is carrying many hundreds of lines of code to support deprecated
> calls and types, so it would likely benefit even more.

  What I've found annoying is that Mac OS-X is following an older POSIX
standard than the rest of the Unix world (mostly visible in the
org.conman.clock module).  

  -spc (Another annoying aspect---some projects at work use my POSIX
	libraries, but older versions---each project a different version.  I
	keep forgetting that the versions in use still have signals under
	the process module)

[1]	Pretty much most of https://github.com/spc476/lua-conmanorg/tree/master/src

[2]	Useful POSIX constants:

[spc]lucy:~/source/gopher-blog>lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> sys = require "org.conman.sys"
> dump = require "org.conman.table".dump
> dump("sys",sys)
sys =
{
  SYSNAME = "Linux",
  MACHINE = "i686",
  ENDIAN = "little",
  POSIX =
  {
    NAME_MAX = 65536.000000,
    OPEN_MAX = 1024.000000,
    HOST_NAME_MAX = 64.000000,
    RTSIG_MAX = 32.000000,
    TZNAME_MAX = 6.000000,
    STREAM_MAX = 16.000000,
    SIGQUEUE_MAX = -1.000000,
    RE_DUP_MAX = 32767.000000,
    VERSION = 200112.000000,
    LOGIN_NAME_MAX = 256.000000,
    PATH_MAX = 1024.000000,
    NGROUPS_MAX = 65536.000000,
    TTY_NAME_MAX = 32.000000,
    CHILD_MAX = 999.000000,
    PAGESIZE = 4096.000000,
    PIPE_BUF = 16.000000,
    CLK_TCK = 100.000000,
    ARG_MAX = 131072.000000,
  },
  PATHS =
  {
    mounted = "/etc/mtab",
    console = "/dev/console",
    sendmail = "/usr/sbin/sendmail",
    lastlog = "/var/log/lastlog",
    varrun = "/var/run/",
    vardb = "/var/db/",
    STDPATH = "/usr/bin:/bin:/usr/sbin:/sbin",
    devdb = "/var/run/dev.db",
    devnull = "/dev/null",
    klog = "/proc/kmsg",
    vi = "/bin/vi",
    preserve = "/var/lib",
    maildir = "/var/mail",
    shadow = "/etc/shadow",
    drum = "/dev/drum",
    tty = "/dev/tty",
    bshell = "/bin/sh",
    man = "/usr/share/man",
    DEFPATH = "/usr/bin:/bin",
    dev = "/dev/",
    wtmp = "/var/log/wtmp",
    unix = "/boot/vmlinux",
    utmp = "/var/run/utmp",
    kmem = "/dev/kmem",
    rwhodir = "/var/spool/rwho",
    tmp = "/tmp/",
    vartmp = "/var/tmp/",
    nologin = "/etc/nologin",
    mnttab = "/etc/fstab",
    cshell = "/bin/csh",
    shells = "/etc/shells",
  },
  NODENAME = "lucy.roswell.conman.org",
  VERSION = "#1 SMP Fri Feb 18 03:46:19 EST 2011",
  DOMAINNAME = "(none)",
  RELEASE = "2.6.9-100.EL.plus.c4smp",
  CPU = "x86",
  CORES = 2.000000,
}

	The POSIX and PATHS arrays were later additions.

[3]	Which isn't even in my file system module!

[4]	Notwithstanding [3].