Wednesday, January 31, 2024

What's New in util-linux v2.40?

The util-linux v2.40-rc1 was released just a few days ago. Let's explore the new features introduced in this release.

We have a new small shared library in the project, liblastlog, to implement a replacement for the lastlog file and lastlog-related utils. The main goal is to fix the Y2038 issue and use a more advanced file format to store the log. The original lastlog implementation uses 32-bit time values and a file format where an entry location is based on UID, so on systems with huge UIDs, it creates a huge lastlog file (fortunately, a file with holes). The new library uses the SQLite3 library to store data. It makes things easy to extend, efficient, and fast. There is also the pam_lastlog2 module as a replacement for the original pam_lastlog. Thanks to Suse, namely Stefan Schubert and Thorsten Kukuk.

The library libuuid has also been improved to support 64-bit time.

The next big change is within libsmartcols. The library now supports filtering expressions and counters. The idea and first implementation come from Masatake Yamato; it was originally designed for lsfd, but we found it very useful to make it generic and usable for arbitrary applications, so now all the functionality is exported by the public library API.

Applications can utilize the filter before gathering all data for output, reducing resource usage and improving performance. This is important for tools like lsblk where gathering data can be time-consuming in some cases (for example, read details from partition tables, filesystems superblocks, or fetch data from udevd). The expressions use lazy evaluation, so only necessary data comes to the game.

The filter expression uses C-like format with human-readable aliases ("&&" alias "and"), for example:

# lsfd -Q 'TIMERFD.remaining < 0.5 && TIMERFD.remaining > 0.0'

It supports basic operators, including regular expressions for strings:

# lsfd -Q 'COMMAND =~ ".*qemu.*" && FD >= 0'

The parser is generated by flex and bison.

The expression can contain data from fields (columns) which will not be printed.

An extension to the expression are counters. The counter uses an aggregation function to count lines or summarize numbers (supported functions are count, min, max, and sum).

The counter is possible to restrict by expression, for example:

# lsfd --summary=only \ -C 'netlink sockets':'(NAME =~ "NETLINK:.*")' \ -C 'unix sockets':'(NAME =~ "UNIX:.*")' VALUE COUNTER 57 netlink sockets 1552 unix sockets

In future releases, I'd like to add the possibility to colorize data in libsmartcols tables based on expressions and cell types. For now, a very basic possibility is available in lsblk by using the "--highlight <expr>" command line option.

You probably know that in Linux we have more system clocks, but do you know any elegant way to see all the clocks? ;-) Ladies and gentlemen, welcome lsclocks, a new util-linux command.

# lsclocks ID NAME TYPE TIME RESOL ISO_TIME 0 realtime sys 1706702926.075958226 1ns 2024-01-31T12:08:46.075958226+00:00 1 monotonic sys 332686.333569506 1ns 1970-01-04T20:24:46.333569506+00:00 4 monotonic-raw sys 332685.732374681 1ns 1970-01-04T20:24:45.732374681+00:00 5 realtime-coarse sys 1706702926.074719228 1ms 2024-01-31T12:08:46.074719228+00:00 6 monotonic-coarse sys 332686.332298188 1ms 1970-01-04T20:24:46.332298188+00:00 7 boottime sys 435547.110588884 1ns 1970-01-06T00:59:07.110588884+00:00 8 realtime-alarm sys 1706702926.075996923 1ns 2024-01-31T12:08:46.075996923+00:00 9 boottime-alarm sys 435547.110592620 1ns 1970-01-06T00:59:07.110592620+00:00 11 tai sys 1706702963.076000869 1ns 2024-01-31T12:09:23.076000869+00:00

It can also read time from RTC, time offsets from namespaces, and process CPU time. Like all ls-like tools in util-linux, it supports parsable outputs, including JSON. Thanks to Thomas Weißschuh.

If you use systemd credentials system, then agetty(8) and login(1) can follow this system. For now, it's supported for autologin. Thanks to Daan De Meyer.

dmesg(1) parses caller-id from kernel messages and prints it. Thanks to Edward Chron. It can also now print timestamps in multiple formats at the same time for each message (--time-format may be specified more than once). Thanks to Rishabh Thukral.

Sounds strange, but sometimes the goal is to break things :-) For this purpose, we have introduced a new command "enosys". It can call an arbitrary program with disabled syscall. The same functionality provides, for example, strace, but it seems useful to have a tiny dedicated tool for this purpose. For example:

# enosys --syscall ioprio_get ionice ionice: ioprio_get failed: Function not implemented

Thanks to Thomas Weißschuh.

Atomicity matters in many cases. The new small command "exch" can atomically exchange paths between two files. Thanks to Masatake Yamato.

Again, your upstream CI tests have been improved. Every pull request has to pass 32 checks, including a static analyzer, fuzzing, build tests on multiple architectures (including riscv64, s390), and multiple distros (Ubuntu, Fedora). It undergoes building by GCC (versions 13 and 14) and Clang compilers, along with more than 300 regression tests and countless subtests.

And many, many other changes – the Release Notes file has approximately 1160 lines. Thanks to all contributors!

 

 

No comments:

Post a Comment