File: netlink-uevent.lua

package info (click to toggle)
lua-posix 36.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,720 kB
  • sloc: ansic: 5,462; makefile: 21; sh: 6
file content (23 lines) | stat: -rw-r--r-- 540 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#! /usr/bin/env lua

local M = require 'posix.sys.socket'


if M.AF_NETLINK ~= nil then
   local getpid = require 'posix.unistd'.getpid

   local fd, err = M.socket(M.AF_NETLINK, M.SOCK_DGRAM, M.NETLINK_KOBJECT_UEVENT)
   assert(fd, err)

   local ok, err = M.bind(fd, {family=M.AF_NETLINK, pid=getpid(), groups=-1})
   assert(ok, err)

   while true do
      local data, err = M.recv(fd, 16384)
      assert(data, err)
      for k, v in string.gmatch(data, '%z(%u+)=([^%z]+)') do
         print(k, v)
      end
      print '\n'
   end
end