Commit graph

298 commits

Author SHA1 Message Date
Thomas Hindoe Paaboel Andersen ce9d6bcf33 path-util: do not return NULL as int
strv_split will only return NULL on oom so we should return -ENOMEM
instead.

Looks like an oversight from the changes in 0f474365
2015-10-26 22:31:37 +01:00
Lennart Poettering 4d0d3d41d2 process-util: move more process related calls to process-util.[ch] 2015-10-26 01:24:39 +01:00
Lennart Poettering 2583fbea8e socket-util: move remaining socket-related calls from util.[ch] to socket-util.[ch] 2015-10-26 01:24:39 +01:00
Lennart Poettering 81a56d6f42 util-lib: move ether_addr_to_string() into ether-addr-util.c 2015-10-26 01:24:39 +01:00
Lennart Poettering 373cd63a37 path-util: minor coding style fix
We usually avoid relying on C's degrade-to-boolean functionality when
comparing numerical variables with 0. We use it only for pointers and
actual booleans.
2015-10-26 01:24:39 +01:00
Lennart Poettering 67c7c892b9 user-util: never hand out or accept invalid UIDs
libc isn't that strict, but it's a good idea if we are, to not create
confusion around invalid user ids.
2015-10-26 01:24:38 +01:00
Lennart Poettering d02608170e util: remove lookup_uid(), replace by uid_to_name()
So far we had two pretty much identical calls in user-util.[ch]:
lookup_uid() and uid_to_name(). Get rid of the former, in favour of the
latter, and while we are at it, rewrite it, to use getpwuid_r()
correctly, inside an allocation loop, as POSIX intended.
2015-10-26 01:24:38 +01:00
Lennart Poettering b1d5277372 user-util: simplify uid parsing a bit 2015-10-26 01:24:38 +01:00
Lennart Poettering b1d4f8e154 util-lib: split out user/group/uid/gid calls into user-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering c004493cde util-lib: split out IO related calls to io-util.[ch] 2015-10-26 01:24:38 +01:00
Hristo Venev 078efddd37 basic: use the return value of endswith
It returns the position where the suffix begins, which can be used for
strndup to extract the prefix without calling strlen.
2015-10-25 18:46:20 +02:00
Lennart Poettering f00022dd12 util-lib: move formats-util.h from shared/ to basic/
It's only a header file, definining format strings for basic system
types, hence it should be in src/basic/, not src/shared/.
2015-10-25 13:19:18 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 00229fe48f util: move logind_running() to login-util.[ch] 2015-10-24 23:30:40 +02:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 4f5dd3943b util: split out escaping code into escape.[ch]
This really deserves its own file, given how much code this is now.
2015-10-24 23:04:42 +02:00
Lennart Poettering dea7b6b043 util-lib: rework extract_first_word_and_warn() a bit
- Really warn in all error cases, not just some. We need to make sure
  that all errors are logged to not confuse the user.

- Explicitly check for EINVAL error code before claiming anything about
  invalid escapes, could be ENOMEM after all.
2015-10-24 23:03:49 +02:00
Lennart Poettering 84ac7bea36 util: split out extract_first_word() and related calls into extract-word.[ch]
This is quite a lot of code these days, hence move it to its own source
file.
2015-10-24 23:03:49 +02:00
Lennart Poettering 0f03c2a4c0 path-util: unify how we process paths specified on the command line
Let's introduce a common function that makes relative paths absolute and
warns about any errors while doing so.
2015-10-24 23:03:49 +02:00
Lennart Poettering 0f47436510 util-lib: get_current_dir_name() can return errors other than ENOMEM
get_current_dir_name() can return a variety of errors, not just ENOMEM,
hence don't blindly turn its errors to ENOMEM, but return correct errors
in path_make_absolute_cwd().

This trickles down into a couple of other functions, some of which
receive unrelated minor fixes too with this commit.
2015-10-24 23:03:49 +02:00
Lennart Poettering 85eca92e20 path-util: rework find_binary(), fsck_exists() and mkfs_exists()
Modernize the code a bit:

- Get rid of FOREACH_WORD_SEPARATOR() loop in favour of a
  extract_first_word() loop.

- Remove find_binary()'s "local" flag. It's not reasonably possible to
  look for binaries on remote systems, we hence should not pretend we
  could.

- When we cannot find a suitable binary, return the last error returned
  from access() rather than ENOENT unconditionally.

- Rework fsck_exists() and mkfs_exists() to return 1 on success, 0 if
  the implementation is missing and negative on real errors. This is
  more like we do it in other functions.

- Make sure we also detect direct fsck symlinks to "true", rather than
  just absolute ones to /bin/true.
2015-10-24 23:03:49 +02:00
Lennart Poettering d3aacce707 Merge pull request #1652 from filbranden/extract1
util: Replace state with separate booleans in extract_first_word
2015-10-23 13:46:03 +02:00
Daniel Mack 952b4473bc Merge pull request #1641 from poettering/btrfs-quota
btrfs quota beef up and various other unrelated changes
2015-10-23 10:50:53 +02:00
Filipe Brandenburger 4cbf8afa04 util: Replace state with separate booleans in extract_first_word
This simplifies the logic and uniformizes the way single and double
quotes are handled. In the end, the code is about 40 lines shorter.

Tested by running the excellent test cases from test-util. Also
installed the systemd binaries including this patch and booted a
system with it, everything looked normal.
2015-10-22 23:12:31 -07:00
Evgeny Vereshchagin 9e44f56b4e util: allow unbalanced double quote in EXTRACT_QUOTES|EXTRACT_RELAX mode
extract_first_word understands "\'string" but doesn't understand "\"string"
fixed this inconsistency.
2015-10-22 00:37:32 +00:00
Lennart Poettering 5bcd08db28 btrfs: beef-up btrfs support with a limited understanding of quota
With this change we understand more than just leaf quota groups for
btrfs file systems. Specifically:

- When we create a subvolume we can now optionally add the new subvolume
  to all qgroups its parent subvolume was member of too. Alternatively
  it is also possible to insert an intermediary quota group between the
  parent's qgroups and the subvolume's leaf qgroup, which is useful for
  a concept of "subtree" qgroups, that contain a subvolume and all its
  children.

- The remove logic for subvolumes has been updated to optionally remove
  any leaf qgroups or "subtree" qgroups, following the logic above.

- The snapshot logic for subvolumes has been updated to replicate the
  original qgroup setup of the source, if it follows the "subtree"
  design described above. It will not cover qgroup setups that introduce
  arbitrary qgroups, especially those orthogonal to the subvolume
  hierarchy.

This also tries to be more graceful when setting up /var/lib/machines as
btrfs. For example, if mkfs.btrfs is missing we don't even try to set it
up as loopback device.

Fixes #1559
Fixes #1129
2015-10-22 01:59:25 +02:00
Lennart Poettering ac7edd9167 util: improve dir_is_empty() call
Simplify the call, and add dir_is_populated() as inverse call, in order
to make some checks easier to read.
2015-10-22 01:59:24 +02:00
Lennart Poettering c91960c5a0 Merge pull request #1619 from iaguis/nspawn-sysfs-netns-3
nspawn: skip /sys-as-tmpfs if we don't use private-network
2015-10-20 12:22:32 +02:00
Iago López Galeiras d167824896 nspawn: skip /sys-as-tmpfs if we don't use private-network
Since v3.11/7dc5dbc ("sysfs: Restrict mounting sysfs"), the kernel
doesn't allow mounting sysfs if you don't have CAP_SYS_ADMIN rights over
the network namespace.

So the mounting /sys as a tmpfs code introduced in
d8fc6a000f doesn't work with user
namespaces if we don't use private-net. The reason is that we mount
sysfs inside the container and we're in the network namespace of the host
but we don't have CAP_SYS_ADMIN over that namespace.

To fix that, we mount /sys as a sysfs (instead of tmpfs) if we don't use
private network and ignore the /sys-as-a-tmpfs code if we find that /sys
is already mounted as sysfs.

Fixes #1555
2015-10-20 10:19:23 +02:00
Zbigniew Jędrzejewski-Szmek ab84f5b95e strv: Add _cleanup_strv_free_erase_ and _cleanup_string_free_erase_ 2015-10-19 23:13:07 +02:00
Lennart Poettering 1602b00853 tree-wide: whenever we deal with passwords, erase them from memory after use
A bit snake-oilish, but can't hurt.
2015-10-19 23:13:07 +02:00
Lennart Poettering aa486a72be Merge pull request #1598 from evverx/run-oomscoreadjust
systemd-run can launch units with OOMScoreAdjust
2015-10-19 19:02:47 +02:00
David Herrmann 606601ddca Merge pull request #1595 from poettering/proxy-fixes
bus proxy fixes, and more
2015-10-18 12:15:10 +02:00
Evgeny Vereshchagin 257b0719cb util: add func for checking OOMScoreAdjust 2015-10-17 20:03:40 +00:00
Tom Gundersen 9c5a882b7f sd-netlink: refcount multicast groups
Track the number of matches installed for a given multicast group, and leave the
group once no matches depend on it.

In order to handle passed-in sockets that are already members of multicast groups
we initialize the refcount based on the membership once we take over the socket.
This way we will leave the socket in the state we found it once we finish with
it.

On kernels that do not fully support reading out the multicast group membership
we fall back to never leaving any groups (as before).
2015-10-15 18:59:08 +02:00
Lennart Poettering 3f952f92b9 btrfs: always remove the per-subvol qgroup when removing a subvol
btrfs doesn't do that automatically, hence let's do that explicitly each
time.
2015-10-15 18:37:03 +02:00
Hristo Venev 51ffa239e8 basic: calendarspec UTC support
Just add " UTC" to the end of the event expression. Works for the
special expressions.
2015-10-15 02:57:59 +03:00
Hristo Venev e4eaf99a31 basic: parse_timestamp UTC and fractional seconds support 2015-10-15 02:57:57 +03:00
Hristo Venev 7c67c79c9a basic: add mktime_or_timegm and localtime_or_gmtime_r
to time-util.h. They take an extra argument `bool utc`.
2015-10-15 02:34:45 +03:00
Evgeny Vereshchagin adb8ec96f2 util: add functions for validating syslog level and facility 2015-10-14 16:35:24 +00:00
Lennart Poettering 1ba239315f util: minor modernization of vt_disallocate() 2015-10-08 15:03:31 +02:00
Lennart Poettering 3d18b16755 util: do not reset terminal in acquire_terminal()
Before, we'd always reset acquired terminals, which is not really
desired, as we expose a setting TTYReset= which is supposed to control
whether the TTY is reset or not. Previously that setting would only
enable a second resetting of the TTY, which is of course pointless...

Hence, move the implicit resetting out of acquire_terminal() and make
the callers do it if they need it.
2015-10-08 15:03:31 +02:00
Lennart Poettering 40e1f4ea74 machined: when opening a shell via machined, pass tty fds in
With this change we'll open the shell's tty right from machined and then
pass it to the transient unit we create. This way we make sure the pty
is opened exactly as long as the transient service is around, and no
longer, and vice versa. This way pty forwarders do not have to deal with
EIO problems due to vhangup, as the pty is open all the time from the
point we set things up to the point where the service goes away.
2015-10-08 15:03:31 +02:00
Lennart Poettering 66cb2fde7b basic: move two more terminal-related calls into terminal-util.[ch] 2015-10-08 12:49:59 +02:00
Lennart Poettering 660021d371 util: always enforce O_NOCTTY and O_CLOEXEC in openpt_in_namespace()
The child process is shortliving, hence always set O_NOCTTY so that the
tty doesn't quickly become controlling TTY and then gives it up again.
Also set O_CLOEXEC, because it's cleaner, and doesn't affect the parent
anyway.
2015-10-07 20:08:49 +02:00
Daniel Mack 79bec997c9 Merge pull request #1484 from poettering/ask-pass-kernel-keyring
cache harddisk passwords in the kernel keyring
2015-10-07 15:32:42 +02:00
Michal Schmidt df553b586b basic: fix env expansion for strings leading with two dollar signs
The way to escape a literal dollar sign is to write "$$". But this does
not work right if it's at the beginning of the argument. Fix it.
2015-10-07 14:43:55 +02:00
Lennart Poettering e287086b8a ask-password: add support for caching passwords in the kernel keyring
This adds support for caching harddisk passwords in the kernel keyring
if it is available, thus supporting caching without Plymouth being
around.

This is also useful for hooking up "gdm-auto-login" with the collected
boot-time harddisk password, in order to support gnome keyring
passphrase unlocking via the HDD password, if it is the same.

Any passwords added to the kernel keyring this way have a timeout of
2.5min at which time they are purged from the kernel.
2015-10-07 12:26:14 +02:00
Daniel Mack 42911a567d Merge pull request #1481 from again4you/devel/smack_sysuser_#4
smack: label /etc/passwd and friends as '_' smack label when --with-smack-run-label' is enabled (v3)
2015-10-07 11:37:21 +02:00
reverendhomer 6fff8ac4a9 strv: fix infinite loop in strv_extend_n()
Fixes Coverity #1325768
2015-10-07 11:52:10 +03:00