Page MenuHomeFreeBSD

flua: Add some mode functions to the posix module
AcceptedPublic

Authored by markj on Thu, Sep 5, 10:41 PM.
Tags
None
Referenced Files
F96545175: D46553.diff
Wed, Sep 25, 10:44 AM
Unknown Object (File)
Tue, Sep 24, 1:21 AM
Unknown Object (File)
Mon, Sep 23, 6:41 PM
Unknown Object (File)
Sun, Sep 22, 12:28 AM
Unknown Object (File)
Fri, Sep 20, 9:02 PM
Unknown Object (File)
Thu, Sep 19, 4:54 AM
Unknown Object (File)
Wed, Sep 18, 6:42 AM
Unknown Object (File)
Mon, Sep 16, 11:50 PM
Subscribers
None

Details

Reviewers
kevans
imp
bapt
Summary

Specifically, add posix_spawn() and friends, and also pipe() and close()
wrappers. Note that posix_spawn() is not in luaposix.

The posix_spawn() interface tries to be flexible. All parameters except
the executable name/path and process arguments are optional. For
example, one can write:

posix_spawn("/bin/ls", {"ls", "-l"})

or

posix_spawnp("env", {"env"}, {"FOO=BAR"})

The file_actions interface is a bit more involved, but can be used to do
things like pipe output of one process to another, or collect standard
output in a string. We are missing a few things to make useful
examples, but it's relatively straightforward.

I would like to replace the "fbsd" module, which provides a much more
limited wrapper for posix_spawn(). In general, I prefer to wrap C
functions directly, and then provide helper functions written in Lua.
The posix_spawn() interface above is clunky, but with that it's easy to
add functions which exec a process and variously:

  • pipe output to another process
  • wait for the proc to exit and return output as a string
  • print the current stdin/stdout/stderr
  • ...

The other "interesting" thing is the use of a userdata type to represent
file descriptors. I provided pipe() and close() implementations to
demonstrate this. They are not too useful on their own, but they help
demonstrate how to

I don't really consider this to be committable yet, just a starting
point for some discussion. One consideration is how we should split up
the sources; cramming everything into one file doesn't seem to be
scalable. The obvious approach would be to have modules/posix/spawn.c,
modules/posix/unistd.c, etc..

One other consideration is how to handle userdata types like the one
used for file descriptors. Should this be part of the core flua
implementation? Ideally it could be used across different modules
(e.g., with a hypothetical freebsd.sys.capsicum.cap_rights_limit()), so
does not really belong in the posix module.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 59329
Build 56216: arc lint + arc unit

Event Timeline

markj requested review of this revision.Thu, Sep 5, 10:41 PM
markj created this revision.

I do like it, not that when this gets in the current fbsd.exec should be removed

Generally, I like this, though I didn't pedantically check the posix_spawn_impl stuff.

libexec/flua/modules/lposix.c
47

I'd be tempted to separate this out into the base flua and not have it be in the posix module (even if most of the things we'd use file descriptors for are in posix)
I really like you went to the effort to make this a user type so we can gc it automatically. There's a clash in styles: Lua wants to do things when references fall to zero (though not the exact instant) and POSIX wants paired calls (effective). By allowing both styles to work, we'll save ourselves a lot of hassle later.

60

I'd be tempted to have these in a common header for the freebsd wrappers that will follow.

619

Apart from namespace (commented separately), I think _np is fine. It mirrors our normal practice (the POSIX standard doesn't define _np) and it's trivial enough to add aliases should these be standardized in the identical way or separate functions if they are standardized in a slightly different, user-visible-to-lua way.

This revision is now accepted and ready to land.Fri, Sep 6, 2:39 PM