Commit graph

987 commits

Author SHA1 Message Date
Tejun Heo 415fc41cea core: simplify cg_[all_]unified()
cg_[all_]unified() test whether a specific controller or all controllers are on
the unified hierarchy.  While what's being asked is a simple binary question,
the callers must assume that the functions may fail any time, which
unnecessarily complicates their usages.  This complication is unnecessary.
Internally, the test result is cached anyway and there are only a few places
where the test actually needs to be performed.

This patch simplifies cg_[all_]unified().

* cg_[all_]unified() are updated to return bool.  If the result can't be
  decided, assertion failure is triggered.  Error handlings from their callers
  are dropped.

* cg_unified_flush() is updated to calculate the new result synchrnously and
  return whether it succeeded or not.  Places which need to flush the test
  result are updated to test for failure.  This ensures that all the following
  cg_[all_]unified() tests succeed.

* Places which expected possible cg_[all_]unified() failures are updated to
  call and test cg_unified_flush() before calling cg_[all_]unified().  This
  includes functions used while setting up mounts during boot and
  manager_setup_cgroup().
2017-02-18 17:51:13 -05:00
Lennart Poettering 925c81cd20 missing: add renameat2() definition for 64bit arm (#5378)
Following a similar commit in casync:

https://github.com/systemd/casync/pull/10
2017-02-17 13:10:09 -05:00
Lennart Poettering e4363cd8ae Merge pull request #5333 from poettering/machined-copy-files-userns
machined userns fixes
2017-02-17 13:51:58 +01:00
Lennart Poettering d01cd40196 machined: when copying files from/to userns containers chown to root
This changes the file copy logic of machined to set the UID/GID of all
copied files to 0 if the host and container do not share the same user
namespace.

Fixes: #4078
2017-02-17 10:22:28 +01:00
Lennart Poettering 1c876927e4 copy: change the various copy_xyz() calls to take a unified flags parameter
This adds a unified "copy_flags" parameter to all copy_xyz() function
calls, replacing the various boolean flags so far used. This should make
many invocations more readable as it is clear what behaviour is
precisely requested. This also prepares ground for adding support for
more modes later on.
2017-02-17 10:22:28 +01:00
Lennart Poettering d91e8e1b69 hostname-util: default to the compile time default hostname in gethostname_malloc()
Currently, if the hostname is not set gethostname_malloc() defaults to
the "sysname", which is "linux" on Linux. Let's change that to also
honour the compile-time fallback hostname as specified on the configure
command line.
2017-02-17 10:19:26 +01:00
Benjamin Robin 2f8e375d17 virt: Update cache if the detected vm is virtualbox (#5364) 2017-02-17 08:45:30 +01:00
Lennart Poettering 2fe917fe91 Merge pull request #4526 from keszybz/coredump-python
Collect interpreter backtraces in systemd-coredump
2017-02-16 11:24:03 +01:00
Christian Hesse 28b1a3eac2 virt: swap order of cpuid and dmi again, but properly detect oracle (#5355)
This breaks again, this time for setups where Qemu is not reported via DMI for whatever
reason. So swap order of cpuid and dmi again, but properly detect oracle.

See issue #5318.
2017-02-15 17:51:31 -05:00
Zbigniew Jędrzejewski-Szmek 2b0445262a tree-wide: add SD_ID128_MAKE_STR, remove LOG_MESSAGE_ID
Embedding sd_id128_t's in constant strings was rather cumbersome. We had
SD_ID128_CONST_STR which returned a const char[], but it had two problems:
- it wasn't possible to statically concatanate this array with a normal string
- gcc wasn't really able to optimize this, and generated code to perform the
  "conversion" at runtime.
Because of this, even our own code in coredumpctl wasn't using
SD_ID128_CONST_STR.

Add a new macro to generate a constant string: SD_ID128_MAKE_STR.
It is not as elegant as SD_ID128_CONST_STR, because it requires a repetition
of the numbers, but in practice it is more convenient to use, and allows gcc
to generate smarter code:

$ size .libs/systemd{,-logind,-journald}{.old,}
   text	   data	    bss	    dec	    hex	filename
1265204	 149564	   4808	1419576	 15a938	.libs/systemd.old
1260268	 149564	   4808	1414640	 1595f0	.libs/systemd
 246805	  13852	    209	 260866	  3fb02	.libs/systemd-logind.old
 240973	  13852	    209	 255034	  3e43a	.libs/systemd-logind
 146839	   4984	     34	 151857	  25131	.libs/systemd-journald.old
 146391	   4984	     34	 151409	  24f71	.libs/systemd-journald

It is also much easier to check if a certain binary uses a certain MESSAGE_ID:

$ strings .libs/systemd.old|grep MESSAGE_ID
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x

$ strings .libs/systemd|grep MESSAGE_ID
MESSAGE_ID=c7a787079b354eaaa9e77b371893cd27
MESSAGE_ID=b07a249cd024414a82dd00cd181378ff
MESSAGE_ID=641257651c1b4ec9a8624d7a40a9e1e7
MESSAGE_ID=de5b426a63be47a7b6ac3eaac82e2f6f
MESSAGE_ID=d34d037fff1847e6ae669a370e694725
MESSAGE_ID=7d4958e842da4a758f6c1cdc7b36dcc5
MESSAGE_ID=1dee0369c7fc4736b7099b38ecb46ee7
MESSAGE_ID=39f53479d3a045ac8e11786248231fbf
MESSAGE_ID=be02cf6855d2428ba40df7e9d022f03d
MESSAGE_ID=7b05ebc668384222baa8881179cfda54
MESSAGE_ID=9d1aaa27d60140bd96365438aad20286
2017-02-15 00:45:12 -05:00
Zbigniew Jędrzejewski-Szmek b18453eda6 Move export format parsing from src/journal-remote/ to src/basic/
No functional change.
2017-02-14 23:56:48 -05:00
Christian Hesse 5f1c788ca9 virt: detect qemu/kvm as 'kvm'
In commit 050e65a we swapped order of detect_vm_{cpuid,dmi}(). That
fixed Virtualbox but broke qemu with kvm, which is expected to return
'kvm'. So check for qemu/kvm first, then DMI, CPUID last.

This fixes #5318.

Signed-off-by: Christian Hesse <mail@eworm.de>
2017-02-14 15:52:53 +01:00
Doug Christman 963e3d8373 calendarspec: fix duplicate detection (#5310)
a2eb5ea79c added a new field to `CalendarComponent`; update
`normalize_chain` to compare all fields when dropping duplicates
2017-02-12 00:39:17 -05:00
Zbigniew Jędrzejewski-Szmek 680a752c83 basic/architecture: adjust Risc-V ifdef (#5304)
https://lists.freedesktop.org/archives/systemd-devel/2017-February/038286.html

Let's keep both the old and new for now, so systemd builds correctly in either
environment. Later on we should drop the old.
2017-02-10 23:48:22 +01:00
Lennart Poettering ae9d60ce4e seccomp: on s390 the clone() parameters are reversed
Add a bit of code that tries to get the right parameter order in place
for some of the better known architectures, and skips
restrict_namespaces for other archs.

This also bypasses the test on archs where we don't know the right
order.

In this case I didn't bother with testing the case where no filter is
applied, since that is hopefully just an issue for now, as there's
nothing stopping us from supporting more archs, we just need to know
which order is right.

Fixes: #5241
2017-02-08 22:21:27 +01:00
Lennart Poettering b6f08ecda9 Merge pull request #5231 from keszybz/mask-wants
Mask individual .wants/.requires symlinks
2017-02-08 14:50:56 +01:00
Zbigniew Jędrzejewski-Szmek 5dd11ab5f3 basic/dirent-util: allow suffix to be omitted for dirent_is_file_with_suffix 2017-02-07 21:06:38 -05:00
Zbigniew Jędrzejewski-Szmek 2d26d8e07e treewide: replace homegrown memory_erase with explicit_bzero
explicit_bzero was added in glibc 2.25. Make use of it.

explicit_bzero is hardcoded to zero the memory, so string erase now
truncates the string, instead of overwriting it with 'x'. This causes
a visible difference only in the journalctl case.
2017-02-05 21:07:55 -05:00
Benjamin Robin d201d90838 time-util: Fix overflow check introduce in commit f977849 (#5216) 2017-02-03 16:13:55 +01:00
Lennart Poettering 315782db14 time-util: add overflow checking to monotonic timestamp specifications 2017-02-02 20:12:32 +01:00
Lennart Poettering 74c5b33b0a time-util: when formatting usec_t as raw integers use PRIu64
After all, usec_t is defined as uint64_t, and not as unsigned long long.
2017-02-02 20:12:31 +01:00
Lennart Poettering f977849c24 time-util: when converting to time_t do something useful in 2038
On systems where time_t is 32bit we should invalidate the
timeval/timespec instead of proceeding with a potentially overflown
value.
2017-02-02 20:12:31 +01:00
Lennart Poettering 1bb4b028a3 time-util: refuse formatting/parsing times that we can't store
usec_t is always 64bit, which means it can cover quite a number of
years. However, 4 digit year display and glibc limitations around time_t
limit what we can actually parse and format. Let's make this explicit,
so that we never end up formatting dates we can#t parse and vice versa.

Note that this is really just about formatting/parsing. Internal
calculations with times outside of the formattable range are not
affected.
2017-02-02 20:12:31 +01:00
Lennart Poettering c477ff141b time: time_t is signed, and mktime() is happy to return negative time
Passing a year such as 1960 to mktime() will result in a negative return
value. This is quite confusing, as the man page claims that on failure
the call will return -1...

Given that our own usec_t type is unsigned, and we can't express times
before 1970 hence, let's consider all negative times returned by
mktime() as invalid, regardless if just -1, or anything else negative.
2017-02-02 20:12:31 +01:00
Lennart Poettering 9ff233dc1f hexdecoct: use typesafe new() instead of malloc() 2017-02-02 00:10:44 +01:00
Lennart Poettering 49bfc8774b fs-util: unify code we use to check if dirent's d_name is "." or ".."
We use different idioms at different places. Let's replace this is the
one true new idiom, that is even a bit faster...
2017-02-02 00:06:18 +01:00
Evgeny Vereshchagin b5267219dd Merge pull request #5166 from keszybz/gcc7
Fixes for gcc 7 and new µhttpd & glibc warnings
2017-02-01 12:02:50 +03:00
Zbigniew Jędrzejewski-Szmek a38d90c672 Merge pull request #5146 from ssahani/ifname-alias
networkd: Allow ':' in label

This reverts a341dfe563 and takes a slightly different approach: anything is
allowed in network interface labels, but network interface names are verified
as before (i.e. amongst other things, no colons are allowed there).
2017-01-31 20:36:20 -05:00
Zbigniew Jędrzejewski-Szmek 6154d33de3 nss-util: silence warning about deprecated RES_USE_INET6
src/nss-resolve/nss-resolve.c: In function ‘_nss_resolve_gethostbyname_r’:
src/nss-resolve/nss-resolve.c:680:13: warning: RES_USE_INET6 is deprecated
 NSS_GETHOSTBYNAME_FALLBACKS(resolve);
             ^~~~~~~~~~~~~~~~~~~~~~~~~

In glibc bz #19582, RES_USE_INET6 was deprecated. This might make sense for
clients, but they didn't take into account nss module implementations which
*must* continue to support the option. glibc internally defines
DEPRECATED_RES_USE_INET6 which can be used without emitting a warning, but
it's not exported publicly. Let's do the same, and just copy the definition
to our header.
2017-01-31 19:55:33 -05:00
Zbigniew Jędrzejewski-Szmek 2c5248e245 MurmurHash: all /* fall through */ comments 2017-01-31 19:35:04 -05:00
Zbigniew Jędrzejewski-Szmek ec251fe7d5 tree-wide: adjust fall through comments so that gcc is happy
gcc 7 adds -Wimplicit-fallthrough=3 to -Wextra. There are a few ways
we could deal with that. After we take into account the need to stay compatible
with older versions of the compiler (and other compilers), I don't think adding
__attribute__((fallthrough)), even as a macro, is worth the trouble. It sticks
out too much, a comment is just as good. But gcc has some very specific
requiremnts how the comment should look. Adjust it the specific form that it
likes. I don't think the extra stuff we had in those comments was adding much
value.

(Note: the documentation seems to be wrong, and seems to describe a different
pattern from the one that is actually used. I guess either the docs or the code
will have to change before gcc 7 is finalized.)
2017-01-31 14:04:55 -05:00
3chas3 877777d776 util-lib: Fix chase_symlinks() with absolute symlinks (#5185)
If chase_symlinks() encouters an absolute symlink, it resets the todo
buffer to just the newly discovered symlink and discards any of the
remaining previous symlink path.  Regardless of whether or not the
symlink is absolute or relative, we need to preserve the remainder of
the path that has not yet been resolved.
2017-01-31 16:21:15 +03:00
Evgeny Vereshchagin ef1fd941f9 basic: check strdup result in khash_dup (#5176)
Fixes CID #1368249
2017-01-31 08:27:14 +01:00
Stefan Schweter 1a012455c2 tree-wide: remove consecutive duplicate words in comments (#5148) 2017-01-24 21:45:30 -05:00
Stefan Schweter ff85f271ca virt: update url to hypervisor top-level functional specification (#5149) 2017-01-24 21:44:59 -05:00
Susant Sahani 7ed95830dc socket-utils: revert f1811313f42dc7ddaed3c47edc834c2bfd1309b2
':' in not a a valid interface name.
2017-01-24 23:54:34 +05:30
peoronoob a341dfe563 network: accept colons in network interface names, normally used for alias interfaces (#5117) 2017-01-23 22:26:41 -05:00
Zbigniew Jędrzejewski-Szmek c05347807f process-util: rename char *r to ans and add comment
Add a comment about the return value and rename r to ans. r is
nowadays reserved for the integer return value, and char *r is confusing.
2017-01-15 12:41:34 -05:00
Zbigniew Jędrzejewski-Szmek 6b3d378331 Merge pull request #4879 from poettering/systemd 2017-01-14 21:29:27 -05:00
Zbigniew Jędrzejewski-Szmek 69dc692252 socket-util: drop _pure_ from a function with an output parameter
If it writes to memory, it's not pure, by definition.
Fixup for 882ac6e769.
2017-01-11 16:37:34 -05:00
Lennart Poettering 84e6712f94 Merge pull request #5046 from stefanha/vsock
Add AF_VSOCK socket activation support
2017-01-11 10:53:59 +01:00
Lubomir Rintel dc66f33a16 sparse: avoid clash with __bitwise and __force from 4.10 linux/types.h (#5061)
It also used __bitwise and __force. It seems easier to rename
our versions since they are local to this one single header.

Also, undefine them afteerwards, so that we don't pollute the
preprocessor macro namespace.
2017-01-11 10:50:25 +01:00
Stefan Hajnoczi 0fc0f14bfd socket-util: add AF_VSOCK address family
The AF_VSOCK address family facilitates guest<->host communication on
VMware and KVM (virtio-vsock).  Adding support to systemd allows guest
agents to be launched through .socket unit files.  Today guest agents
are stand-alone daemons running inside guests that do not take advantage
of systemd socket activation.
2017-01-10 15:29:04 +00:00
Stefan Hajnoczi 882ac6e769 socket-util: introduce port argument in sockaddr_port()
sockaddr_port() either returns a >= 0 port number or a negative errno.
This works for AF_INET and AF_INET6 because port ranges are only 16-bit.

In AF_VSOCK ports are 32-bit so an int cannot represent all port number
and negative errnos.  Separate the port and the return code.
2017-01-10 15:29:04 +00:00
Stefan Hajnoczi 4e0399e69b missing.h: add AF_VSOCK bits
Ubuntu 14.04 (Trusty) kernel header packages ship without
<linux/vm_sockets.h>.  Only struct sockaddr_vm and VMADDR_CID_ANY will
be needed by systemd and they are simple enough to go in missing.h.

CentOS 7 <sys/socket.h> does not define AF_VSOCK.  Define it so the code
can compile although actual socket(2) calls may fail at runtime if the
address family isn't available.
2017-01-10 15:27:00 +00:00
Mike Gilbert c9f7b4d356 build-sys: add check for gperf lookup function signature (#5055)
gperf-3.1 generates lookup functions that take a size_t length
parameter instead of unsigned int. Test for this at configure time.

Fixes: https://github.com/systemd/systemd/issues/5039
2017-01-10 08:39:05 +01:00
Martin Pitt 56a9366d7d Merge pull request #4994 from poettering/private-tmp-tmpfiles
automatically clean up PrivateTmp= left-overs in /var/tmp on next boot
2016-12-29 11:18:38 +01:00
Lennart Poettering d71f050599 core: implicitly order units with PrivateTmp= after systemd-tmpfiles-setup.service
Preparation for fixing #4401.
2016-12-27 23:25:24 +01:00
Lennart Poettering 1429dfe5f8 util-lib: add a comment explaining the user name rules we enforce 2016-12-27 18:09:58 +01:00
Lennart Poettering 436e916eae util-lib: rework path_check_fstype() and path_is_temporary_fs() to use O_PATH
Also, add tests to make sure this actually works as intended.
2016-12-21 19:09:32 +01:00