Commit graph

163 commits

Author SHA1 Message Date
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Tom Gundersen 039dd4afd6 nspawn: UP the host side of the veth pair after adding it to a bridge 2014-03-16 13:55:41 +01:00
Dave Reisner 7947952ede nspawn: remove unused variable 2014-03-13 21:56:07 -04:00
Brandon Philips f418f31d50 nspawn: allow -EEXIST on mkdir_safe /home/${uid}
With systemd 211 nspawn attempts to create the home directory for the
given uid. However, if the home directory already exists then it will
fail. Don't error out on -EEXIST.
2014-03-14 02:25:56 +01:00
Tom Gundersen 01dde0611b nspawn: make host0's MAC address persistent
We still need to make sure that no two MAC addresses are the same, so we use
a logic similar to what is used in udev to generate MAC addresses, and base
it on a hash of the host's machine ID and thecontainer's name.
2014-03-13 17:47:33 +01:00
Lennart Poettering 727fd4fda5 nspawn: honour GPT partition flags when mounting file systems following the discoverable partitions spec 2014-03-13 01:33:33 +01:00
Mantas Mikulėnas 4de8292689 nspawn: fix argv[0] for getent 2014-03-11 17:45:20 +01:00
Lennart Poettering a07f961e98 nspawn: allow using kdbus from nspawn containers 2014-03-11 17:43:41 +01:00
Lennart Poettering 8c4e25b73c nspawn: fix getent fallback 2014-03-11 03:08:54 +01:00
Lennart Poettering 0cb9fbcd44 nspawn: when resoliving UIDs/GIDs for "-u", do so in forked off /usr/bin/getent instead of in-process
When the container runs a different native architecture than the host we
shouldn't attempt to load the container's NSS modules with the host's
libc. Instead, resolve UID/GID by invoking /usr/bin/getent in the
container. The tool should be fairly universally available and allows us
to do resolving of the UID/GID with the container's libc in a parsable
format.

https://bugs.freedesktop.org/show_bug.cgi?id=75733
2014-03-11 02:41:13 +01:00
Lennart Poettering d96c1ecf7b nspawn: make sure we don't try to mount the container block device in the child after the parent added us to the device cgroup 2014-03-11 01:01:38 +01:00
Lennart Poettering eb0f0863f5 nspawn: don't try mknod() of /dev/console with the correct major/minor
We overmount /dev/console with an external pty anyway, hence there's no
point in using the real major/minor when we create the node to
overmount. Instead, use the one of /dev/null now.

This fixes a race against the cgroup device controller setup we are
using. In case /dev/console was create before the cgroup policy was
applied all was good, but if created in the opposite order the mknod()
would fail, since creating /dev/console is not allowed by it. Creating
/dev/null instances is however permitted, and hence use it.
2014-03-10 21:36:01 +01:00
Lennart Poettering 1b9e5b1263 nspawn: add --image= switch to boot GPT disk images that follow the Discoverable Partitions Specification 2014-03-10 20:35:52 +01:00
Tero Roponen 13e8ceb84e nspawn: fix detection of missing /proc/self/loginuid
Running 'systemd-nspawn -D /srv/Fedora/' gave me this error:
 Failed to read /proc/self/loginuid: No such file or directory

 Container Fedora failed with error code 1.

This patch fixes the problem.
2014-02-28 12:58:02 +01:00
Lennart Poettering 9875fd7875 nspawn: no need for duplicate checks against EEXIST 2014-02-26 02:19:28 +01:00
Lennart Poettering c74e630d0c nspawn: add new switch --network-macvlan= to add a macvlan device to the container 2014-02-25 02:37:59 +01:00
Lennart Poettering 9457ac5b4e nspawn: make use of the devices cgroup controller by default 2014-02-24 03:38:58 +01:00
Lennart Poettering 08af0da269 nspawn: when adding a veth interface to a bridge, use the "vb-" rather than "ve-" interface name prefix
This way we can recognize the interfaces later on to apply different
host-side configuration to them.
2014-02-21 04:02:12 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Lennart Poettering 39883f622f make gcc shut up
If -flto is used then gcc will generate a lot more warnings than before,
among them a number of use-without-initialization warnings. Most of them
without are false positives, but let's make them go away, because it
doesn't really matter.
2014-02-19 17:53:50 +01:00
Lennart Poettering ac45f971a1 core: add Personality= option for units to set the personality for spawned processes 2014-02-19 03:27:03 +01:00
Lennart Poettering 6afc95b736 nspawn: add new --personality= switch to make it easier to run 32bit containers on a 64bit host 2014-02-18 23:37:27 +01:00
Lennart Poettering 3302da4667 nspawn: x86 is special with its socketcall() semantics, be permissive in the seccomp setup 2014-02-18 22:27:46 +01:00
Lennart Poettering e9642be2cc seccomp: add helper call to add all secondary archs to a seccomp filter
And make use of it where appropriate for executing services and for
nspawn.
2014-02-18 22:14:00 +01:00
Dave Reisner f3d5485b80 nspawn: allow 32-bit chroots from 64-bit hosts
Arch Linux uses nspawn as a container for building packages and needs
to be able to start a 32bit chroot from a 64bit host. 24fb111207
disrupted this feature when seccomp handling was added.
2014-02-18 21:26:24 +01:00
Tom Gundersen 4fb7242cbb sd-rtnl-message: store reference to the bus in the message
This mimics the sd-bus api, as we may need it in the future.
2014-02-18 11:21:22 +01:00
Lennart Poettering 37c47eb709 nspawn: netns_fd can be removed now 2014-02-17 15:49:21 +01:00
Thomas Hindoe Paaboel Andersen 32457153f4 nspawn: typo fix in help 2014-02-16 22:15:24 +01:00
Tom Gundersen ab046dde6f nspawn: add new --network-bridge= switch
This adds the host side of the veth link to the given bridge.

Also refactor the creation of the veth interfaces a bit to set it up
from the host rather than the container. This simplifies the addition
to the bridge, but otherwise the behavior is unchanged.
2014-02-16 21:40:28 +01:00
Tom Gundersen 818dc5e72a sd-rtnl: always include linux/rtnetlink.h 2014-02-15 12:14:45 +01:00
Tom Gundersen ee3a6a51e5 sd-rtnl: message_open_container - don't take a 'size' argument
We can always know the size based on the type, so let's do this inside the library.
2014-02-15 12:14:45 +01:00
Lennart Poettering 262d10e6bd nspawn: if we don't find bash, try sh 2014-02-14 16:41:03 +01:00
Lennart Poettering 6b9132a9c4 nspawn: don't accept just any tree to execute
When invoked without -D in an arbitrary directory we should not try to
execute anything, make some validity checks first.
2014-02-14 16:35:18 +01:00
Lennart Poettering 24fb111207 nspawn: make socket(AF_NETLINK, *, NETLINK_AUDIT) fail with EAFNOTSUPPORT in containers
The kernel still doesn't support audit in containers, so let's make use
of seccomp and simply turn it off entirely. We can get rid of this big
as soon as the kernel is fixed again.
2014-02-13 20:30:02 +01:00
Lennart Poettering 69c79d3c32 nspawn: add new --network-veth switch to add a virtual ethernet link to the host 2014-02-13 18:47:53 +01:00
Lennart Poettering 7e2270246b nspawn: check with udev before we take possession of an interface 2014-02-13 14:38:02 +01:00
Lennart Poettering b88eb17a7a nspawn: no need to subscribe to netlink messages if we just want to execute one operation 2014-02-13 14:08:16 +01:00
Lennart Poettering a42c8b54b1 nspawn: --private-network should imply CAP_NET_ADMIN 2014-02-13 14:07:59 +01:00
Lennart Poettering d595c5cc9e rtnl: rename constructors from the form sd_rtnl_xxx_yyy_new() to sd_rtnl_xxx_new_yyy()
So far we followed the rule to always indicate the "flavour" of
constructors after the "_new_" or "_open_" in the function name, so
let's keep things in sync here for rtnl and do the same.
2014-02-13 13:53:25 +01:00
Lennart Poettering cf6a891173 rtnl: drop "sd_" prefix from cleanup macros
The "sd_" prefix is supposed to be used on exported symbols only, and
not in the middle of names. Let's drop it from the cleanup macros hence,
to make things simpler.

The bus cleanup macros don't carry the "sd_" either, so this brings the
APIs a bit nearer.
2014-02-13 03:44:14 +01:00
Lennart Poettering aa28aefe61 nspawn: add new --network-interface= switch to move an existing interface into the container 2014-02-13 03:27:39 +01:00
Lennart Poettering 39ed67d146 nspawn: introduce --capability=all for retaining all capabilities 2014-02-13 02:45:11 +01:00
Lennart Poettering db999e0f92 nspawn: newer kernels (>= 3.14) allow resetting the audit loginuid, make use of this 2014-02-12 03:02:09 +01:00
Lennart Poettering 89f7c8465c machined: optionally, allow registration of pre-existing units (scopes
or services) as machine with machined
2014-02-11 17:16:08 +01:00
Lennart Poettering eb91eb187b nspawn: add --register=yes|no switch to optionally disable registration of the container with machined 2014-02-11 17:16:07 +01:00
Lennart Poettering 8a96d94e4c nspawn: add new --share-system switch to run a container without PID/UTS/IPC namespacing 2014-02-10 13:18:16 +01:00
Lennart Poettering 82adf6af7c nspawn,man: use a common vocabulary when referring to selinux security contexts
Let's always call the security labels the same way:

  SMACK: "Smack Label"
  SELINUX: "SELinux Security Context"

And the low-level encapsulation is called "seclabel". Now let's hope we
stick to this vocabulary in future, too, and don't mix "label"s and
"security contexts" and so on wildly.
2014-02-10 13:18:16 +01:00
Vincent Batts fcf90586a2 nspawn: require /etc/os-release only for init
/etc/os-release is expected for the case for booting a full system, and
need not be required for thin container execution.
2014-02-10 11:57:53 +01:00
Lennart Poettering ba978d7b32 nspawn: rename --file-label to --apifs-label since it's really just about the API file systems, nothing else 2014-02-07 19:29:28 +01:00
Tom Gundersen 5d63309cf5 nspawn: fix HAVE_SELINUX ifdef 2014-02-06 17:30:01 +01:00