Skip to content

add preservation of comment lines - #20

Closed
wififreedom wants to merge 1 commit into
openwrt:masterfrom
wififreedom:preserve_comments
Closed

add preservation of comment lines#20
wififreedom wants to merge 1 commit into
openwrt:masterfrom
wififreedom:preserve_comments

Conversation

@wififreedom

@wififreedom wififreedom commented Mar 31, 2026

Copy link
Copy Markdown

This pull request implements preservation of comments in configuration files.

Comment lines before an entry, and the comment at the end of an entry are considered to be associated with that entry.

Example:

# this comment line is associated with section2

  # this comment line is associated with section2
config type section2 # this comment is associated with section 2
# this comment line is associated with opt
    
        # this comment line is associated with opt
        option opt 'val' # this comment is associated with opt
    
      # this comment line is not associated with any entry

Wih option -D, uci works as before and strips comments. The following commands have enhanced behaviour:

  • uci import preserves comments of unchanged configuration entries, and imports entries with their associated comments
  • uci export exports entries with their associated comments
  • uci 'commit preserves comments of unchanged configuration entries when committing changes with uci commands 'add', 'delete', 'set', 'add_list', and/or 'del_list'.
  • uci get '<config>.<section>' '#' shows the section comment
  • uci get '<config>.<section>.<option> '#' shows the option comment
  • uci set '<config>.<section>=<value>' '<comment>' sets the section value and comment
  • uci set '<config>.<section>.option=<value>' '<comment>' sets the option value and comment
  • uci add_list '<config>.<section>.option=<value> '<comment>' adds a list entry with value and comment
  • uci changes also shows comments
  • uci show does not show comments
  • uci batch supports the above commands

Features:

  • Comments are auto-indented if preserved, set or added.
  • The new delta file format is both backward compatible and forward compatible. Older uci versions interpret the addition in the new format as comment and ignores it.
  • Comments at the end of the file are not preserved because they do not belong to an entry.

I've added lots of shunit2 tests to verify the implementation.

An example of a result: the above example after and option 'opt2' has been added:


# this comment line is associated with section2
# this comment line is associated with section2
config type section2 # this comment is associated with section 2
        # this comment line is associated with opt
        # this comment line is associated with opt
        option opt 'val' # this comment is associated with opt
        # comment line for new option 'opt2'
        option opt2 'val2'

Comment thread file.c Outdated
@GeorgeSapkin

Copy link
Copy Markdown
Member

You'll need to look into the submission guidelines regarding commit formatting, etc.

@wififreedom
wififreedom marked this pull request as ready for review April 2, 2026 14:16
@wififreedom
wififreedom force-pushed the preserve_comments branch 3 times, most recently from 92f0747 to bf0a598 Compare April 3, 2026 11:21
@wififreedom
wififreedom marked this pull request as draft April 4, 2026 09:06
@wififreedom
wififreedom force-pushed the preserve_comments branch 7 times, most recently from 56181fc to 0cb0626 Compare April 6, 2026 22:06
@wififreedom
wififreedom marked this pull request as ready for review April 6, 2026 22:33
@wififreedom
wififreedom force-pushed the preserve_comments branch 2 times, most recently from f1c8b3c to db733c0 Compare April 11, 2026 05:19
This pull request implements preservation of comments in configuration
files.

Comment lines before an entry, and the comment at the end of an entry
are considered to be associated with that entry.

Example:

  # this comment line is associated with section

    # this comment line is associated with section
  config type 'section' # this comment is associated with section
  # this comment line is associated with opt

          # this comment line is associated with opt
          option opt 'val' # this comment is associated with opt

        # this comment line is not associated with any entry

Wih option -D, uci works as before and strips comments.

The following commands have enhanced behaviour:
  * uci import
    preserves comments of unchanged configuration entries, and imports
    entries with their associated comments
  * uci export
    exports entries with their associated comments
  * uci commit
    preserves comments of unchanged configuration entries when
    committing changes with uci commands 'add', 'delete', 'set',
    'add_list', and/or 'del_list'.
  * uci get '<config>.<section>' '#'
    shows the section comment
  * uci get '<config>.<section>.<option> '#'
    shows the option comment
  * uci set '<config>.<section>=<value>' '<comment>'
    sets the section value and comment
  * uci set '<config>.<section>.option=<value>' '<comment>'
    sets the option value and comment
  * uci add_list '<config>.<section>.option=<value> '<comment>'
    adds a list entry with value and comment
  * uci changes
    also shows comments
  * uci show
    does not show comments
  * uci batch
    supports the above commands

Features:
  * Comments are auto-indented if preserved, set or added.
  * The new delta file format is both backward compatible and forward
    compatible. Older uci versions interpret the addition in the new
    format as comment and ignore it.
  * Comments at the end of the file are not preserved because they do
    not belong to an entry.

An example of a result: the above example after and option 'opt2' has
been added with a comment:

  # this comment line is associated with section2
  # this comment line is associated with section2
  config type section2 # this comment is associated with section 2
          # this comment line is associated with opt
          # this comment line is associated with opt
          option opt 'val' # this comment is associated with opt
          # comment line for new option 'opt2'
          option opt2 'val2'

Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
@bluewavenet

Copy link
Copy Markdown

@wififreedom

Before reviewing any code, I have a few fundamentals to be discussed.

Comment lines before an entry, and the comment at the end of an entry are considered to be associated with that entry.

How are such comments linked to an entry? I am not aware of any association mechanism.

What happens to comments after an option or list is deleted? - I guess they will become orphaned.
What happens to these orphaned comments if an option or list is reinstated? - The option or list will be recreated at the end of the section, the comments will be - somewhere...

Wi[t]h option -D, uci works as before and strips comments

Currently, uci does not strip comments, it ignores them - in other words, it does not read them.
Currently uci commit rewrites /etc/config/ with any changes but minus the comments it ignored.
Currently uci works entirely in memory/tmpfs storage, only re-writing the config file on receiving a commit request.

Does this PR make a fundamental change to how uci works?
If so does it / how does it maintain 100% compatibility?

Many complex packages can have hundreds of potential options and lists. It is very common for a large and mostly commented out config file to be installed, with most and sometimes all options/lists described in some detail as a form of documentation.
The "proper" mechanism for enabling options/lists is to use the uci set or uci add_list command.
Once the required configuration is completed, a commit is issued.
This very often is done at first boot by the uci-defaults script file for the package.
What consideration for this has been made in this PR?

Without some detailed information, IMHO, the proposed changes to uci in this PR will, for a complex package, result in at best, a messy set of unlinked comments, or at worst, a config file that current packages might consider invalid.

@wififreedom

Copy link
Copy Markdown
Author

@bluewavenet

@wififreedom

Before reviewing any code, I have a few fundamentals to be discussed.

Comment lines before an entry, and the comment at the end of an entry are considered to be associated with that entry.

How are such comments linked to an entry? I am not aware of any association mechanism.

In the config file, the comments are by convention linked to an entry by their position. In memory, uci stores the comments in the uci_element.comment struct member (in uci.h), unless -D has been specified, in which case the behavior is as original uci and no comments are stored in memory while reading a config file.

What happens to comments after an option or list is deleted?

They are deleted together with the option or list (with the uci_element or uci_elements).

  • I guess they will become orphaned. What happens to these orphaned comments if an option or list is reinstated? - The option or list will be recreated at the end of the section, the comments will be - somewhere...

This does not apply, the comments associated with an entry form a whole and are deleted together.

Wi[t]h option -D, uci works as before and strips comments

Currently, uci does not strip comments, it ignores them - in other words, it does not read them. Currently uci commit rewrites /etc/config/ with any changes but minus the comments it ignored. Currently uci works entirely in memory/tmpfs storage, only re-writing the config file on receiving a commit request.

uci strips comments if you commit one or more changes. I believe sometimes, a commit is not required (e.g. if I remember correctly, merge commands in some situations apply changes directly, someone opened an issue about this a while ago, but that's something not relevant to this pull request).

Does this PR make a fundamental change to how uci works? If so does it / how does it maintain 100% compatibility?

No fundamental change.

In the delta file, original uci does not store a '#', but does ignore a '#' and everything after it when reading a delta line.

The new code stores comments in the delta file at the end of the line after a '#', and processes them when reading and committing. E.g. at the end of a 'set' delta, or of an 'add_list' delta. So this is both forward and backward compatible.

Basically, the only change is that uci no longer ignores everything at the end of an entry after a '#' character, in config files, delta files, and on the command line.

Many complex packages can have hundreds of potential options and lists. It is very common for a large and mostly commented out config file to be installed, with most and sometimes all options/lists described in some detail as a form of documentation. The "proper" mechanism for enabling options/lists is to use the uci set or uci add_list command. Once the required configuration is completed, a commit is issued. This very often is done at first boot by the uci-defaults script file for the package. What consideration for this has been made in this PR?

The comments are stored in the delta file with the deltas for the set and add_list commands, and applied together with the rest of the delta.

Without some detailed information, IMHO, the proposed changes to uci in this PR will, for a complex package, result in at best, a messy set of unlinked comments, or at worst, a config file that current packages might consider invalid.

No unlinked comments, no mess, no invalid config file. Entries are deleted with their comment. A change to an entry deletes both the old entry and all associated comment. No mess remains. No invalid config file can result.

@wififreedom

wififreedom commented Jul 6, 2026

Copy link
Copy Markdown
Author

@bluewavenet

Example delta file with comments: tests/shunit2/references/changes_keep_comments.result‎

Original uci for each line just ignores the first '#' and everything after it.

@bluewavenet

Copy link
Copy Markdown

@wififreedom

Example delta file with comments

I would have to invest a significant time to try to figure out what it is that link is supposed to be and then interpreting it in real terms!

You say you have a working version of the new code, so:
Could you provide clarity by testing on an actual package installed default? ie
https://github.com/openNDS/mesh11sd/blob/master/linux_openwrt/mesh11sd/files/etc/config/mesh11sd

Tests:

  1. compare cat /etc/config/mesh11sd with uci export mesh11sd
  2. give the output of uci show mesh11sd
  3. Run uci set mesh11sd.setup.cpe_mode='prefix_delegation'
  4. repeat tests 1 and 2
  5. Run uci commit mesh11sd
  6. repeat tests 1 and 2

Depending on these results I could suggest more simple tests.
But if the results are positive, you will be well on the way to mitigating my scepticism!

I don't expect you to install the full package, but note for information, when the package () service daemon is running. expected outputs should be similar to:

root@meshnode-8ec9:~# uci show mesh11sd
mesh11sd.setup=mesh11sd
mesh11sd.setup.auto_config='1'
mesh11sd.mesh_params=mesh11sd
mesh11sd.mesh_params.mesh_fwding='1'
mesh11sd.mesh_params.mesh_retry_timeout='255'
mesh11sd.mesh_params.mesh_confirm_timeout='255'
mesh11sd.mesh_params.mesh_holding_timeout='255'
mesh11sd.mesh_params.mesh_rssi_threshold='-68'
mesh11sd.mesh_params.mesh_gate_announcements='1'
mesh11sd.mesh_params.mesh_hwmp_rootmode='4'
mesh11sd.mesh_params.mesh_hwmp_root_interval='5000'
mesh11sd.mesh_params.mesh_hwmp_active_path_to_root_timeout='6000'
mesh11sd.mesh_params.mesh_max_peer_links='16'
mesh11sd.mesh_params.mesh_plink_timeout='500'
mesh11sd.mesh_params.mesh_hwmp_rann_interval='1953'
mesh11sd.mesh_params.mesh_hwmp_preq_min_interval='586'
mesh11sd.mesh_params.mesh_hwmp_active_path_timeout='1465'
mesh11sd.mesh_params.mesh_hwmp_max_preq_retries='4'
mesh11sd.mesh_params.mesh_connected_to_as='1'
mesh11sd.mesh_params.mesh_connected_to_gate='1'
root@meshnode-8ec9:~# 
root@meshnode-8ec9:~# uci export mesh11sd
package mesh11sd

config mesh11sd 'setup'
	option auto_config '1'

config mesh11sd 'mesh_params'
	option mesh_fwding '1'
	option mesh_retry_timeout '255'
	option mesh_confirm_timeout '255'
	option mesh_holding_timeout '255'
	option mesh_rssi_threshold '-68'
	option mesh_gate_announcements '1'
	option mesh_hwmp_rootmode '4'
	option mesh_hwmp_root_interval '5000'
	option mesh_hwmp_active_path_to_root_timeout '6000'
	option mesh_max_peer_links '16'
	option mesh_plink_timeout '500'
	option mesh_hwmp_rann_interval '1953'
	option mesh_hwmp_preq_min_interval '586'
	option mesh_hwmp_active_path_timeout '1465'
	option mesh_hwmp_max_preq_retries '4'
	option mesh_connected_to_as '1'
	option mesh_connected_to_gate '1'

root@meshnode-8ec9:~# uci changes mesh11sd
mesh11sd.mesh_params.mesh_fwding='1'
mesh11sd.mesh_params.mesh_retry_timeout='255'
mesh11sd.mesh_params.mesh_confirm_timeout='255'
mesh11sd.mesh_params.mesh_holding_timeout='255'
mesh11sd.mesh_params.mesh_rssi_threshold='-63'
mesh11sd.mesh_params.mesh_gate_announcements='1'
mesh11sd.mesh_params.mesh_hwmp_rootmode='0'
mesh11sd.mesh_params.mesh_hwmp_root_interval='5000'
mesh11sd.mesh_params.mesh_hwmp_active_path_to_root_timeout='6000'
mesh11sd.mesh_params.mesh_max_peer_links='16'
mesh11sd.mesh_params.mesh_plink_timeout='500'
mesh11sd.mesh_params.mesh_hwmp_rann_interval='1953'
mesh11sd.mesh_params.mesh_hwmp_preq_min_interval='586'
mesh11sd.mesh_params.mesh_hwmp_active_path_timeout='1465'
mesh11sd.mesh_params.mesh_hwmp_max_preq_retries='4'
mesh11sd.mesh_params.mesh_hwmp_rootmode='3'
mesh11sd.mesh_params.mesh_rssi_threshold='-68'
mesh11sd.mesh_params.mesh_connected_to_as='1'
mesh11sd.mesh_params.mesh_connected_to_gate='1'
mesh11sd.mesh_params.mesh_hwmp_rootmode='4'
root@meshnode-8ec9:~# 

For completeness, currently, after startup, or after reflash with the package built in, the actual config file is as follows:

root@meshnode-8ec9:~# cat /etc/config/mesh11sd

config mesh11sd 'setup'
	option auto_config '1'

config mesh11sd 'mesh_params'

root@meshnode-8ec9:~# 


Note also: The package installs a copy of the "super-#commented" original elsewhere for user reference.

@TheRootED24

TheRootED24 commented Jul 7, 2026

Copy link
Copy Markdown

I still find the whole idea absolutely preposterous!! but if by some miracle it manages to sneak by, the following is a hard NO!!

Wih option -D, uci works as before and strips comments

Default should be the original default!! no flags, you have got this backwards, -C (may be taken) or similar for comment would be appropriate as it is the new feature.

It would take me a over a week to update all my existing uci code and modules to specify an option that previously didn't exist.

@bluewavenet

Copy link
Copy Markdown

@TheRootED24

got this backwards

Indeed, I would most definitely agree, but reversing it will mean the precious comments would disappear anyway.
I was trying to encourage some real world testing, but I have a feeling that won't happen.

It is a firm no from me too unless I can be 100% demonstrated that there is no impact elsewhere.

It looks to me that this has been developed from the point of view of "manual edits to add comments keep disappearing", in the bubble of experience where the config files are always edited directly, something unfortunately often seen being propagated on the Forum.

@wififreedom

Copy link
Copy Markdown
Author

@bluewavenet

Tests:

1. compare `cat /etc/config/mesh11sd` with `uci export mesh11sd`

The export has leading whitespace removed from each line, and blank lines removed, so I used diff -w -B

root@OpenWrt:~# diff -w -B /etc/config/mesh11sd mesh11sd.export 
0a1
> package mesh11sd
708,718d654
<       # A minimum set of parameters is automatically set for initial startup and do not have to be configured here
<       #
<       # Any mesh parameter supported by the wireless driver can be specified here
<       # and will be dynamically set and continuously checked every "checkinterval"
<       # 
<       # Examples:
<       #option mesh_rssi_threshold '-70'
<       #option mesh_max_peer_links '20'
< 
<       #
<       # The command: "mesh11sd status" gives a full list of supported parameters.
2. give the output of `uci show mesh11sd`
root@OpenWrt:~# uci show mesh11sd
mesh11sd.setup=mesh11sd
mesh11sd.mesh_params=mesh11sd
3. Run `uci set mesh11sd.setup.cpe_mode='prefix_delegation'`
root@OpenWrt:~# uci set mesh11sd.setup.cpe_mode='prefix_delegation'
4. repeat tests 1 and 2
root@OpenWrt:~# uci export mesh11sd >mesh11sd.export
root@OpenWrt:~# diff -w -B /etc/config/mesh11sd mesh11sd.export 
0a1
> package mesh11sd
2a4,5
>       option cpe_mode 'prefix_delegation'
> 
708,718d655
<       # A minimum set of parameters is automatically set for initial startup and do not have to be configured here
<       #
<       # Any mesh parameter supported by the wireless driver can be specified here
<       # and will be dynamically set and continuously checked every "checkinterval"
<       # 
<       # Examples:
<       #option mesh_rssi_threshold '-70'
<       #option mesh_max_peer_links '20'
< 
<       #
<       # The command: "mesh11sd status" gives a full list of supported parameters.
root@OpenWrt:~# uci show mesh11sd
mesh11sd.setup=mesh11sd
mesh11sd.setup.cpe_mode='prefix_delegation'
mesh11sd.mesh_params=mesh11sd
5. Run `uci commit mesh11sd`
root@OpenWrt:~# uci commit mesh11sd
6. repeat tests 1 and 2
root@OpenWrt:~# uci export mesh11sd >mesh11sd.export
root@OpenWrt:~# diff -w -B /etc/config/mesh11sd mesh11sd.export 
0a1
> package mesh11sd
root@OpenWrt:~# uci show mesh11sd
mesh11sd.setup=mesh11sd
mesh11sd.setup.cpe_mode='prefix_delegation'
mesh11sd.mesh_params=mesh11sd

@wififreedom

Copy link
Copy Markdown
Author

@bluewavenet

We can certainly discuss default options.

One of the challenges is to have all applications honor the setting. If only one application that uses libuci to make changes to the config files removes the comments, they are gone. So it has to be the default uci behavior, or a global setting for the entire system that libuci can honor.

For now, I have chosen the default is to keep comments. For example, I considered having a hidden file like /etc/config/.ucikeepcomment instead. There are many other possibilities that crossed my mind.

Let's discuss the feature itself first.

@TheRootED24

Copy link
Copy Markdown

I don't see why it needs to be a new feature of uci. I have dozens of features like this for ubus. Things I prefer and or find extremely handy. But I couldn't imagine proposing to have any of them actually added to ubus. Instead, I simply create a patch and put it in the patches dir in ubus root. If i want to share, i create a fork so others can pull in the patches and test. Sure, i have to maintain it, but that's just part of SD IMO.

To me it seems the approach here is to just get it in there so the maintainer will maintain it, with no thought as to how it would affect the 1000's of users that already have uci deployed in projects. The -D is just proof of that. Sure it just becomes default behavior and luci and the like need no modification to accept it ... but this imposes on everyone. So i either just accept it, or go through 1000's of lines of code to add the -D flag to override it !!

in what world does that make any sense...

@wififreedom

Copy link
Copy Markdown
Author

@TheRootED24
This is a sincere question: Can you explain to me why you would want no comments in the config files, what's the harm keeping comments does? Everything functionally works as before. I would like to understand your use case.

@TheRootED24

Copy link
Copy Markdown

I have no issue with comments in my configs. The problem is, I have been using uci since its inception. I have it deployed on all sorts on tiny embedded devices, many of which have little to no bytes to spare. This could potentially cause all sorts of headaches for me and many others moving forward. UCI is a very mature library, any changes what so ever will be far reaching ...far beyond just comments in a config file

@TheRootED24

TheRootED24 commented Jul 7, 2026

Copy link
Copy Markdown

have you considered an external library ?? I have not looked too closely at all the code but from what i did examine, this could be done as an external lib with uci as a dependency ..

I guess this would require far more accommodation so again it come back to the question ... is this something that will benefit the many ...or just a few

@wififreedom

Copy link
Copy Markdown
Author

@TheRootED24

have you considered an external library ?? I have not looked too closely at all the code but from what i did examine, this could be done as an external lib with uci as a dependency ..

What do you mean exactly, libuci.so already exists?

I guess this would require far more accommodation so again it come back to the question ... is this something that will benefit the many ...or just a few

uci is nice for automation, but not for other use cases such as troubleshooting. For example, everyone at the forum asks to cat the config file, not to do 'uci show'.

Also, I don't want to have to remember what each option in a config file does and what the possible values are and why I set it to the current value to solve which problem. So I like very much to add a comment and keep that comment. I'm not alone, I'm sure. If I'm the many or the few I can't claim.

I don't know how common devices with only bytes to spare are, although with the current AI situation making memory very expensive they may become more popular again. Packages become larger all the time, including the kernel. At some point you may need to upgrade your device anyway, for reasons having nothing to do with the few bytes extra used by uci keeping comments. I will strive to accommodate this use case anyway.

We can of course have something other than option "-D".

@TheRootED24

TheRootED24 commented Jul 7, 2026

Copy link
Copy Markdown

everyone at the forum asks to cat the config file, not to do 'uci show'.

cat /etc/config/conf vs uci show conf

doesn't warrant disruption of current deployment, and most users know that uci export conf produces the same results as a cat ..

Packages become larger all the time, including the kernel. At some point you may need to upgrade your device anyway

your proving my point here, name 1 packages that has increase size to retain comments ?? or a kernel feature that hasn't been carefully scrutinized with the WHY question.

What is your use case, do you have fleets deployed as many openwrt users/devs do ? or a few devices ?

something tells me the later, which is likely why you failed to properly consider cost/benefit of such a novelty feature. You can document configs with a pen and paper when it comes down to it, the same cannot be said for memory. In most embedded devices, memory is always the first consideration.

I do not argue that it this is a useful feature, the problem is this feature does nothing to enhance the overall functionality of a mature embedded library. It does not add security, does not fix a bug, and cost precious memory, which leaves you standing on its handy for you.

As i have said before, there is many other ways this can be implemented without affecting a single users anywhere. You can also use it as you wish. But until you've proven its usefulness or make your case as to why it must be done by altering uci (potentially affecting many users) i see it as a none starter. Which is likely why no one will look at it.

To be clear, I think you've done a wonderful job, I know the uci codebase very well and i see no issues with the actual implementation. Just can't get past the WHY

With that said, I have stated my case. I do not wish to impede on the conversation any further. I will live with the maintainers decision.

kind regards.

@bluewavenet

Copy link
Copy Markdown

@wififreedom

root@OpenWrt:~# uci show mesh11sd
mesh11sd.setup=mesh11sd
mesh11sd.mesh_params=mesh11sd

No -D, yet the carefully crafted comments have all gone.
This shows it does not retain comments in general, only in special cases - so not all that useful after all.

As I indicated on the forum, a reliable way to include comments is to embed them as list entries.
I do this all the time.
No changes in uci needed and fully compatible with everything.

From the forum:

As an example, I quickly added some comments to my test router:

root@meshnode-8ec9:~# uci add_list system.ntp.comment='enable_server does what it says. You can use the enabled server from your computer to get the time'
root@meshnode-8ec9:~# uci add_list system.ntp.comment='server 0 sometimes gets quite busy'
uci commit system
root@meshnode-8ec9:~# uci export system
package system

config system
	option hostname 'meshnode-8ec9'
	option timezone 'GMT0'
	option zonename 'UTC'
	option ttylogin '0'
	option log_size '128'
	option urandom_seed '0'

config timeserver 'ntp'
	option enabled '1'
	option enable_server '0'
	list server '0.openwrt.pool.ntp.org'
	list server '1.openwrt.pool.ntp.org'
	list server '2.openwrt.pool.ntp.org'
	list server '3.openwrt.pool.ntp.org'
	list comment 'enable_server does what it says. You can use the enabled server from your computer to get the time'
	list comment 'server 0 sometimes gets quite busy'

@wififreedom

Copy link
Copy Markdown
Author

@bluewavenet

@wififreedom

root@OpenWrt:~# uci show mesh11sd
mesh11sd.setup=mesh11sd
mesh11sd.mesh_params=mesh11sd

No -D, yet the carefully crafted comments have all gone. This shows it does not retain comments in general, only in special cases - so not all that useful after all.

No they have not gone, the diff command shows that there is no difference, so the comments are still there!

uci show just does not show comments, for backward compatibility reasons. I can make uci show show the comments, but I don't know if that would be a problem for parsers that do not expect comments.

@TheRootED24

TheRootED24 commented Jul 7, 2026

Copy link
Copy Markdown

root@meshnode-8ec9:# uci add_list system.ntp.comment='enable_server does what it says. You can use the enabled server from your computer to get the time'
root@meshnode-8ec9:
# uci add_list system.ntp.comment='server 0 sometimes gets quite busy'
uci commit system
root@meshnode-8ec9:~# uci export system
package system

config system
option hostname 'meshnode-8ec9'
option timezone 'GMT0'
option zonename 'UTC'
option ttylogin '0'
option log_size '128'
option urandom_seed '0'

config timeserver 'ntp'
option enabled '1'
option enable_server '0'
list server '0.openwrt.pool.ntp.org'
list server '1.openwrt.pool.ntp.org'
list server '2.openwrt.pool.ntp.org'
list server '3.openwrt.pool.ntp.org'
list comment 'enable_server does what it says. You can use the enabled server from your computer to get the time'
list comment 'server 0 sometimes gets quite busy'

i missed this in the forum, Now that is a pretty slick and elegant solution implemented with nothing but good thinking .

You can even be option specific .. list <enable_server_info> .. list <enable_server_note_special_case> and this works great with uci-defaults as well.

case closed

@wififreedom

Copy link
Copy Markdown
Author

The list comment workaround does not place the comment where it needs to be, which is with the option it is about. So it is hard to read. You get a jumbled sequence of comments about multiple options somewhere else.

@TheRootED24

Copy link
Copy Markdown

yes but you can query the comment directly which is more typical usage

@wififreedom

Copy link
Copy Markdown
Author

There is no structure. You can add list comment entries and can query them, but you have no clue which option they are about.

@TheRootED24

Copy link
Copy Markdown

i think accurate naming solves this directly ...no ?

@bluewavenet

Copy link
Copy Markdown

Even with generic naming it is often good enough:

root@meshnode-8ec9:~# uci get system.ntp.comment
'enable_server does what it says. You can use the enabled server from your computer to get the time' 'server 0 sometimes gets quite busy'
root@meshnode-8ec9:~# 


@wififreedom

Copy link
Copy Markdown
Author

It's fine if someone wants to use a list comment workaround.

I don't want the system to delete the syntactically valid comments I add to the config files. I'm sure I'm not the only one to expect that from the system.

By the way, do you also delete all comments from the *.sh source code in /lib to save space?

@TheRootED24

Copy link
Copy Markdown

By the way, do you also delete all comments from the *.sh source code in /lib to save space?

Are you under the impression uci must be used within openwrt ? i use it on actual embedded devices for config and hot reloads, in many devices i don't have room for the scripts ... let alone the comments ;)

@wififreedom

Copy link
Copy Markdown
Author

If size really matters, it would even be possible to have uci-full and libuci-full packages next to uci and libuci packages, just like with packages ip and ip-full.

A few #ifdef statements would do the trick.

Of course that comes with its own advantages and disadvantages.

@TheRootED24

Copy link
Copy Markdown

well shoot!! now thats a mod i could get behind

@wififreedom

Copy link
Copy Markdown
Author

I'm tempted to implement the uci-full and libuci-full package solution, but at the same time wonder if the maintainers would frown at the idea of having to maintain that and all the #ifdef statements.

So, what to do?

@bluewavenet

Copy link
Copy Markdown

@wififreedom
The fundamental problem is that # comments have no connection with any uci functionality, in particular, they are not linked in any way to sections, options or lists. There is no mechanism to link either. Depending on a comment line being next to an option line for example only covers a very specific case.

So, what to do?

I would say a completely independent new package, that reads in the static /etc/config files and builds a config specific "documentation file" every time it is run, allowing people to add their own comments locked in to each option etc.
the file format of this could be used by package authors to distribute config information (this sounds a lot like a dynamic man page generator).
Then we would have a very useful optional tool that adds value and disrupts nothing.....

@TheRootED24

Copy link
Copy Markdown

The core libraries are designed in principle to be very nimble and contain no frills ...frills are user specific. I am sure this would have been added if it was part of the intention of the library ... the author doesn't miss much ;)

My advice would be to host a package or fork and offer it that way, users that find it useful will thank you, and those that don't will not want to burn your ram out of spite :)

I would say a completely independent new package, that reads in the static /etc/config files and builds a config specific "documentation file" every time it is run, allowing people to add their own comments locked in to each option etc.

I agree with this 100%, openwrt its just a bunch of packages, I have near as many of my own packages as openwrt :) i link to libraries, but build on top, and never within the cores.

@wififreedom

Copy link
Copy Markdown
Author

@bluewavenet @TheRootED24
I don't agree with either of you. IMO not having the option to preserve '#' style comments is very primitive. Comments should just be preserved by default on most systems. Only if someone has a special system where every byte counts, comments should be discarded. You will not convince me otherwise.

I do thank you both for your feedback. It's given me more insight, and I have ideas for an implementation that does not get in anyone's way.

@wififreedom

Copy link
Copy Markdown
Author

I will retract my pull request. The way to go is not by modifying uci and libuci.

One of the technical problems I encounter is that the libuci API is too exposed to make non-breaking changes: all structs can be manipulated at will by clients, and modifying a struct breaks binary compatibility, requiring the client to recompile its code.

There appears to be much opposition to expand a tool that strives to be as lean and mean as possible for embedded systems.

So it seems that '#'-style comments in config files will not be supported for systems that use uci, until uci and libuci can be replaced by something more flexible. I will work on that instead, no results promised.

@wififreedom wififreedom closed this Jul 9, 2026
@wififreedom

Copy link
Copy Markdown
Author

Closed for the above reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants