98 Commits

Author SHA1 Message Date
Aleksa Sarai 1e20abef19 runc: add libpathrs info to --version and features
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2026-06-18 11:57:38 +02:00
lifubang 57fad01d52 chore(deps): upgrade urfave/cli from v1 to v3
Migrate from urfave/cli v1 (maintenance mode) to v3 to benefit from
active development, improved features, and long-term support.

Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-05-20 05:26:51 +00:00
Aleksa Sarai 627054d246 lint/revive: add package doc comments
This silences all of the "should have a package comment" lint warnings
from golangci-lint.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-10-03 15:17:43 +10:00
Kir Kolyshkin c12c99b7d2 runc: embed version from VERSION file
This ensures that if runc is built without the provided Makefile, the
version is still properly set.

No change in the output.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-23 09:31:26 -07:00
Kir Kolyshkin d54eaaf2c2 runc --version: use a function
Instead of setting cli.App.Version in main, let's set up
cli.VersionPrinter. This way, we only get various versions
when needed.

Note it does not change the output of runc --version.

It changes the output of runc --help though, and I think it's for the
better.

Before this patch:

> $ runc help
> ...
> USAGE:
>    runc [global options] command [command options] [arguments...]
>
> VERSION:
>    1.3.0-rc.1+dev
> commit: v1.3.0-rc.1-93-g932e8342
> spec: 1.2.1
> go: go1.24.2
> libseccomp: 2.5.5
>
> COMMANDS:
>    checkpoint  checkpoint a running container
> ...

After:

> $ runc help
> ...
> USAGE:
>    runc [global options] command [command options] [arguments...]
>
> VERSION:
>    1.3.0-rc.1+dev
>
> COMMANDS:
>    checkpoint  checkpoint a running container
> ...

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-23 09:31:26 -07:00
Kir Kolyshkin 1d78cb2112 Completely remove --criu option
This option is ignored since commit 6e1d476a, it's now time to actually
remove it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-09 10:10:50 -07:00
Kir Kolyshkin a75076b4a4 Switch to opencontainers/cgroups
This removes libcontainer/cgroups packages and starts
using those from github.com/opencontainers/cgroups repo.

Mostly generated by:

  git rm -f libcontainer/cgroups

  find . -type f -name "*.go" -exec sed -i \
    's|github.com/opencontainers/runc/libcontainer/cgroups|github.com/opencontainers/cgroups|g' \
    {} +

  go get github.com/opencontainers/cgroups@v0.0.1
  make vendor
  gofumpt -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-02-28 15:20:33 -08:00
Kir Kolyshkin 4f3319b56d libct: decouple libct/cg/devices
Commit b6967fa84c moved the functionality of managing cgroup devices
into a separate package, and decoupled libcontainer/cgroups from it.

Yet, some software (e.g. cadvisor) may need to use libcontainer package,
which imports libcontainer/cgroups/devices, thus making it impossible to
use libcontainer without bringing in cgroup/devices dependency.

In fact, we only need to manage devices in runc binary, so move the
import to main.go.

The need to import libct/cg/dev in order to manage devices is already
documented in libcontainer/cgroups, but let's
 - update that documentation;
 - add a similar note to libcontainer/cgroups/systemd;
 - add a note to libct README.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-04-17 15:05:38 -07:00
Kir Kolyshkin 899342b5d4 main: improve XDG_RUNTIME_DIR handling
1. Variable xdgRuntimeDir is only checked to be non-empty. Change it to
   a boolean.

2. Refactor so that os.Getenv is not called twice.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-02-18 16:05:29 -08:00
Kir Kolyshkin 6e1d476aad runc: remove --criu option
This was introduced in an initial commit, back in the day when criu was
a highly experimental thing. Today it's not; most users who need it have
it packaged by their distro vendor.

The usual way to run a binary is to look it up in directories listed in
$PATH. This is flexible enough and allows for multiple scenarios (custom
binaries, extra binaries, etc.). This is the way criu should be run.

Make --criu a hidden option (thus removing it from help). Remove the
option from man pages, integration tests, etc. Remove all traces of
CriuPath from data structures.

Add a warning that --criu is ignored and will be removed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-01-26 20:25:56 -08:00
Akihiro Suda 520702dac5 Add runc features command
Fix issue 3274

See `types/features/features.go`.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-11-30 16:40:39 +09:00
Kir Kolyshkin a20c8b29d4 runc --debug: shorter caller info
Commit 9f3d7534ea enabled logrus to show information about log
caller, if --debug is set.

The problem is, the file name and in many cases the function name have a
long prefix of github.com/opencontainers/runc (this is with -trimpath,
and without it it's worse).

Add a function to trim the prefix.

Note all this happens only when --debug is given.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-04 11:47:31 -07:00
Kir Kolyshkin f77fb7a3ee init.go, main.go: don't use logs.ConfigureLogging
This function is somewhat strange and I always wanted to remove it,
as it tries to satisfy both init.go and main.go, which have somewhat
different needs.

It is more straightforward and readable to configure logrus directly.

While at it, simplify errors on panic (errors from logrus.ParseLevel
and strconv.Atoi already contain value which they fail to parse, and
panic already contains enough context to figure out what's wrong).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-20 10:59:46 -07:00
Kir Kolyshkin 7a0302f0d7 runc init: simplify
runc init is special. For one thing, it needs to do a few things before
main(), so we have func init() that checks if we're init and does that.

What happens next is main() is called, which does some options parsing,
figures out it needs to call initCommand.Action and so it does.

Now, main() is entirely unnecessary -- we can do everything right from
init().

Hopefully the change makes things slightly less complicated.

From a user's perspective, the only change is runc help no longer
lists 'runc init` (which I think it also good).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-27 12:16:09 -07:00
Kir Kolyshkin e8bd33ae28 runc --help: improve log options description
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-15 17:49:56 -07:00
Kir Kolyshkin e6048715e4 Use gofumpt to format code
gofumpt (mvdan.cc/gofumpt) is a fork of gofmt with stricter rules.

Brought to you by

	git ls-files \*.go | grep -v ^vendor/ | xargs gofumpt -s -w

Looking at the diff, all these changes make sense.

Also, replace gofmt with gofumpt in golangci.yml.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-01 12:17:27 -07:00
Kir Kolyshkin aa934af087 runc -v: set default for, always show main.version
Apparently not everyone compiles runc via the provided Makefile. For
example, one can just run "go build", in which case Version variable
is left empty, which leads to:

	$ ./runc -v
	runc version spec: 1.0.2-dev
	go: go1.16.3

Surely, the main problem here is runc was built in a wrong way, but the
second problem is such output is very confusing -- it may seem that we
have runc 1.0.2.

To solve, make sure to _always_ add version (even if empty), and set the
default to "unknown".

NOTE this does not change anything in case runc is compiled via the
Makefile.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-05-25 12:07:12 -07:00
Kir Kolyshkin 9f3d7534ea logging: enable file/line info if --debug is set
This helps a lot to find out where the errors come from.

Before:
> level=warning msg="lstat /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/test_hello: no such file or directory"

After:
> level=warning msg="lstat /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/test_hello: no such file or directory" func=github.com/opencontainers/runc/libcontainer.destroy file="github.com/opencontainers/runc/libcontainer/state_linux.go:44"

Presumably this comes with an overhead, but I guess no one is using
--debug by default anyway.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-15 10:58:29 -07:00
Mrunal Patel 1827254afe Merge pull request #2870 from kolyshkin/seccomp-version
libct/seccomp: remove IsEnabled
2021-03-26 11:20:55 -07:00
Kir Kolyshkin 688ea99e1b runc init: fix double call to ConfigureLogs
I have noticed that ConfigureLogs do not return an error in case logging
was already configured -- instead it just warns about it. So I went
ahead and changed the warning to the actual error...

... only to discover I broke things badly, because in case of runc init
logging is configured twice. The fix is to not configure logging in case
we are init.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin dd6c8d76bb main: cast Chmod argument to os.FileMode
This fixes a big red warning in my vim.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin d38d1f9f79 libcontainer/logs: use int for Config.LogPipeFd
It does not make sense to have a string for a numeric type.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin 9b2f1e6fb6 runc version: don't use seccomp.IsEnabled
As pointed out to in [1], seccomp.IsEnabled does some runtime checks,
while here (when printing libseccomp version) we should merely print
the version number of libseccomp, if compiled in.

Change the code to check if the version is non-zero (as seccomp.Version
returns 0, 0, 0 in case seccomp is not compiled in.

[1] https://github.com/opencontainers/runc/pull/2866

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-23 16:10:08 -07:00
Kir Kolyshkin c11e997a59 Merge pull request #2629 from knabben/revise-root
Convert root path to absolute on create command
2020-10-06 13:45:01 -07:00
root ede8a86ec1 Convert root path to absolute path on create command
Signed-off-by: Amim Knabben <amim.knabben@gmail.com>
2020-10-03 07:56:27 -04:00
Sebastiaan van Stijn 8bf216728c use string-concatenation instead of sprintf for simple cases
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-30 10:51:59 +02:00
Akihiro Suda 6249136a29 add libseccomp version to runc --version
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-08-08 04:56:29 +09:00
Akihiro Suda 1d85333ad8 add runtime.Version() to runc --version
Printing Go version would be helpful to debug runtime-related errors.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-08-08 04:55:09 +09:00
Kir Kolyshkin 1b84a21c51 Don't print errors twice
Function fatal() and method (*FatalWriter).Write log the error to the
logger when prints it to stderr just be be sure. Since by default the
logger is configured to write to os.Stderr, we get something like this
as a result:

> # ./runc checkpoint xx5
> ERRO[0000] Container cannot be checkpointed in stopped state
> Container cannot be checkpointed in stopped state

or

> # ./runc sdf
> ERRO[0000] No help topic for 'sdf'
> No help topic for 'sdf'

This is very annoying.

To fix, check if logrus is logging into stderr, and if it is, skip
the second write.

After this commit:

> # ./runc sdf
> ERRO[0000] No help topic for 'sdf'

> [root@kir-rhat runc]# ./runc --log=out sdf
> No help topic for 'sdf'

Note that now the logrus prefix might be in or out, depending on whether
logrus is logging to stderr or not. This is not perfect, but better than
the old behavior.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-02 18:13:07 -07:00
lifubang 7d6e091fe0 fix error when there is --root and XDG_RUNTIME_DIR env
Signed-off-by: lifubang <lifubang@acmcoder.com>
Signed-off-by: Lifubang <lifubang@acmcoder.com>
Signed-off-by: lifubang <lifubang@acmcoder.com>
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2020-03-12 10:16:53 +08:00
Giuseppe Scrivano 8383c724a4 main: not reopen /dev/stderr
commit a146081828 introduced a change to
write to /dev/stderr by default.  Do not reopen the file in this case,
but use directly the fd 2.

Closes: https://github.com/opencontainers/runc/issues/2056
Closes: https://github.com/kubernetes/kubernetes/issues/77615
Closes: https://github.com/cri-o/cri-o/issues/2368

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-14 21:56:41 +02:00
Georgi Sabev a146081828 Write logs to stderr by default
Minor refactoring to use the filePair struct for both init sock and log pipe

Co-authored-by: Julia Nedialkova <julianedialkova@hotmail.com>
Signed-off-by: Georgi Sabev <georgethebeatle@gmail.com>
2019-04-24 15:18:14 +03:00
Georgi Sabev ba3cabf932 Improve nsexec logging
* Simplify logging function
* Logs contain __FUNCTION__:__LINE__
* Bail uses write_log

Co-authored-by: Julia Nedialkova <julianedialkova@hotmail.com>
Co-authored-by: Danail Branekov <danailster@gmail.com>
Signed-off-by: Georgi Sabev <georgethebeatle@gmail.com>
2019-04-22 17:53:52 +03:00
Danail Branekov c486e3c406 Address comments in PR 1861
Refactor configuring logging into a reusable component
so that it can be nicely used in both main() and init process init()

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
Co-authored-by: Giuseppe Capizzi <gcapizzi@pivotal.io>
Co-authored-by: Claudia Beresford <cberesford@pivotal.io>
Signed-off-by: Danail Branekov <danailster@gmail.com>
2019-04-04 14:57:28 +03:00
Marco Vedovati 9a599f62fb Support for logging from children processes
Add support for children processes logging (including nsexec).
A pipe is used to send logs from children to parent in JSON.
The JSON format used is the same used by logrus JSON formatted,
i.e. children process can use standard logrus APIs.

Signed-off-by: Marco Vedovati <mvedovati@suse.com>
2019-04-04 14:53:23 +03:00
Akihiro Suda 06f789cf26 Disable rootless mode except RootlessCgMgr when executed as the root in userns
This PR decomposes `libcontainer/configs.Config.Rootless bool` into `RootlessEUID bool` and
`RootlessCgroups bool`, so as to make "runc-in-userns" to be more compatible with "rootful" runc.

`RootlessEUID` denotes that runc is being executed as a non-root user (euid != 0) in
the current user namespace. `RootlessEUID` is almost identical to the former `Rootless`
except cgroups stuff.

`RootlessCgroups` denotes that runc is unlikely to have the full access to cgroups.
`RootlessCgroups` is set to false if runc is executed as the root (euid == 0) in the initial namespace.
Otherwise `RootlessCgroups` is set to true.
(Hint: if `RootlessEUID` is true, `RootlessCgroups` becomes true as well)

When runc is executed as the root (euid == 0) in an user namespace (e.g. by Docker-in-LXD, Podman, Usernetes),
`RootlessEUID` is set to false but `RootlessCgroups` is set to true.
So, "runc-in-userns" behaves almost same as "rootful" runc except that cgroups errors are ignored.

This PR does not have any impact on CLI flags and `state.json`.

Note about CLI:
* Now `runc --rootless=(auto|true|false)` CLI flag is only used for setting `RootlessCgroups`.
* Now `runc spec --rootless` is only required when `RootlessEUID` is set to true.
  For runc-in-userns, `runc spec`  without `--rootless` should work, when sufficient numbers of
  UID/GID are mapped.

Note about `$XDG_RUNTIME_DIR` (e.g. `/run/user/1000`):
* `$XDG_RUNTIME_DIR` is ignored if runc is being executed as the root (euid == 0) in the initial namespace, for backward compatibility.
  (`/run/runc` is used)
* If runc is executed as the root (euid == 0) in an user namespace, `$XDG_RUNTIME_DIR` is honored if `$USER != "" && $USER != "root"`.
  This allows unprivileged users to allow execute runc as the root in userns, without mounting writable `/run/runc`.

Note about `state.json`:
* `rootless` is set to true when `RootlessEUID == true && RootlessCgroups == true`.

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2018-09-07 15:05:03 +09:00
Akihiro Suda f103de57ec main: support rootless mode in userns
Running rootless containers in userns is useful for mounting
filesystems (e.g. overlay) with mapped euid 0, but without actual root
privilege.

Usage: (Note that `unshare --mount` requires `--map-root-user`)

  user$ mkdir lower upper work rootfs
  user$ curl http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/x86_64/alpine-minirootfs-3.7.0-x86_64.tar.gz | tar Cxz ./lower || ( true; echo "mknod errors were ignored" )
  user$ unshare --mount --map-root-user
  mappedroot# runc spec --rootless
  mappedroot# sed -i 's/"readonly": true/"readonly": false/g' config.json
  mappedroot# mount -t overlay -o lowerdir=./lower,upperdir=./upper,workdir=./work overlayfs ./rootfs
  mappedroot# runc run foo

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2018-05-10 12:16:43 +09:00
Aleksa Sarai 4f4af7bfde rootless: set sticky bit if using XDG_RUNTIME_DIR
According to the XDG specification[1], in order to avoid the possibility of
our container states being auto-pruned every 6 hours we need to set the
sticky bit. Rather than handling all of the users of --root, we just
create the directory and set the sticky bit during detection, as it's
not expensive.

[1]: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2018-03-19 11:02:31 +11:00
Giuseppe Scrivano fdf85e35b3 main: honor XDG_RUNTIME_DIR for rootless containers
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2017-09-09 12:44:34 +10:00
Steven Hartland ee4f68e302 Updated logrus to v1
Updated logrus to use v1 which includes a breaking name change Sirupsen -> sirupsen.

This includes a manual edit of the docker term package to also correct the name there too.

Signed-off-by: Steven Hartland <steven.hartland@multiplay.co.uk>
2017-07-19 15:20:56 +00:00
Kenfe-Mickael Laventure 294d24fb1a Ensure we log into logrus on command error
`urfave/cli` now takes upon itself to log the error returned by the
command action directly. This means that by default the `--log` option
was ignored upon error.

This commit ensure that `urfave/cli.ErrWriter` will use logrus

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
2016-10-03 08:01:09 -07:00
Mrunal Patel a753b06645 Replace github.com/codegangsta/cli by github.com/urfave/cli
The package got moved to a different repository

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2016-06-06 11:47:20 -07:00
rajasec 0307c88ee9 Updating README for starting the container
Signed-off-by: rajasec <rajasec79@gmail.com>

Updating README for starting the container

Signed-off-by: rajasec <rajasec79@gmail.com>

Updating README files for container start

Signed-off-by: rajasec <rajasec79@gmail.com>

updating README files for container start

Signed-off-by: rajasec <rajasec79@gmail.com>
2016-06-05 14:41:58 +05:30
Michael Crosby c5060ff303 Merge pull request #827 from crosbymichael/create-start
Implement create and start
2016-06-03 10:38:03 -07:00
Michael Crosby 3fe7d7f31e Add create and start command for container lifecycle
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2016-05-31 11:06:41 -07:00
Michael Crosby 75fb70be01 Rename start to run
`runc run` is the command that will create and start a container in one
single command.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2016-05-31 11:06:41 -07:00
Qiang Huang 152ee95380 Add VERSION file to contain the version info
We need this because we need to get version info out of
go code, eg. build rpm package.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
2016-05-30 10:24:22 +08:00
Zhao Lei f79716d6cf Unify log setting's error output
When we set a wrong --log-format value, runc exit without any
message:
 # ./runc --log-format aaa list
 #
It is again "no news is good news" rule.

And it is not unified with the case when we set a wrong --log
value:
 # ./runc --log / list
 ERRO[0000] open /: is a directory
 open /: is a directory
 #

This patch unified action for above two error-setting.

After patch:
 # ./runc --log-format aaa list
 unknown log-format: "aaa"
 #

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
2016-05-25 16:10:30 +08:00
Kenfe-Mickael Laventure 4190e5a920 Add new update command to runc.
This command allow users to update some of a container cgroups
parameters.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
2016-05-06 08:05:15 -07:00
Mrunal Patel 8075a9ee6f Change OCF to OCI in help string and man page.
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2016-05-03 16:05:20 -07:00