Commit graph

522 commits

Author SHA1 Message Date
Lennart Poettering 5954c07433 cgroup: do not allow manipulating the cgroup path of units within the systemd:/system subtree 2013-04-30 08:36:01 -03:00
Lennart Poettering aa96c6cb44 id128: when taking user input for a 128bit ID, validate syntax
Also, always accept both our simple hexdump syntax and UUID syntax.
2013-04-30 08:36:01 -03:00
Zbigniew Jędrzejewski-Szmek 2a371001f8 Use attribute(unused) in PROTECT_ERRNO
clang emits warnings about unused attribute _saved_errno_, which drown
out other—potentially useful—warnings. gcc documentation is not exactly
verbose about the effects of __attribute__((unused)) on variables, but
let's assume that it works if the unit test passes.
2013-04-25 21:50:48 -04:00
Cristian Rodríguez b1e2b33c52 Add some extra __attribute__ ((format)) s 2013-04-25 21:50:48 -04:00
Zbigniew Jędrzejewski-Szmek 750ef27274 Make up for attribute malloc with alloc_size
It is imperative that open source code be well attributed.
Sprinkle attribute((alloc_size)) here and there, telling gcc
how much memory we are actually allocating.
2013-04-25 21:50:48 -04:00
Zbigniew Jędrzejewski-Szmek b231b54780 Remove erroneous attribute((malloc)) annotations
According to gcc documentation, returned pointer "cannot alias any
other pointer valid when the function returns" and "the memory has
undefined content". This second part is (hopefully) untrue for all
those functions.
2013-04-25 21:28:05 -04:00
Kay Sievers 67fb4482ac always unconditionally create /dev/rtc and use it internally
Partially revert 2b3c81b02f, which
tried to avoid inconsistent rules about when and how to create the
/dev/rtc symlink.

Instead of conditionally or not creating the /dev/rtc link at all,
now always create it with additional and more reliable udev rules.

First try to find the "system rtc" with the hctosys flag, if this
is not found, fall back to create the link for /dev/rtc0.

Our code now never actively searches for the "system rtc" it can
always use /dev/rtc.
2013-04-26 01:11:52 +02:00
Lennart Poettering d6dd604b55 util: rework safe_atod() to be locale-independent
This adds some syntactic sugar with a macro RUN_WITH_LOCALE() that reset
the thread-specific locale temporarily.
2013-04-25 00:05:14 -03:00
Lennart Poettering db5c012285 conf-parser: restrict .include usage
Disallow recursive .include, and make it unavailable in anything but
unit files.
2013-04-25 00:05:14 -03:00
Lennart Poettering 78edb35ab4 cgroup: always validate cgroup controller names
Let's better be safe than sorry.
2013-04-24 19:02:13 -03:00
Lennart Poettering 2b77f67e78 fileio: unify how we chop off whitespace from key and value in parse_env_file_internal() 2013-04-24 19:02:13 -03:00
Kay Sievers 2b3c81b02f do not create /dev/rtc symlink, let systemd search for it if needed
The export of the RTCs hctosys flag is uneccesary, the kernel takes care
of the persistemt clock management itself, without any need for:
  CONFIG_RTC_HCTOSYS=y
  CONFIG_RTC_HCTOSYS_DEVICE="rtc0"

"Chaotic hardware platforms" without native kernel persistent clock
support will find the proper RTC with the logic rtc_open() without
the need for a custom symlink.
2013-04-24 19:20:51 +02:00
Zbigniew Jędrzejewski-Szmek ef42202ac8 Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
2013-04-24 00:25:04 -04:00
Lennart Poettering ae018d9bc9 cgroup: make sure all our cgroup objects have a suffix and are properly escaped
Session objects will now get the .session suffix, user objects the .user
suffix, nspawn containers the .nspawn suffix.

This also changes the user cgroups to be named after the numeric UID
rather than the username, since this allows us the parse these paths
standalone without requiring access to the cgroup file system.

This also changes the mapping of instanced units to cgroups. Instead of
mapping foo@bar.service to the cgroup path /user/foo@.service/bar we
will now map it to /user/foo@.service/foo@bar.service, in order to
ensure that all our objects are properly suffixed in the tree.
2013-04-22 23:14:12 -03:00
Lennart Poettering aff38e74bd nspawn: suffix the nspawn cgroups with ".nspawn"
As discussed with Dan Berrange it's a good idea to suffix all objects in
the cgroup tree with ".something", so that when the system is
partitioned using a resource management tool we can drop objects of
different types into the same partition directory without generate
namespace conflicts.

We'l add this to the Pax Control Group document as soon as write access
to the fdo wiki is restored.
2013-04-22 23:14:12 -03:00
Zbigniew Jędrzejewski-Szmek 31885cd5e3 core/killall: use procfs_file_alloca 2013-04-19 10:10:41 -04:00
Harald Hoyer bdd29249a8 Reintroduce f_type comparison macro
This reverts commit 4826f0b7b5.

Because statfs.t_type can be int on some architecures, we have to cast
the const magic to the type, otherwise the compiler warns about
signed/unsigned comparison, because the magic can be 32 bit unsigned.

statfs(2) man page is also wrong on some systems, because
f_type is not __SWORD_TYPE on some architecures.

The following program:

int main(int argc, char**argv)
{
        struct statfs s;
        statfs(argv[1], &s);

	printf("sizeof(f_type) = %d\n", sizeof(s.f_type));
	printf("sizeof(__SWORD_TYPE) = %d\n", sizeof(__SWORD_TYPE));
	printf("sizeof(long) = %d\n", sizeof(long));
	printf("sizeof(int) = %d\n", sizeof(int));
	if (sizeof(s.f_type) == sizeof(int)) {
		printf("f_type = 0x%x\n", s.f_type);
	} else {
                printf("f_type = 0x%lx\n", s.f_type);
	}
        return 0;
}

executed on s390x gives for a btrfs:

sizeof(f_type) = 4
sizeof(__SWORD_TYPE) = 8
sizeof(long) = 8
sizeof(int) = 4
f_type = 0x9123683e
2013-04-19 13:59:07 +02:00
Harald Hoyer 4826f0b7b5 Revert f_type fixups
This reverts commit a858b64ddd.
This reverts commit aea275c431.
This reverts commit fc6e6d245e.
This reverts commit c4073a27c5.
This reverts commit cddf148028.
This reverts commit 8c68a70170.

The constants are now casted to __SWORD_TYPE, which should resolve the
compiler warnings about signed vs unsigned.

After talking to Kay, we concluded:

This should be fixed in the kernel, not worked around in userspace tools.

Architectures cannot use int and expect magic constants lager than INT_MAX
to work correctly. The kernel header needs to be fixed.

Even coreutils cannot handle it:
  #define RAMFS_MAGIC  0x858458f6
  # stat -f -c%t /
  ffffffff858458f6

  #define BTRFS_SUPER_MAGIC 0x9123683E
  # stat -f -c%t /mnt
  ffffffff9123683e

Although I found the perfect working macro to fix the thing :)

        __extension__ ({                                                \
                        bool _ret = false;                              \
                        switch(f) { case c: _ret=true; };               \
                        ( _ret );                                       \
                })
2013-04-18 15:01:55 +02:00
Harald Hoyer a858b64ddd macro.h: let F_TYPE_CMP() macro fail to compile, if second parameter is not const
If the magic parameter is not a const, then the macro does not work, so
better fail to compile, than be surprised afterwards.
2013-04-18 12:05:41 +02:00
Harald Hoyer 98f59e59e0 fileio.c: do not parse comments after non-whitespace chars
systemd does not want to understand comments after the first
non-whitespace char occured.

key=foo #comment  will result into key == "foo #comment"
key="foo" #comment  will result into key == "foo#comment"
"key= #comment" will result into key == "#comment"
"key #comment" is an invalid line
2013-04-18 11:29:00 +02:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Harald Hoyer aea275c431 rename CMP_F_TYPE to F_TYPE_CMP 2013-04-18 08:06:55 +02:00
Harald Hoyer fc6e6d245e Add ugly CMP_F_TYPE() macro
On some architectures (like s390x) the kernel has the type int for
f_type, but long in userspace.
Assigning the 32 bit magic constants from linux/magic.h to the 31 bit
signed f_type in the kernel, causes f_type to be negative for some
constants.
glibc extends the int to long for those architecures in 64 bit mode, so
the negative int becomes a negative long, which cannot be simply
compared to the original magic constant, because the compiler would
automatically cast the constant to long.
To workaround this issue, we also compare to the (int)MAGIC value in a
macro. Of course, we could do #ifdef with the architecure, but it has to
be maintained, and the magic constants are 32 bit anyway.

Someday, when the int is unsigned or long for all architectures, we can
remove this macro again. Until then, keep it as simple as it can be.
2013-04-18 07:34:25 +02:00
Simon Peeters 449101fce2 Move bus_error to dbus-common and remove bus_error_message_or_strerror
bus_error and bus_error_message_or_strerror dit almost exactly the same,
so use only one of them and place it in dbus-common.
2013-04-18 02:54:58 +02:00
Harald Hoyer c4073a27c5 fixup for cddf148028
Instead of making a type up, just use __SWORD_TYPE, after reading
statfs(2).

Too bad, this does not fix s390x because __SWORD_TYPE is (long int) and
the kernel uses (int) to fill in the field!!!!!!
2013-04-17 19:00:50 +02:00
Harald Hoyer cddf148028 fixup 8c68a7017 and cast to (unsigned long) 2013-04-17 18:23:17 +02:00
Harald Hoyer 8c68a70170 fixed statfs.f_type signed vs unsigned comparisons
statfs.f_type is signed but the filesystem magics are unsigned.
Casting the magics to signed will not make the signed.

Problem seen on big-endian 64bit s390x with __fsword_t 8 bytes.

Casting statfs.f_type to unsigned on the other hand will get us what we
need.

https://bugzilla.redhat.com/show_bug.cgi?id=953217
2013-04-17 18:14:25 +02:00
Harald Hoyer ebc05a09ad core/execute: report invalid environment variables from files
Because "export key=val" is not supported by systemd, an error is logged
where the invalid assignment is coming from.

Introduce strv_env_clean_log() to log invalid environment assignments,
where logging is possible and allowed.

parse_env_file_internal() is modified to allow WHITESPACE in keys, to
report the issues later on.
2013-04-17 15:31:45 +02:00
Harald Hoyer db53720916 fileio:parse_env_file_internal() fix environment file parsing
parse_env_file_internal() could not parse the following lines correctly:

export key="val"
key="val"#comment
2013-04-17 11:06:25 +02:00
Mantas Mikulėnas ced2d10a28 fileio: also escape $ and ` when writing out env vars
These are also considered special by sh and bash.
2013-04-17 00:32:02 -04:00
Zbigniew Jędrzejewski-Szmek 44df3e637f systemd: ignore hw timestamps in containers
They are irrelevant and misleading.

E.g. systemd-analyze:

  Startup finished in 6d 4h 15min 32.330s (kernel) + 49ms 914us (userspace) = 6d 4h 15min 32.380s

becomes

Startup finished in 53.735ms (userspace) = 53.735ms

which looks much better :)
2013-04-17 00:09:16 -04:00
Zbigniew Jędrzejewski-Szmek 543295ad36 core/main: use _cleanup_ 2013-04-17 00:09:16 -04:00
Zbigniew Jędrzejewski-Szmek e8e581bf25 Report about syntax errors with metadata
The information about the unit for which files are being parsed
is passed all the way down. This way messages land in the journal
with proper UNIT=... or USER_UNIT=... attribution.

'systemctl status' and 'journalctl -u' not displaying those messages
has been a source of confusion for users, since the journal entry for
a misspelt setting was often logged quite a bit earlier than the
failure to start a unit.

Based-on-a-patch-by: Oleksii Shevchuk <alxchk@gmail.com>
2013-04-17 00:09:16 -04:00
Zbigniew Jędrzejewski-Szmek eb3491d9ab conf-parser: generate 7 parsing functions from a macro
Those functions were identical, apart from typos. Log message
is modified to contain the type of destination var (int, double,
...). I think this might make it easier to understand why a value
was rejected (e.g. a minus from an unsigned type).
2013-04-17 00:09:15 -04:00
Lennart Poettering 49aa47c7fb util: make generation of profcs PID paths nicer 2013-04-16 14:50:05 +02:00
Lennart Poettering 6606089752 path-util: unify code for detecting OS trees
This also makes sure we always detect an OS tree the same way, by
checking for /etc/os-release.
2013-04-16 05:47:04 +02:00
Lennart Poettering dfb33a9737 macro: rework how we define cleanup macros
There's now a generic _cleanup_ macro with an argument. The macros for
specific types are now defined using this macro, and in the header files
where they belong.

All cleanup handlers are now inline functions.
2013-04-16 05:25:57 +02:00
Lennart Poettering 82da66fb75 util: replace decimal_str_max() by a typesafe macro DECIMAL_STR_WIDTH()
DECIMAL_STR_WIDTH() now works on any numeric type, and is easier to
distingish from DECIMAL_STR_MAX().

This also replaces another manual implementaiton of ulog10 by this macro.
2013-04-16 05:04:53 +02:00
Lennart Poettering 7027ff61a3 nspawn: introduce the new /machine/ tree in the cgroup tree and move containers there
Containers will now carry a label (normally derived from the root
directory name, but configurable by the user), and the container's root
cgroup is /machine/<label>. This label is called "machine name", and can
cover both containers and VMs (as soon as libvirt also makes use of
/machine/).

libsystemd-login can be used to query the machine name from a process.

This patch also includes numerous clean-ups for the cgroup code.
2013-04-16 04:41:21 +02:00
Lennart Poettering cec4ead904 util: make sure result of hostname_cleanup() passes hostname_is_valid() 2013-04-16 04:41:21 +02:00
Lennart Poettering 9a3ef988b8 audit: since nspawn now sets CAP_AUDIT_CONTROL for containers we cannot user this anymore to skip audit session ID retrieval
As audit is still broken in containers we need a reliable way how we can
determine whether the audit data we read from 7proc is actually useful.
Previously we used CAP_AUDIT_CONTROL for this, since nspawn removed that
from the nspawn container. This has changed a while back however, which
means we used audit data of host system in the container.

This adds an explicit container check to the audit calls, so that all
audit data is turned off in containers.

This should fix session creation with pam_systemd/logind in nspawn containers.
2013-04-15 21:59:04 +02:00
Lennart Poettering a32360f1a5 core: always create /user and /machine top-level cgroup dirs
This allows clients to put inotify watches on these trees to watch for
state changes, without having to wait until these dirs are created.

This introduces the new top-level /machine cgroup dir as canonical
location where OS containers and VMs shall be located (as discussed with
the libvirt folks).
2013-04-15 21:59:04 +02:00
Harald Hoyer fee79e010f do not change console to non-unicode for LANG=C
If systemd-vconsole-setup was started with LANG=C (no locale.conf), then
it would set the console to non-unicode, which is not what we want.
2013-04-15 18:37:24 +02:00
Anatol Pomozov ab06eef810 Fix spelling errors using 'codespell' tool 2013-04-15 08:40:05 -04:00
Lennart Poettering 6c03089c32 bus: handle env vars safely
Make sure that our library is safe for usage in SUID programs when it
comes to env var handling
2013-04-15 14:05:03 +02:00
Zbigniew Jędrzejewski-Szmek 4094bcbfac MurmurHash3: actually inline functions
"__attribute__((always_inline))" does not replace "inline" and they
still need to be used together. This fixes "always_inline function
might not be inlinable [-Wattributes]" warning in gcc 4.7

Idea-from-patch-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2013-04-14 13:11:06 -04:00
Lennart Poettering a56f19c4f9 kdbus: generare bloom filters properly for messages we send 2013-04-14 17:49:18 +02:00
Lennart Poettering ed5c5dbde1 util: introduce alloca0() and use it at a number of places 2013-04-14 17:43:59 +02:00
Zbigniew Jędrzejewski-Szmek d3b6d0c21e fileio: in envfiles, do not skip lines following empty lines
https://bugs.freedesktop.org/show_bug.cgi?id=63477
2013-04-13 20:24:39 -04:00
Zbigniew Jędrzejewski-Szmek 7914d6bba4 Remove a few NULLs
Just {} is used in a lot of places now, and there's nothing
special abose those few.
2013-04-13 20:24:39 -04:00