Skip to content

allow empty values in sysctl.conf

Kernel parameters can have empty values. For example, net.ipv4.ip_local_reserved_ports is empty by default.

387e2cf1 fixed this for individual parameters on the command line, e.g.:

$ sudo sysctl net.ipv4.ip_local_reserved_ports=
net.ipv4.ip_local_reserved_ports =

Setting empty values via config file, however, remained impossible.

$ echo net.ipv4.ip_local_reserved_ports= > sysctl.conf
$ sudo sysctl -p sysctl.conf
sysctl: sysctl.conf(1): invalid syntax, continuing...

This adjusts the parser to allow empty values.

Implementation note: the strtok() return value is, per my man page:

The strtok() and strtok_r() functions return a pointer to the next
token, or NULL if there are no more tokens.

If, however, any strtok() implementation happens to return a pointer to an empty string, that will be accepted and have the same effect.

Edited by Corey Hickey

Merge request reports