Description

The "language" in which udev rules are written as documented in udev(7) is horrible. To name just a few problems:

  • The only control statements are LABEL and GOTO.
  • Conditionals are the most important part of the language, but it supports only conjunction ("AND"), forcing developers to use GOTO even for simple "OR" relations.
  • The AND operation is denoted by a comma (,).
  • Conventions for quoting are weird.
  • There aren't even basic string handling facilities.
  • There is no API for passing flags between different rule sets, just a set of global environment variables.
  • Environment variales are written in ENV{FOO} when assigned to, but $env{FOO} or %E{FOO} when dereferenced.

While this is ok-ish for the simple set of tasks the language was originally intended for, it makes larger rule sets with complex logic almost impossible to read and understand. Examples for such complex rule sets are the device-mapper and multipath rules.

While working on the multipath rule sets a few weeks ago, I found myself desparately translating the rules into some pythonesque pseudo-code in order to make sure I fully understand the code flow.

This project wants to explore the possibilities to replace this weird DSL with something saner. The idea is to embed Lua in udev, and rewrite the udev rule sets as Lua modules.

It's meant as a fun project that may have practical merits. I am aware that it's questionable whether the systemd maintainers are going to embrace this. I think it will only have a tiny chance if it really improves readability of rules massively, while impacting neither performance nor code size too badly. I have good hopes in terms of performance as Lua has the reputation to be fast, but code size will of course increase, and so will the list of dependencies of systemd.

Goals

  1. Learn how to write Lua, and how to embed it in C code and write C modules for it. I've read the manual, but I can't say that I'm fluent with it yet.
  2. Design an API for udev in Lua. Figure out how to expose status like device properties (environment variables), tags, and other variables like ACTION and SUBSYSTEM to Lua code, and tentatively re-write a set of representative rule sets in this new DSL. This may need several attempts until the rules can be written in an intuitive way.
  3. Create the basic framework for embedding Lua in udev and providing the environment for the Lua code.
  4. Write libraries with helper funtions to be used by the Lua. For example, we'll need code to access sysfs in order to provide ATTRS and similar features of udev. I'm not certain yet but for most of this it will probably make sense to write the code in C and make it callable by Lua, as udev already has powerful mechanisms for accessing sysfs attributes.
  5. One problem is that the Lua standard library provides getenv but not setenv. We need to be able to set environment variables in order to work with external programs to replicate the functionality of the PROGRAM and IMPORT{program} directives.
  6. Eventually, make the entire feature set of the udev language available.
  7. Eventually, rewrite the entire set of upstream rules (to the extent we're aware of) in Lua.
  8. While I'd love trash the original language, I guess it needs to continue to exist.

Looking for hackers with the skills:

udev lua

This project is part of:

Hack Week 24

Activity

  • 22 days ago: michals liked this project.
  • 30 days ago: osalvador liked this project.
  • about 1 month ago: mwilck added keyword "udev" to this project.
  • about 1 month ago: mwilck added keyword "lua" to this project.
  • about 1 month ago: mwilck originated this project.

  • Comments

    Be the first to comment!

    Similar Projects

    This project is one of its kind!