Commit graph

415 commits

Author SHA1 Message Date
Lennart Poettering a354329f72 core: add new logic for services to store file descriptors in PID 1
With this change it is possible to send file descriptors to PID 1, via
sd_pid_notify_with_fds() which PID 1 will store individually for each
service, and pass via the usual fd passing logic on next invocation.
This is useful for enable daemon reload schemes where daemons serialize
their state to /run, push their fds into PID 1 and terminate, restoring
their state on next start from the data in /run and passed in from PID
1.

The fds are kept by PID 1 as long as no POLLHUP or POLLERR is seen on
them, and the service they belong to are either not dead or failed, or
have a job queued.
2015-01-06 03:16:39 +01:00
Topi Miettinen abe4aa144b util: Do not clear parent mount flags when setting up namespaces
When setting up a namespace, mount flags like noexec, nosuid and
nodev are cleared, so the mounts always have exec, suid and dev
flags enabled.

Copy source directory mount flags to target mount when remounting
the bind mounts.
2015-01-05 13:24:57 +01:00
Colin Walters 9bc5cd6d74 util: Fix signedness error in lines(), match implementations
Regression introduced by ed757c0cb0

Mirror the implementation of columns(), since the fd_columns()
functions returns a negative integer for errors.

Also fix columns() to return the unsigned variable instead of the
signed intermediary (they're the same, but better to be explicit).
2015-01-05 03:05:15 +01:00
Lennart Poettering f02ca52281 util: treat -1 as special size in format_bytes() 2014-12-28 02:08:40 +01:00
Lennart Poettering ebd93cb684 machinectl/machined: implement "rename", "clone", "read-only" verbs for machine images 2014-12-28 02:08:40 +01:00
Lennart Poettering 2c39ea529b util: always override crtime xattr 2014-12-26 19:21:58 +01:00
Lennart Poettering 10f9c75519 machined: beef up machined image listing with creation/modification times of subvolumes
We make use of the btrfs subvol crtime for this, and for gpt images of a
manually managed xattr, if we can.
2014-12-25 03:19:19 +01:00
Lennart Poettering 4a4d89b682 util: make creation time xattr logic more generic 2014-12-24 16:53:04 +01:00
Shawn Paul Landden 0254e9448f util: fix strict aliasing violations in use of struct inotify_event v5
There is alot of cleanup that will have to happen to turn on
-fstrict-aliasing, but I think our code should be "correct" to the rule.
2014-12-24 16:53:04 +01:00
Lennart Poettering 5f8cc96a03 machined: add new call OpenMachineLogin() that starts a getty in a container on a pty and returns the pty master fd to the client
This is a one-stop solution for "machinectl login", and should simplify
getting logins in containers.
2014-12-23 19:15:27 +01:00
Lennart Poettering 9d8c4979c0 util: add allocation loop to gettyname_malloc() 2014-12-23 03:26:24 +01:00
Lennart Poettering ee451d766a systemd-run: support -t mode when combined with -M
For that, ask machined for a container PTY and use that.
2014-12-23 03:26:24 +01:00
Lennart Poettering c2ce6a3d82 machined: add new GetImage() bus call for retrieving the bus path for an image 2014-12-19 20:07:23 +01:00
Lennart Poettering a34bf9db5d util: rename ignore_file() to hidden_file()
hidden_file() is a bit more precise, since dot files usually shouldn't
be ignored, but certainly be considered hidden.
2014-12-19 20:03:36 +01:00
Lennart Poettering 8eebf6ad55 util: when creating temporary filename for atomic creation of files, add an extra "#" to the name
That way, we have a simple, somewhat reliable way to detect such
temporary files, by simply checking if they start with ".#".
2014-12-19 19:19:29 +01:00
Lennart Poettering e02d225b1e util: make sure rm_rf() can be called on symlinks (with the effect of deleting it) 2014-12-19 02:07:42 +01:00
Zbigniew Jędrzejewski-Szmek ba774317ac Treat a trailing backslash as an error
Commit a2a5291b3f changed the parser to reject unfinished quoted
strings. Unfortunately it introduced an error where a trailing
backslash would case an infinite loop. Of course this must fixed, but
the question is what to to instead. Allowing trailing backslashes and
treating them as normal characters would be one option, but this seems
suboptimal. First, there would be inconsistency between handling of
quoting and of backslashes. Second, a trailing backslash is most
likely an error, at it seems better to point it out to the user than
to try to continue.

Updated rules:
ExecStart=/bin/echo \\ → OK, prints a backslash
ExecStart=/bin/echo \ → error
ExecStart=/bin/echo "x → error
ExecStart=/bin/echo "x"y → error
2014-12-18 19:26:21 -05:00
Lennart Poettering 20b63d12b5 util: in make_stdio() use dup2() rather than dup3()
dup3() allows setting O_CLOEXEC which we are not interested in. However,
it also fails if called with the same fd as input and output, which is
something we don't want. Hence use dup2().

Also, we need to explicitly turn off O_CLOEXEC for the fds, in case the
input fd was O_CLOEXEC and < 3.
2014-12-18 01:36:28 +01:00
Lennart Poettering c4e34a612c nspawn: allow spawning ephemeral nspawn containers based on the root file system of the OS
This works now:

        # systemd-nspawn -xb -D / -M foobar

Which boots up an ephemeral container, based on the host's root file
system. Or in other words: you can now run the very same host OS you
booted your system with also in a container, on top of it, without
having it interfere. Great for testing whether the init system you are
hacking on still boots without reboot the system!
2014-12-12 17:30:25 +01:00
Lennart Poettering 6ce830fa61 util: minor simplification for loop_write() and loop_read() 2014-12-12 13:35:32 +01:00
Lennart Poettering ae6c3cc009 util: when using basename() for creating temporary files, verify the resulting name is actually valid
Also, rename filename_is_safe() to filename_is_valid(), since it
actually does a full validation for what the kernel will accept as file
name, it's not just a heuristic.
2014-12-12 13:35:32 +01:00
Torstein Husebø cc13b32729 shared: correct spacing near eol in code comments 2014-12-11 15:08:35 +01:00
Zbigniew Jędrzejewski-Szmek 553acb7b6b treewide: sanitize loop_write
loop_write() didn't follow the usual systemd rules and returned status
partially in errno and required extensive checks from callers. Some of
the callers dealt with this properly, but many did not, treating
partial writes as successful. Simplify things by conforming to usual rules.
2014-12-09 21:36:08 -05:00
Lennart Poettering f7c1ad4fd4 core: unify how we iterate over inotify events
Let's add some syntactic sugar for iterating through inotify events, and
use it everywhere.
2014-12-10 01:48:39 +01:00
Lennart Poettering 3280236156 sd-bus: get rid of PID starttime concept
As kdbus no longer exports this, remove all traces from sd-bus too
2014-12-09 18:16:54 +01:00
Thomas Hindoe Paaboel Andersen e706d931e0 util: don't shadow variable
environ is already defined in unistd.h
2014-12-03 23:51:51 +01:00
Didier Roche 979ef53a26 machine-id-setup: add a machine_id_commit call to commit on disk a transient machine-id
If /etc was read only at boot time with an empty /etc/machine-id, the latter
will be mounted as a tmpfs and get reset at each boot. If the system becomes rw
later, this functionality enables to commit in a race-free manner the
transient machine-id to disk.
2014-12-03 03:41:19 +01:00
Zbigniew Jędrzejewski-Szmek 820d3acfe9 delta: diff returns 1 when files differ, ignore this
https://bugs.debian/org/771397
2014-11-29 11:10:51 -05:00
Lennart Poettering fed1e721fd treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1 2014-11-28 20:55:04 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Lennart Poettering 1a29929959 kdbus: set kernel attach mask before creating the first bus 2014-11-27 22:05:24 +01:00
Jakub Filak c593bb360e util: add function getting proc environ
On the contrary of env, the added function returns all characters
cescaped, because it improves reproducibility.
2014-11-27 00:24:52 -05:00
Lennart Poettering 62028d9c2b util: skip incomplete ucred information in getpeersec() 2014-11-25 14:28:34 +01:00
Jakub Filak ad450c3e04 util: add functions getting proc cwd and root
/proc/[pid]/cwd and /proc/[pid]/root are symliks to corresponding
directories

The added functions returns values of that symlinks.
2014-11-21 00:32:02 +01:00
Lennart Poettering 781fa93815 busctl: add new "call" command to invoke methods on a service 2014-11-14 13:18:51 +01:00
Lennart Poettering f88e6be5ee strv: rework strv_split_quoted() to use unquote_first_word()
This should make the unquoting scheme a bit less naive.
2014-11-10 23:45:12 +01:00
Tom Gundersen 9a67bcf275 shared: add readlink_value
Reads the basename of the target of a symlink.
2014-11-07 19:46:14 +01:00
Lennart Poettering f4934dfaaa util: simplify normalize_env_assignment() a bit 2014-11-07 01:19:56 +01:00
Lennart Poettering b5e1fad5b1 util: file_is_priv_sticky() is used internally in util.c only nowadays, make it static 2014-11-07 01:19:56 +01:00
Lennart Poettering f32d2db140 util: rework /proc/cmdline parser to use unquote_first_word() 2014-11-07 01:19:56 +01:00
Lennart Poettering b5884878a2 util: simplify proc_cmdline() to reuse get_process_cmdline()
Also, make all parsing of the kernel cmdline non-fatal.
2014-11-07 01:19:56 +01:00
Lennart Poettering 0c2576ef74 util: make use of isempty() where appropriate 2014-11-07 01:19:56 +01:00
Lennart Poettering d1bddcec98 condition: unify condition logic in one file 2014-11-06 14:21:10 +01:00
Lennart Poettering 4a6ca457eb util: minor modernisations 2014-11-05 19:46:07 +01:00
Lennart Poettering ef309a681f util: unify how we see srand() 2014-10-30 15:35:37 +01:00
Lennart Poettering 97768fc574 util: don't block on getrandom() 2014-10-30 15:27:53 +01:00
Lennart Poettering 539618a0dd util: make use of the new getrandom() syscall if it is available when needing entropy
Doesn't require an fd, and could be a bit faster, so let's make use of
it, if it is available.
2014-10-29 17:06:32 +01:00