Some invocations to external programs used exec.CombinedOutput, that
combines stdout and strerr into a single byte array. This can be an
issue if this output is parsed, as many programs print debug output or
warnings to stderr and that data is unexpected by the parsers. This
patch changes to using osutil.RunSplitOutput or osutil.RunCmd (that
return separately stdout and stderr) when we need to parse stdout, and
also in some other cases when printing separately both streams could
be helpful. Fixes LP #1885597.
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
Some target were not having warnings, for instance snap-generator,
because they did not have explicit CFLAGS, and AM_CFLAGS did
not contain CHECK_CFLAGS.
When a device is bound unound to/from a driver, BIND/UNBIND events are
sent. We have been generating error as "unknown action", which
pollutes the logs and confuse users.
While a device node should be present in theory already from the ADD
event, we still ensure the device is added to the cgroup on BIND
events. Like we do with CHANGE events.
The TestParseQuotas was hitting the /v2/quota/<group> endpoint
and with no snapd available it would hang forever. This commit
fixes this by adding the missing fake handler.
Older versions of gcc are buggy and will give incorrect errors when
using `-Wmissing-field-initializers`. This is true on e.g. 14.04
and 16.04. However this is relatively straightforward to detect
and the configure.ac snippet in this commit will take care of it.
* many: add `_daemon_` as valid system username
With the recent adoption of the `_daemon_` user in the spec RK011
by the rocks team we should follow suite and also support the
new `_daemon_` user for snaps.
This commit implements this support.
* osutil: improve comments
* tests: improve system-users-are-created spread test
* many: tweak function naming/comment (thanks to Samuele)
* osutil: rename EnsureUserGroup->EnsureSnapUserGroup
The tiobe software quality checker flaged this and while it's a bit
debatable it adds some clarity around the booleans in the `sc_mount`
struct so I think it's overall worth it.
On any Windows + WSL 2 + Docker system, running any snap command is immediately
preceded by the two errors:
2023/06/17 23:59:52.071511 system_key.go:129: cannot determine nfs usage in
generateSystemKey: cannot parse mountinfo: incorrect number of tail fields,
expected 3 but found 4
2023/06/17 23:59:52.080033 cmd_run.go:1046: WARNING: cannot create user data
directory: cannot determine SELinux status: failed to obtain SELinux mount
path: incorrect number of tail fields, expected 3 but found 4
Those errors confuse tools that parse program output and generally cause a lot of havoc.
The root of the issue is caused by this specific entry in /proc/self/mountinfo
(not wrapped to preserve the problematic part more prominently):
1146 77 0:149 / /Docker/host rw,noatime - 9p drvfs rw,dirsync,aname=drvfs;path=C:\Program Files\Docker\Docker\resources;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio
Note that the super-block mount option contains a key=value pair where the
value contains un-escaped spaces. Historically mountinfo has been an utter mess
to parse, with several bugs in both the userspace parsing and several bugs in
the fragile kernel interface generating the contents of said file.
To work around this problem allow spaces in the super-block options and
silently parse them as if they had been escaped correctly.
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>