Compare commits

...

9 Commits

9 changed files with 48 additions and 25 deletions

View File

@ -4722,11 +4722,15 @@ I think we could make the event loop abstraction leak less?
It's not actually a _loop_, all the actual GOTO 10 happens
outside of it
1) see if we can do netlink in lualinux
2) if so, convert it to lualinux
3) add netlink socket to event loop
4) make it send messages to subscribers
[X] 1) see if we can do netlink in lualinux
[X] 2) if so, convert it to lualinux
[X] 3) add netlink socket to event loop
[X] 4) make it send messages to subscribers
5) package it
6) make inout test use it instead of uevent-watcher
6) make uevent-watcher use it instead of netlink directly
7) write an inout test variant that has the stick inserted
at boot time already
I'm also thinking we could wrap the raw fds from lualinux into small
objects with read and close methods? It would make testing easier if
nothing else - also use of with-open. Maybe do that in anoia.

View File

@ -2,6 +2,7 @@
fennel
, stdenv
, lua
, lualinux
}:
let pname = "anoia";
in stdenv.mkDerivation {
@ -9,7 +10,7 @@ in stdenv.mkDerivation {
version = "0.1";
src = ./.;
nativeBuildInputs = [ fennel ];
buildInputs = with lua.pkgs; [ luafilesystem ];
buildInputs = with lua.pkgs; [ luafilesystem lualinux ];
outputs = [ "out" "dev" ];
doCheck = true;

View File

@ -1,7 +1,19 @@
(local lfs (require :lfs))
(local ll (require :lualinux))
(local S_IFMT 0xf000)
(local S_IFSOCK 0xc000)
(local S_IFLNK 0xa000)
(local S_IFREG 0x8000)
(local S_IFBLK 0x6000)
(local S_IFDIR 0x4000)
(local S_IFCHR 0x2000)
(local S_IFIFO 0x1000)
(fn ifmt-bits [mode] (and mode (band mode 0xf000)))
(fn directory? [pathname]
(= (lfs.symlinkattributes pathname :mode) "directory"))
(let [(mode size mtime) (ll.lstat3 pathname)]
(= (ifmt-bits mode) S_IFDIR)))
(fn mktree [pathname]
(if (or (= pathname "") (= pathname "/"))
@ -10,28 +22,28 @@
(or (directory? pathname)
(let [parent (string.gsub pathname "/[^/]+/?$" "")]
(or (directory? parent) (mktree parent))
(assert (lfs.mkdir pathname)))))
(assert (ll.mkdir pathname)))))
(fn rmtree [pathname]
(case (lfs.symlinkattributes pathname)
(case (ifmt-bits (ll.lstat3 pathname))
nil true
{:mode "directory"}
S_IFDIR
(do
(each [f (lfs.dir pathname)]
(when (not (or (= f ".") (= f "..")))
(rmtree ( .. pathname "/" f)))
(lfs.rmdir pathname)))
{:mode "file"}
S_IFREG
(os.remove pathname)
{:mode "link"}
S_IFLNK
(os.remove pathname)
unknown
(error (.. "can't remove " pathname " of kind \"" unknown.mode "\""))))
(error (.. "can't remove " pathname " of mode \"" unknown "\""))))
{
: mktree
: rmtree
: directory?
:symlink (fn [from to] (lfs.link from to true))
:symlink (fn [from to] (ll.symlink from to))
}

View File

@ -82,11 +82,11 @@
(collect [_ v (ipairs pollfds)]
(let [fd (band (rshift v 32) 0xffffffff)
revent (band v 0xffff)]
(values fd revent))))
(values fd (if (> revent 0) revent nil)))))
(fn parse-terms [str]
(print :terms str)
(collect [n (string.gmatch str "([^ ]+)")]
(collect [n (string.gmatch (str:gsub "\n+$" "") "([^ ]+)")]
(string.match n "(.-)=(.+)")))
(fn handle-client [db client]
@ -138,7 +138,7 @@
true)))
(loop:register
nl
#(do (print :netlink (ll.read nl)) true))
#(do (db:add (ll.read nl)) true))
(while true
(let [pollfds (pollfds-for (loop:fds))]
(ll.poll pollfds 5000)

View File

@ -1,6 +1,6 @@
(local { : database : event-loop } (require :devout))
(local { : view } (require :fennel))
(local sock (require :minisock))
(local ll (require :lualinux))
(import-macros { : expect : expect= } :anoia.assert)
(var failed false)
@ -166,9 +166,7 @@ MINOR=17")
))
(fn new-fd []
(let [fd (sock.bind (.. "\1\0" "/tmp/test-socket" "\0\0\0\0\0"))]
(os.remove "/tmp/test-socket")
fd))
(ll.open "/dev/zero" 0 0x1ff))
(example
"when the callback returns false it is unregistered and the fd is closed"

View File

@ -5,6 +5,7 @@
, lib
, luaPackages
, lua
, lualinux
, writeScriptBin
, linotify
, anoia
@ -15,7 +16,9 @@ let packages = [
linotify
anoia
fennel
lualinux
netlink-lua
lua.pkgs.readline
lua.pkgs.luafilesystem
];
join = ps: builtins.concatStringsSep ";" ps;

View File

@ -12,7 +12,10 @@ in lua.pkgs.buildLuaPackage {
version = "0.1"; # :shrug:
inherit src;
makeFlags = [ "LUADIR=." "lualinux.so" ];
postPatch = ''
sed -i -e '/strip/d' Makefile
'';
makeFlags = [ "LUADIR=." "CC:=$(CC)" "STRIP=true" "lualinux.so" ];
installPhase = ''
mkdir -p "$out/lib/lua/${lua.luaversion}"

View File

@ -2,5 +2,6 @@
writeFennelScript
, anoia
, lua
, lualinux
}:
writeFennelScript "odhcpc-script" [anoia lua.pkgs.luafilesystem] ./odhcp6-script.fnl
writeFennelScript "odhcpc-script" [anoia lualinux] ./odhcp6-script.fnl

View File

@ -1,6 +1,7 @@
{
lua
, nellie
, lualinux
, writeFennel
, runCommand
, anoia
@ -15,7 +16,7 @@ stdenv.mkDerivation {
installPhase = ''
mkdir -p $out/bin
cp -p ${writeFennel "uevent-watch" {
packages = [fennel anoia nellie lua.pkgs.luafilesystem];
packages = [fennel anoia nellie lualinux];
mainFunction = "run";
} ./watch.fnl} $out/bin/uevent-watch
'';