Commit graph

641 commits

Author SHA1 Message Date
Lennart Poettering fecffe5d0a util: add macro for iterating through all prefixes of a path
Syntactic sugar in a macro PATH_FOREACH_PREFIX.
2013-09-25 21:04:35 +02:00
Lennart Poettering 13b84ec7df cgroup: if we do a cgroup operation then do something on all supported controllers
Previously we did operations like attach, trim or migrate only on the
controllers that were enabled for a specific unit. With this changes we
will now do them for all supproted controllers, and fall back to all
possible prefix paths if the specified paths do not exist.

This fixes issues if a controller is being disabled for a unit where it
was previously enabled, and makes sure that all processes stay as "far
down" the tree as groups exist.
2013-09-25 03:38:17 +02:00
Kay Sievers c51d84dc09 support acpi firmware performance data (FPDT)
Prefer firmware-provided performance data over loader-exported ones; if
ACPI data is available, always use it, otherwise try to read the loader
data.

The firmware-provided variables start at the time the first EFI image
is executed and end when the operating system exits the boot services;
the (loader) time calculated in systemd-analyze increases.
2013-09-24 15:43:41 +02:00
Kay Sievers 036ae95ac4 shared: device-nodes - add include guard 2013-09-24 15:34:57 +02:00
Zbigniew Jędrzejewski-Szmek 1e5413f74f Add more tests and fix capability logging 2013-09-19 16:22:59 -05:00
Dave Reisner 8f6ce71fe7 device-nodes: move device node specific code to own file
In the process, rename udev_encode_string which is poorly named for what
it does. It deals specifically with encoding names that udev creates and
has its own rules: utf8 is valid but some ascii is not (e.g. path
separators), and everything else is simply escaped. Rename it to
encode_devnode_name.
2013-09-19 11:50:34 -04:00
Dave Reisner 7991ac34ab shared/utf8: merge implementations, remove cruft
This unifies the utf8 handling code which was previously duplicated in
udev and systemd.
2013-09-19 11:49:03 -04:00
David Strauss c22428fb73 Spelling fix from later revision of committed patch from Shawn Landden <shawn@churchofgit.com>. 2013-09-18 15:46:51 -05:00
Zbigniew Jędrzejewski-Szmek 4ec29144dd Fix capability logging when effective caps are 0
Shawn Landen> Doesn't this also skip the last '0' when it is all '0's?
              You need to keep the last one.
2013-09-18 11:43:29 -05:00
Colin Walters 72fd713962 polkit: Avoid race condition in scraping /proc
If a calling process execve()s a setuid program, it can appear to be
uid 0.  Since we're receiving requests over DBus, avoid this by simply
passing system-bus-name as a subject.
2013-09-18 11:06:04 -05:00
Zbigniew Jędrzejewski-Szmek 00f117a599 logs-show.c: fix enum type in function declaration 2013-09-18 11:00:51 -05:00
Zbigniew Jędrzejewski-Szmek 0a7b53bdd2 util: restore get_process_capeff behaviour
69ab8088 unified parsing of status files and removed the logic of
skipping extra '0's when getting the effective capabilities. Restore
that logic, so that the same capabilities are always mapped to the
same strings in the journal.
2013-09-17 18:37:32 -05:00
David Herrmann 118ecf3242 logind: introduce session-devices
A session-device is a device that is bound to a seat and used by a
session-controller to run the session. This currently includes DRM, fbdev
and evdev devices. A session-device can be created via RequestDevice() on
the dbus API of the session. You can drop it via ReleaseDevice() again.
Once the session is destroyed or you drop control of the session, all
session-devices are automatically destroyed.

Session devices follow the session "active" state. A device can be
active/running or inactive/paused. Whenever a session is not the active
session, no session-device of it can be active. That is, if a session is
not in foreground, all session-devices are paused.
Whenever a session becomes active, all devices are resumed/activated by
logind. If it fails, a device may stay paused.

With every session-device you request, you also get a file-descriptor
back. logind keeps a copy of this fd and uses kernel specific calls to
pause/resume the file-descriptors. For example, a DRM fd is muted
by logind as long as a given session is not active. Hence, the fd of the
application is also muted. Once the session gets active, logind unmutes
the fd and the application will get DRM access again.
This, however, requires kernel support. DRM devices provide DRM-Master for
synchronization, evdev devices have EVIOCREVOKE (pending on
linux-input-ML). fbdev devices do not provide such synchronization methods
(and never will).
Note that for evdev devices, we call EVIOCREVOKE once a session gets
inactive. However, this cannot be undone (the fd is still valid but mostly
unusable). So we reopen a new fd once the session is activated and send it
together with the ResumeDevice() signal.

With this infrastructure in place, compositors can now run without
CAP_SYS_ADMIN (that is, without being root). They use RequestControl() to
acquire a session and listen for devices via udev_monitor. For every
device they want to open, they call RequestDevice() on logind. This
returns a fd which they can use now. They no longer have to open the
devices themselves or call any privileged ioctls. This is all done by
logind.
Session-switches are still bound to VTs. Hence, compositors will get
notified via the usual VT mechanisms and can cleanup their state. Once the
VT switch is acknowledged as usual, logind will get notified via sysfs and
pause the old-session's devices and resume the devices of the new session.

To allow using this infrastructure with systems without VTs, we provide
notification signals. logind sends PauseDevice("force") dbus signals to
the current session controller for every device that it pauses. And it
sends ResumeDevice signals for every device that it resumes. For
seats with VTs this is sent _after_ the VT switch is acknowledged. Because
the compositor already acknowledged that it cleaned-up all devices.
However, for seats without VTs, this is used to notify the active
compositor that the session is about to be deactivated. That is, logind
sends PauseDevice("force") for each active device and then performs the
session-switch. The session-switch changes the "Active" property of the
session which can be monitored by the compositor. The new session is
activated and the ResumeDevice events are sent.

For seats without VTs, this is a forced session-switch. As this is not
backwards-compatible (xserver actually crashes, weston drops the related
devices, ..) we also provide an acknowledged session-switch. Note that
this is never used for sessions with VTs. You use the acknowledged
VT-switch on these seats.

An acknowledged session switch sends PauseDevice("pause") instead of
PauseDevice("force") to the active session. It schedules a short timeout
and waits for the session to acknowledge each of them with
PauseDeviceComplete(). Once all are acknowledged, or the session ran out
of time, a PauseDevice("force") is sent for all remaining active devices
and the session switch is performed.
Note that this is only partially implemented, yet, as we don't allow
multi-session without VTs, yet. A follow up commit will hook it up and
implemented the acknowledgements+timeout.

The implementation is quite simple. We use major/minor exclusively to
identify devices on the bus. On RequestDevice() we retrieve the
udev_device from the major/minor and search for an existing "Device"
object. If no exists, we create it. This guarantees us that we are
notified whenever the device changes seats or is removed.

We create a new SessionDevice object and link it to the related Session
and Device. Session->devices is a hashtable to lookup SessionDevice
objects via major/minor. Device->session_devices is a linked list so we
can release all linked session-devices once a device vanishes.

Now we only have to hook this up in seat_set_active() so we correctly
change device states during session-switches. As mentioned earlier, these
are forced state-changes as VTs are currently used exclusively for
multi-session implementations.

Everything else are hooks to release all session-devices once the
controller changes or a session is closed or removed.
2013-09-17 17:15:30 -05:00
Zbigniew Jędrzejewski-Szmek 9fb3675e7e Use first partition in /proc/swaps for hibernation test
It seems that the kernel uses the first configured partition
for hibernation. If it is too full, hibernation will fail. Test
that directly.
2013-09-17 16:44:38 -04:00
Dave Reisner 22f5f6281f Use udev_encode_string in fstab_node_to_udev_node
Resolves a longstanding bug which caused this function to wrongly
handle (escape) valid utf8 characters.
2013-09-17 16:31:32 -04:00
Dave Reisner 02a36bc9a1 move utf8 functions from libudev-private.h to utf8.h
There's now some more obvious overlap amongst the two utf8 validation
functions, but no more than there already was previously.

This also adds some menial tests for anyone who wants to do more
merging of these two in the future.
2013-09-17 16:31:32 -04:00
Lennart Poettering 19f6d71077 specifier: rework specifier calls to return proper error message
Previously the specifier calls could only indicate OOM by returning
NULL. With this change they will return negative errno-style error codes
like everything else.
2013-09-17 10:06:50 -05:00
Zbigniew Jędrzejewski-Szmek 4b549144d8 Verify validity of session name when received from outside
Only ASCII letters and digits are allowed.
2013-09-16 09:58:37 -05:00
Zbigniew Jędrzejewski-Szmek 442e00839e Assume that /proc/meminfo can be missing
Travis tests are failing, probably because /proc/meminfo is not available
in the test environment. The same might be true in some virtualized systems,
so just treat missing /proc/meminfo as a sign that hibernation is not
possible.
2013-09-16 09:47:28 -05:00
Zbigniew Jędrzejewski-Szmek 69ab808815 Advertise hibernation only if there's enough free swap
Condition that is checked is taken from upower:
  active(anon) < free swap * 0.98

This is really stupid, because the kernel knows the situation better,
e.g. there could be two swap files, and then hibernation would be
impossible despite passing this check, or the kernel could start
supporting compressed swap and/or compressed hibernation images, and
then this this check would be too stringent. Nevertheless, until
we have something better, this should at least return a true negative
if there's no swap.

Logging of capabilities in the journal is changed to not strip leading
zeros. I consider this more readable anyway.

http://cgit.freedesktop.org/upower/tree/src/up-daemon.c#n613
https://bugzilla.redhat.com/show_bug.cgi?id=1007059
2013-09-13 19:41:52 -04:00
Zbigniew Jędrzejewski-Szmek da2620a5f8 Actually allow tabs in environment files
Fixup for ac4c8d6da8.
2013-09-12 10:03:16 -04:00
Zbigniew Jędrzejewski-Szmek ac4c8d6da8 Allow tabs in environment files
bash allows them, and so should we.

string_has_cc is changed to allow tabs, and if they are not wanted,
they must be now checked for explicitly. There are two other callers,
apart from the env file loaders, and one already checked anyway, and
the other is changed to check.

https://bugs.freedesktop.org/show_bug.cgi?id=68592
https://bugs.gentoo.org/show_bug.cgi?id=481554
2013-09-11 21:58:22 -04:00
Zbigniew Jędrzejewski-Szmek 4bcc8c3cb5 Fix two compiler warnings 2013-09-09 17:35:52 -04:00
Zbigniew Jędrzejewski-Szmek c9d954b27e run: allow non-absolute paths as command 2013-09-09 13:49:30 -04:00
Zbigniew Jędrzejewski-Szmek 116cc02874 path-util.c: small modernization 2013-09-09 13:49:30 -04:00
Zbigniew Jędrzejewski-Szmek a6fde35332 systemd-run: properly escape arguments
Spaces, quotes, and such, were not properly escaped. We should
write them like we read them.

https://bugs.freedesktop.org/show_bug.cgi?id=67971
2013-09-09 13:49:29 -04:00
Zbigniew Jędrzejewski-Szmek 335c46b598 Disallow invalid UTF-8 configuration
It is best to catch such errors early. If invalid UTF-8 ends up being
given to dbus methods, the program will crash:

process 20801: arguments to dbus_message_iter_append_basic() were incorrect, assertion "_dbus_check_is_valid_utf8 (*string_p)" failed in file dbus-message.c line 2598.
2013-08-28 08:04:56 -04:00
Maciej Wereski ea92ae33e0 "-" prefix for InaccessibleDirectories and ReadOnlyDirectories 2013-08-23 12:48:14 -04:00
Kay Sievers df89481a35 Optimize startswith() to macro
I guess it's easier and cleaner anyway to use simple static inline
functions instead of defines.
2013-08-22 00:52:14 -04:00
Shawn Landden 2a0e069256 remove hasprefix(), use startswith() 2013-08-22 00:52:14 -04:00
Zbigniew Jędrzejewski-Szmek 2526d62691 logs-show: fix condition for ellipsizing multi-line messages
falconindy> the ellipsizing seems a bit wrong here....

I got a bit carried away with putting dots everywhere :)
2013-08-21 01:36:51 -04:00
Zbigniew Jędrzejewski-Szmek cf40f0be1a logs-show: show source timestamp in verbose mode
This makes verbose behave like short mode, i.e. try to show
the source timestamp, and fall back to journald timestamp
only if unavailable or unparsable. I think verbose should
be like short, only showing more fields, and showing different
timestamps would be confusing.
2013-08-20 21:18:44 -04:00
Zbigniew Jędrzejewski-Szmek f02d836794 logs-show: add short-precise mode with us timestamps
Also, always show us timestamps in verbose mode.

https://bugzilla.redhat.com/show_bug.cgi?id=991678
2013-08-20 21:18:43 -04:00
Zbigniew Jędrzejewski-Szmek c51cf05646 Rename F_TYPE_CMP() to F_TYPE_EQUAL() 2013-08-20 21:18:43 -04:00
Michael Marineau 4b357e1587 build-sys: Add configure check for linux/btrfs.h
btrfs.h was added to uapi in Linux 3.9. To fix building with older
header versions this adds a configure check for the header and re-adds
btrfs definitions to missing.h which was removed in bed2e820 along with
two other ioctls used by gpt-auto-generator.

[ Apparently, btrfs.h was only added recently:
  http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=55e301fd57a6239ec14b91a1cf2e70b3dd135194
  let's re-add it for now -- kay ]
2013-08-16 23:29:41 +02:00
Kay Sievers 585275000c hashmap: remove empty lines 2013-08-15 17:51:02 +02:00
Lennart Poettering bed2e820db missing: use btrfs.h instead of defining our own btrfs structures 2013-08-13 10:12:35 +02:00
Zbigniew Jędrzejewski-Szmek a6f0104a16 logs-show: limit to 3 lines and use dots if not showing full message
So far, we would show up to 128 bytes from a message, simply
cutting of the rest. With multiline messages, it is quite common
for a message to be longer than that, and this model doesn't really
work anymore.

A new limit is added: up to 3 lines will be shown, unless --full is
used (c.f. first line below).  The limit for bytes is extended to 300
bytes. An ellipsis will always be used, if some form of truncation
occurs. If the tail of the message is cut off, either because of
length or line limit, dots will be shown at the end of the last
line. If this last line is short, the dots will be simply appended. If
the last line is too long for that, it will be ellipsized with dots at
the very end.

Note that the limits are in bytes, not characters, and we suck at
outputting unicode strings (c.f. last three lines below).

Aug 11 10:46:21 fedora python[67]: test message
                                   line
                                   line...
Aug 11 10:50:47 fedora python[76]: test message word word word word word word word word word word word wor...
Aug 11 10:55:11 fedora python[83]: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
Aug 11 11:03:21 fedora python[90]: ąąąąąąąąąąąąąąąąąąąąąąąąąąąąąą...
Aug 11 11:03:53 fedora python[97]: aąąąąąąąąąąąąąąąąąąąąąąąąąąąąąą...
Aug 11 11:25:45 fedora python[121]: aąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąą�...
2013-08-11 18:10:34 -04:00
Zbigniew Jędrzejewski-Szmek b4b02cbeec logs-show: fix indentation for 2nd and later lines, show lines in full
Now --full will show long fields in full, like it already did
with --all.
2013-08-11 18:10:34 -04:00
Zbigniew Jędrzejewski-Szmek 94e0bd7db1 systemctl: show hint about --full when lines don't fit 2013-08-11 18:10:34 -04:00
Daniel Schaal 0b5a519c89 systemd-delta: Only print colors when on a tty
This make systemd-delta follow the behaviour of systemctl
and journalctl.

https://bugs.freedesktop.org/show_bug.cgi?id=67656

[zj: unify color query methods between those three programs.]
2013-08-04 08:33:02 -04:00
Kay Sievers e21fea24ae rework systemd's own process environment handling/passing
Stop importing non-sensical kernel-exported variables. All
parameters in the kernel command line are exported to the
initial environment of PID1, but suppressed if they are
recognized by kernel built-in code. The EFI booted kernel
will add further kernel-internal things which do not belong
into userspace.

The passed original environ data of the process is not touched
and preserved across re-execution, to allow external reading of
/proc/self/environ for process properties like container*=.
2013-07-26 18:40:40 +02:00
Zbigniew Jędrzejewski-Szmek 68fee104e6 journalctl: use _COMM= match for scripts
In case of scripts, _EXE is set to the interpreter name, and
_COMM is set based on the file name. Add a match for _COMM,
and _EXE if the interpreter is not a link (e.g. for yum,
the interpreter is /usr/bin/python, but it is a link to
/usr/bin/python2, which in turn is a link to /usr/bin/python2.7,
at least on Fedora, so we end up with _EXE=/usr/bin/python2.7).
I don't think that such link chasing makes sense, because
the final _EXE name is more likely to change.
2013-07-26 12:16:57 -04:00
Kay Sievers 39bdfa31f2 shared: split mkdir_*() and mkdir_*_label() from each other
Avoid pulling-in selinux for tools which just create directories
but not need to fix the selinux label.
2013-07-26 04:13:55 +02:00
Lennart Poettering 8b18fdc195 core: synchronously block when logging
Previously, the logging sockets were asynchronous and if clogged we'd
lose messages. We did this to be extra careful given that PID 1 might
need to spawn the logging daemon as response to PID 1's own log messages
and we really should avoid a deadlock in that case.

As it turns out this causes loss of too many messages, hence make the
socket blocking again, however put a time limit on it to avoid unbounded
deadlocks in the unlikely case they happen.

https://bugs.freedesktop.org/show_bug.cgi?id=66664
2013-07-24 12:34:28 +02:00
Shawn Landden 3c475ce44e shared: fix build on !x86 2013-07-20 21:33:10 -04:00
Zbigniew Jędrzejewski-Szmek 6aaa8c2f78 core: add %v specifier 2013-07-19 02:45:49 -04:00
Lennart Poettering d4ac85c6f6 util: add split_pair() for splitting foo=bar strings 2013-07-18 20:22:29 +02:00
Tomasz Torcz 44bc6e1fe0 journalctl: add ”short-iso” output format with verbose ISO8601 timestamps
Example:
2013-07-18T10:10:01+0200 sandworm CROND[20957]: (root) CMD (/usr/lib64/sa/sa1 1 1)
2013-07-18 15:58:49 +02:00
Zbigniew Jędrzejewski-Szmek 4ad16808c0 journalctl,systemctl: fix tiny memleak 2013-07-16 22:41:47 -04:00