Commit Graph

87 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
d422c87e44
sys: compile volume-path regex once, and update GoDoc
Ideally, we would construct this lazily, but adding a function and a
sync.Once felt like a bit "too much".

Also updated the GoDoc for some functions to better describe what they do.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-10-17 00:55:37 +02:00
Sebastiaan van Stijn
c7e6a889b8
sys: remove unused IsAbs() (windows)
This function was forked from Moby in 6089c1525b,
which copied the whole file, but the `IsAbs()` was never used, and has no
external consumers, so let's remove it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-10-14 10:41:23 +02:00
Sebastiaan van Stijn
2e677c9329
sys: move ForceRemoveAll to integration/client
ForceRemoveAll was only used in tests/fuzzing, but added hcsshim as dependency
for the sys package. Moving this to integration/client makes the "sys" package
slightly more lightweight, and may help simplifying dependency-management.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-30 17:39:18 +02:00
Sebastiaan van Stijn
93342d637c
replace sys Sequential funcs with moby/sys/sequential
These functions were originally copied from the docker / moby repository in
4a7a8efc2d. Migrating these functions to use the
github.com/moby/sys/sequential module allows them being shared between moby,
docker/cli, and containerd, and to allow using them without importing all of sys
which also depends on hcsshim and more.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-29 18:36:34 +02:00
Maksym Pavlenko
871b6b6a9f Use testify
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-04-01 18:17:58 -07:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08:00
Wei Fu
6ee8577e54 sys/reaper: avoid leaky goroutine when exec timeout
The channel is created with no capacity that it needs receiver when
sending data. Otherwise, the sending-data goroutine will be blocked
forever. For the #6166 pr, the exec command timeout will return and
no receiver for the data. It will cause goroutine leaky.

This commit allocates buffered channel for the command status and closes
the channel after sending. And also use time.Timer with Stop for
performance concern.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2021-10-31 23:04:04 +08:00
botieking98
3e51312a61 fix shim reaper wait command execute blocked
wait no timeout will lead to event publish
process hang in some special scenarios.

Signed-off-by: botieking98 <botieking@gmail.com>
2021-10-27 15:20:03 +08:00
Claudiu Belu
ca35f4e820 Windows: Cleanup rm- prefixed layers
Some layers might be prefixed with rm-, which will result
in an error when converting that string into an integer.

Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
2021-09-29 12:46:35 -07:00
Eng Zer Jun
50da673592
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-09-21 09:50:38 +08:00
Sebastiaan van Stijn
2ac9968401
replace uses of os/exec with golang.org/x/sys/execabs
Go 1.15.7 contained a security fix for CVE-2021-3115, which allowed arbitrary
code to be executed at build time when using cgo on Windows. This issue also
affects Unix users who have “.” listed explicitly in their PATH and are running
“go get” outside of a module or with module mode disabled.

This issue is not limited to the go command itself, and can also affect binaries
that use `os.Command`, `os.LookPath`, etc.

From the related blogpost (ttps://blog.golang.org/path-security):

> Are your own programs affected?
>
> If you use exec.LookPath or exec.Command in your own programs, you only need to
> be concerned if you (or your users) run your program in a directory with untrusted
> contents. If so, then a subprocess could be started using an executable from dot
> instead of from a system directory. (Again, using an executable from dot happens
> always on Windows and only with uncommon PATH settings on Unix.)
>
> If you are concerned, then we’ve published the more restricted variant of os/exec
> as golang.org/x/sys/execabs. You can use it in your program by simply replacing

This patch replaces all uses of `os/exec` with `golang.org/x/sys/execabs`. While
some uses of `os/exec` should not be problematic (e.g. part of tests), it is
probably good to be consistent, in case code gets moved around.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-25 18:11:09 +02:00
Akihiro Suda
d3aa7ee9f0
Run go fmt with Go 1.17
The new `go fmt` adds `//go:build` lines (https://golang.org/doc/go1.17#tools).

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-08-22 09:31:50 +09:00
Derek McGowan
6f027e38a8
Remove redundant build tags
Remove build tags which are already implied by the name of the file.
Ensures build tags are used consistently

Signed-off-by: Derek McGowan <derek@mcg.dev>
2021-08-05 22:27:46 -07:00
Sebastiaan van Stijn
21f532d518
move sys.FMountat() into mount package
It's the only location this is used, so might as well move it
into that package. I could not find external users of this utility,
so not adding an alias / deprecation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-06-23 18:14:30 +02:00
Sebastiaan van Stijn
5a0beaefbb
sys: remove StatAtime(), StatCtime(), StatMtime() and StatATimeAsTime() utils
This removes the StatAtime(), StatCtime(), StatMtime() and StatATimeAsTime()
utilities from the sys package. These utilities are not currently used in the
containerd codebase, and a copy of these utilities can be found in
github.com/containerd/continuity/fs;

- fa7d162237/fs/stat_darwinbsd.go
- fa7d162237/fs/stat_linuxopenbsd.go

Given that the containerd/sys package is not designed for external consumption,
I'm not adding "deprecated" comments (or aliases to their new location).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-06-23 00:08:49 +02:00
Michael Crosby
ada96ec192
Merge pull request #5328 from kevpar/win-ci-cleanup
Fix error case in Windows layer cleanup
2021-06-03 11:15:39 -04:00
Sebastiaan van Stijn
1c03c377e5
go.mod: github.com/containerd/fifo v1.0.0
full diff: https://github.com/containerd/fifo/compare/115abcc95a1d...v1.0.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-19 09:27:45 +02:00
Kevin Parsons
f8538b5e12 Fix error case in Windows layer cleanup
ForceRemoveAll has special logic on Windows for cleaning up a Windows
snapshotter directory. The logic was missing proper handling for an
error case that can be returned in some cases.

This fixes the CI failure seen in #5326.

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2021-04-09 01:34:57 -07:00
Sebastiaan van Stijn
3d20fa9309
fix TestSetOOMScoreBoundaries
(this was introduced in 44240116aa)

Setting the oom-score-adj to -1000 is only possible if the parent process
either has no score set, or if the score is set to -1000.

However, the current implementation of GetOOMScoreAdj conflates situations
where either _no_ oom-score is set, _or_ oom-score is set, but set to 0.

In the latter case, the test would fail:

    --- FAIL: TestSetOOMScoreBoundaries (0.01s)
        oom_linux_test.go:79: assertion failed: 0 (adjustment int) != -1000 (OOMScoreAdjMin int)
    FAIL

To prevent failures in this situation, skip that part of the test in the
above situation.

Also update the description of GetOOMScoreAdj to clarify its behavior.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-08 13:14:04 +02:00
Sebastiaan van Stijn
7bb73da6b9
runtime/v2/shim: remove unused SetScore() and remove sys.OOMScoreMaxKillable
The shim.SetScore() utility was no longer used since 7dfc605fc6.

Checking for uses outside of this repository, I found only one external use of
this in gVisor; a9441aea27/pkg/shim/service.go (L262-L264)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:58 +02:00
Sebastiaan van Stijn
91e7d21ee8
sys: add AdjustOOMScore() utility
Handle the limits in this function so that consumers don't have to
perform the boundary checks.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:56 +02:00
Sebastiaan van Stijn
44240116aa
sys: add boundary checks to SetOOMScore()
Produce a more user-friendly error in the odd case we would try to set a
score out of range

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:55 +02:00
Sebastiaan van Stijn
ace1912bba
sys: use assert for error checks in OOM tests
Slightly easier to read, and we were already using assert in this file

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:53 +02:00
Sebastiaan van Stijn
6e72715226
sys: add missing pre-condition checks in tests
SetOOMScore requires both privileged (root) and non-user namespace,
for negative values, so adjust the pre-conditions accordingly.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:51 +02:00
Sebastiaan van Stijn
badd60d3f6
sys: un-export runningPrivileged(), remove runningUnprivileged()
These are currently only used inside this package, so we might
as well un-export them until we need them elsewhere.

Also updated SetOOMScore() to first check for privileged; check for privileged
looks to be the "faster" path, and checking it first could (in case of non-
privileged) save having to read and parse /proc/self/uid_map.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:49 +02:00
Paul "TBBle" Hampson
da7d96ba3f Clean up WCOW layers after tests in the correct order
This ensures that we do not trigger assertions inside HCS by tring to
call hcsshim.DestroyLayer on the parent of a currently-activated layer.

It also deactivates the layers before deletion, to ensure we trigger or
avert file-in-use failures due to leftover state from the tests with
more detail than 'destroy failed'.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2021-03-25 05:26:24 +11:00
Maksym Pavlenko
eb7c7c71e2 Fix oom tests on non Linux
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2021-03-23 11:57:24 -07:00
Sebastiaan van Stijn
708299ca40
Move RunningInUserNS() to its own package
This allows using the utility without bringing whole of "sys" with it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-23 11:29:53 +01:00
Muhammad Kaisar Arkhan
380b52652c Bring OpenBSD support
Signed-off-by: Muhammad Kaisar Arkhan <hi@yukiisbo.red>
2021-01-04 14:43:48 +01:00
Simon Kaegi
da2fd657ab Add bounds on max oom_score_adj value for AdjustOOMScore
oom_score_adj must be in the range -1000 to 1000. In AdjustOOMScore if containerd's score is already at the maximum value we should set that value for the shim instead of trying to set 1001 which is invalid.

Signed-off-by: Simon Kaegi <simon_kaegi@ca.ibm.com>
2020-12-14 15:09:24 -05:00
Phil Estes
af2fb4eb77
Allow oom adj test to run in environments with a score
GitHub Actions process wrapper sets score adj to 500 for any process;
the OOM score adj test expected default adj to be 0 during test.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2020-11-19 08:43:32 -05:00
Leonardo Taccari
4c47fe0a2f Add support for NetBSD
Signed-off-by: Leonardo Taccari <leot@NetBSD.org>
2020-09-22 20:03:50 +02:00
Gaurav Singh
ae08491bff waitForPid: fix goroutine leak
Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
2020-06-07 17:33:10 -04:00
Sebastiaan van Stijn
dc92ad6520
Replace errors.Cause() with errors.Is()
Dependencies may be switching to use the new `%w` formatting
option to wrap errors; switching to use `errors.Is()` makes
sure that we are still able to unwrap the error and detect the
underlying cause.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-08 14:36:45 +02:00
Phil Estes
990076b731
Merge pull request #4228 from thaJeztah/refactor_reaper
Refactor reaper-related functionality to be in the sys/reaper package
2020-05-07 14:32:55 -04:00
Sebastiaan van Stijn
0088c2de80
sys: RunningInUserNS(): use sync.Once
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-04 18:57:02 +02:00
Sebastiaan van Stijn
76c62f2722
sys: simplify RunningInUserNS to original implementation
Given that we're only interested in detecting if userns is
enabled, and no further details about the mapping, we can
revert this function to go back to its original implementation
in github.com/lxc/lxd/shared/util.go

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-04 18:56:59 +02:00
Sebastiaan van Stijn
6a9b94927f
Remove remaining uses of libcontainer/system package
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-04 18:56:57 +02:00
Sebastiaan van Stijn
37c839e594
sys/proc: remove GetSystemCPUUsage as it is unused
After e115b52ce2 was merged, this
function was no longer in use, so we should be able to remove it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-04 13:40:19 +02:00
Sebastiaan van Stijn
1b66fecad3
Integrate sys.SetSubreaper, sys.GetSubreaper in sys/reaper package
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-04 08:44:02 +02:00
Sebastiaan van Stijn
fffea312aa
move sys.Reap() into sys/reaper package
It was only used in sys/reaper, and after moving it, that package
no longer depends on the `sys` package.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-04 08:44:00 +02:00
Sebastiaan van Stijn
295e74008f
sys: remove custom setChildSubreaper const
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-04 08:43:57 +02:00
Haitao Li
35c14c6b56 sys/mount_linux: use pipe for communicating mount result
forkAndMountat forks a process to chdir then mount layers. Signals are
blocked (using runtime_beforeFork) during fork.

There is a race condition that the child process finishes before the
parent process is scheduled and can unblock signal handling. The SIGCHLD
signal sent from the finished process may have been delivered to the
shim process's reaper thread and caused the parent process fail with
ECHLD error.

This patch sets up a pipe for communication between child and parent
instead of waiting for child exit status.

Fixes #4009.

Signed-off-by: Haitao Li <hli@atlassian.com>
2020-04-09 09:50:41 +10:00
Phil Estes
0c78dacbc5
Move isFifo from process/io to sys/ and make public
Make "IsFifo" a public function for use by other parts of containerd
codebase.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2020-03-25 10:44:17 -04:00
Sebastiaan van Stijn
6320236985
Partial revert of sys: windows: use golang.org/x/sys/windows
- preserve `syscall.ENOTDIR` to match os.MkDirAll
- change back parameter name to `adminAndLocalSystem`
- revert accidental change of permissions of parent-dir

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-09 16:01:09 +01:00
Michael Crosby
9ec579bf8a
Merge pull request #4093 from thaJeztah/replace_more_syscall
sys: windows: use golang.org/x/sys/windows
2020-03-09 10:47:23 -04:00
Sebastiaan van Stijn
0a7fd55f32
sys: deprecate EpollCreate1, EpollCtl, EpollWait
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-09 13:15:07 +01:00
Sebastiaan van Stijn
7b06192f61
sys: windows: use golang.org/x/sys/windows
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-03-09 13:05:53 +01:00
Sebastiaan van Stijn
f2edc6f164
vendor: update gotest.tools v3.0.2
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-28 17:47:20 +01:00
Shengjing Zhu
35a8e6e589 sys: clean up process after test
Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2020-01-15 22:03:39 +08:00