GNOME Bugzilla – Bug 795346
/etc/os-release parser fails on comments or empty lines
Last modified: 2018-04-29 11:04:35 UTC
command: ./cerbero-uninstalled bootstrap If there is an empty line in /etc/os-release cerbero fails with Traceback (most recent call last):
+ Trace 238565
from cerbero.main import main
from cerbero import hacks
from cerbero.utils.shell import call as shell_call
PLATFORM = system_info()[0]
k,v = line.rstrip().split("=")
Comments introduced by '#' are parsed, so a missing '=' in the comment will also trigger Traceback (most recent call last):
whereas a commented '=' won't.
Thanks for the bug report. Are you going to make a patch for this? :)
(In reply to Tim-Philipp Müller from comment #1) > Thanks for the bug report. Are you going to make a patch for this? :) I'm on page 3 of "python for dummies". Pages 1-2 were about finding bugs in build systems 8-) Sorry, no patch so far. I'll continue reading 8-)
Maybe something like try: ...split.. except: continue ? (Not really a python person myself either, there might be a more idiomatic solution) Also seems like it doesn't handle there not being a VERSION_ID gracefully
Which distro has comments in its /etc/os-release ? Can you attach the file here so whoever writes a patch can test against it?
And indeed comments are valid in there, ref: https://www.freedesktop.org/software/systemd/man/os-release.html
(In reply to Olivier Crête from comment #4) > Which distro has comments in its /etc/os-release ? Can you attach the file > here so whoever writes a patch can test against it? Hmmm... as you said, comments are valid. To be honest, empty lines are not mentioned. So we cannot really support them. The parser should stop immediately when it reads an empty line. Maybe tell the user to contact his distro to fix it. maybe force a system upgrade in background to see if this has been fixed already. Anyways, I don't think we want to discuss the format of /etc/os-release of distro xyz or force a patch writer to install distro xyz for testing purposes, would we ? sudo echo "#" > /etc/os-release ... would be the first thing he should try for testing 8-) "creating your own distro for dummies - page 12" open I,'<','/etc/os-release' or die; while(<I>){ /^\s*#.*//; /^\s*$/ and next; /(\S+)\s*=\s*(.*)\s*/ and $V{$1}=$2; } close(I); untested code in an 80s language ("writing pseudo code in ancient languages - national geograhics, book 314, page 1592") or maybe, for testing purposes, create a local copy of /etc/os-release via "cp /etc/os-release os-release" and change the code by deleting the "/etc" part of the filename. There might be a python module for "cp". sorry, I don't want to troll, but hey: this program parses a text file of a couple of lines, and we are discussing "valid formats" ? give me a break.
Created attachment 371154 [details] [review] utils: skip empty lines and comment lines when parsing /etc/os-release
I created issue *Specify if blank lines are allowed in `/etc/os-release` #8773* for systemd [1] asking for a clarification. [1]: https://github.com/systemd/systemd/issues/8773
Ok, but it's trivial to skip empty lines so I don't see why we don't just implement that and get on with our lives? Does the patch fix the issue on your machine?
Please re-open if it's still a problem, thanks. commit f7ebcf3371dc56b04ec33e453e94907a2dedb384 Author: Tim-Philipp Müller <tim@centricular.com> Date: Fri Apr 20 12:53:36 2018 +0100 utils: skip empty lines and comment lines when parsing /etc/os-release https://bugzilla.gnome.org/show_bug.cgi?id=795346