19 Commits

Author SHA1 Message Date
Alfonso Sánchez-Beato
bad061e63f osutil: add RunCmd and RunSplitOutput functions
These functions return separately std{err,out}, and will be used to
replace calls to exec.CombinedOuput.
2023-10-05 14:14:28 +02:00
Arseniy Aharonov
fcc3ba8aea osutil: refactoring the code exporting mocking APIs to other packages
* osutil: Refactoring the code exporting mocking APIs to other packages

File 'mockable.go' is used to mock certain data obtained by 'osutil'
from the system (e.g. 'mountinfo'). The file also contained some
variables that belong to production code itself. A cleanup
refactoring was applied to this file and 'mountinfo_linux.go':
- Package variables moved from 'mockable.go' to logic that owns it
- Test-related logic moved from 'mountinfo_linux.go' to 'mockable.go'
- United and refactored logic designed to mock 'mountinfo'

Signed-off-by: Arseniy Aharonov <arseniy.aharonov@canonical.com>

* osutil: Fixes and cleanups after the code review

Signed-off-by: Arseniy Aharonov <arseniy.aharonov@canonical.com>

* osutil: make mustNotBeTestBinary function non-exportable

To avoid unwonted usage of this method in different places in
the code it was requested to make this function local to package
osutil only.

Signed-off-by: Arseniy Aharonov <arseniy.aharonov@canonical.com>

* osutil: refactoring mountinfo code following PR review

My original refactoring of the mountinfo logic introduced
an inconsistency into the code, so that os-agnostic code
contain Linux-related logic. This inconsistencey was
eliminated.

Signed-off-by: Arseniy Aharonov <arseniy.aharonov@canonical.com>
2022-01-25 17:44:18 +01:00
Michael Vogt
f0dd2d524e osutil,cmdutil: move CommandFromCore and make it use the snapd snap (if available)
The CommandFromCore helper is currently always looking at the
core snap. With the snapd snap we need to refactor it so that
it uses the snapd snap if available and just falls back to the
core snap.

The osutil.CommandFromCore is not in the rightplace and it also does
not take the snapd snap into account. This PR moves it to the
cmd/cmdutil package (cannot be in cmd because of an import cycle
with cmd/snapinfo.go).

It also tweaks the arguments slightly (no need to pass the
snapMountDir anymore).
2019-04-30 16:07:35 +02:00
Maciej Borzecki
9caacd035d osutil: do not import dirs
Importing `dirs` package in `osutil` leads to import cycles if one attempts to
use `osutils` from packages that are directly or indirectly imported by `dirs`,
such as `release`. It doesn't make any sense for `osutil` to depend on
other non `*util` packages.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2018-12-11 07:27:28 +01:00
Michael Vogt
7c30819254 Merge pull request #4584 from stolowski/fix-hooks-oom
hooks/strutil: limit the number of data read from the hooks to avoid oom
2018-02-23 09:36:17 +01:00
Zygmunt Krynicki
5d5e6c4736 osutil: aggregate mockable symbols
This will help in upcoming improvements to mocking. As more things are
added to osutil it is sometimes unclear what is being mocked and how.
This patch should help to improve the situation.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-02-22 18:29:13 +01:00
Pawel Stolowski
6d33df4208 Renamed to LimitedBuffer. 2018-02-07 10:48:23 +01:00
Pawel Stolowski
83168576d3 Use Buffer internally in the LimitedWriter. Updated spread test. 2018-02-05 13:15:15 +01:00
Pawel Stolowski
f41c708e24 Better LimitedWriter. 2018-02-05 12:15:29 +01:00
Pawel Stolowski
a5750d9847 Fix comment. 2018-02-02 11:38:02 +01:00
Pawel Stolowski
d2ac747b3a Truncate output by num of lines and bytes. 2018-02-02 10:42:09 +01:00
Pawel Stolowski
7703378c06 Kill the hook if buffer size is exceeded. Use bytes.Buffer in the LimitedWriter (thanks to Maciej for suggestion). 2018-02-02 09:45:52 +01:00
Pawel Stolowski
12738f3b9a Report buffer error via channel. 2018-02-01 18:06:21 +01:00
Pawel Stolowski
b9d8665ee9 Introduce LimitedWriter to limit the number of data read from the stdout/stderr of hooks. 2018-02-01 13:54:38 +01:00
Michael Vogt
e9981423f4 add defaultTimeout of 30min for repairs 2017-08-21 16:49:59 +02:00
John R. Lenton
e0b8200f67 osutil: introducing WaitingReader 2017-07-03 15:38:48 +01:00
John R. Lenton
f67bedbb58 osutil: unexport KillProcessGroup until we have a use case
also tweak some error messages (thanks @pedronis for the review).
2017-06-20 12:04:50 +01:00
John R. Lenton
d35701d3a0 osutil: RunAndWait, for DRY between hookstate and oddjobstate. 2017-06-20 12:04:50 +01:00
Michael Vogt
0e53b0aac9 store: use xdelta3 from core if available and not on the regular system (#2791)
This avoids us having to add a dependency to snapd for xdelta3 (and fixes the issues that snapd 2.0.10 from Ubuntu 16.04.1 won't apt-get upgrade with any new dependencies).

It is slightly complicated because we want to ensure that the correct ld-linux.so is used and also that the correct libraries from core (instead of from the host) are used.
2017-02-15 10:52:09 -02:00