Commit graph

197 commits

Author SHA1 Message Date
Lennart Poettering 2928b0a863 core: add support for a configurable system-wide start-up timeout
When this system-wide start-up timeout is hit we execute one of the
failure actions already implemented for services that fail.

This should not only be useful on embedded devices, but also on laptops
which have the power-button reachable when the lid is closed. This
devices, when in a backpack might get powered on by accident due to the
easily reachable power button. We want to make sure that the system
turns itself off if it starts up due this after a while.

When the system manages to fully start-up logind will suspend the
machine by default if the lid is closed. However, in some cases we don't
even get as far as logind, and the boot hangs much earlier, for example
because we ask for a LUKS password that nobody ever enters.

Yeah, this is a real-life problem on my Yoga 13, which has one of those
easily accessible power buttons, even if the device is closed.
2014-08-22 18:10:31 +02:00
Lennart Poettering af4ec4309e notify: send STOPPING=1 from our daemons 2014-08-21 17:24:21 +02:00
Lennart Poettering 70af4d17da manager: don#t dispatch sd_notify() messages and SIGCHLD multiple times to the same units 2014-08-21 17:24:21 +02:00
Lennart Poettering 55836941ff manager: reuse sockaddr_union instead of redefining our own version of it 2014-08-21 17:24:21 +02:00
Lennart Poettering c1dc6153c9 log: never ever log to syslog from PID 1, log to the journal again
We don't support journal-less systems anyway, so let's avoid the
confusion.
2014-08-11 20:08:08 +02:00
Zbigniew Jędrzejewski-Szmek 1d749d044b tty-ask-password-agent: modernization 2014-08-03 21:46:07 -04:00
Kay Sievers 3a43da2832 time-util: add and use USEC/NSEC_INFINIY 2014-07-29 13:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 1cd974edfd systemd: return the first error from manager_startup() 2014-07-20 19:48:16 -04:00
Zbigniew Jędrzejewski-Szmek 0d8c31ff72 test-engine: fix access to unit load path
Also add a bit of debugging output to help diagnose problems,
add missing units, and simplify cppflags.

Move test-engine to normal tests from manual tests, it should now
work without destroying the system.
2014-07-20 19:48:16 -04:00
Zbigniew Jędrzejewski-Szmek 6b9732b2bf Be more verbose when bind or listen fails
Also be more verbose in devnode_acl_all().
2014-07-18 21:44:59 -04:00
Umut Tezduyar Lindskog 285cd771cb core: fix oneshot service resource control
Oneshot services's cgroup is removed when the service
exits. An assert is hit otherwise.
2014-07-15 10:08:01 -04:00
Lennart Poettering e26807239b firstboot: get rid of firstboot generator again, introduce ConditionFirstBoot= instead
As Zbigniew pointed out a new ConditionFirstBoot= appears like the nicer
way to hook in systemd-firstboot.service on first boots (those with /etc
unpopulated), so let's do this, and get rid of the generator again.
2014-07-07 21:05:09 +02:00
Lennart Poettering 418b9be500 firstboot: add new component to query basic system settings on first boot, or when creating OS images offline
A new tool "systemd-firstboot" can be used either interactively on boot,
where it will query basic locale, timezone, hostname, root password
information and set it. Or it can be used non-interactively from the
command line when prepareing disk images for booting. When used
non-inertactively the tool can either copy settings from the host, or
take settings on the command line.

$ systemd-firstboot --root=/path/to/my/new/root --copy-locale --copy-root-password --hostname=waldi

The tool will be automatically invoked (interactively) now on first boot
if /etc is found unpopulated.

This also creates the infrastructure for generators to be notified via
an environment variable whether they are running on the first boot, or
not.
2014-07-07 15:25:55 +02:00
Lennart Poettering 9a05490933 cgroups: simplify CPUQuota= logic
Only accept cpu quota values in percentages, get rid of period
definition.

It's not clear whether the CFS period controllable per-cgroup even has a
future in the kernel, hence let's simplify all this, hardcode the period
to 100ms and only accept percentage based quota values.
2014-05-22 11:53:12 +09:00
Lennart Poettering db785129c9 cgroup: rework startup logic
Introduce a (unsigned long) -1 as "unset" state for cpu shares/block io
weights, and keep the startup unit set around all the time.
2014-05-22 07:13:56 +09:00
WaLyong Cho 95ae05c0e7 core: add startup resource control option
Similar to CPUShares= and BlockIOWeight= respectively. However only
assign the specified weight during startup. Each control group
attribute is re-assigned as weight by CPUShares=weight and
BlockIOWeight=weight after startup.  If not CPUShares= or
BlockIOWeight= be specified, then the attribute is re-assigned to each
default attribute value. (default cpu.shares=1024, blkio.weight=1000)
If only CPUShares=weight or BlockIOWeight=weight be specified, then
that implies StartupCPUShares=weight and StartupBlockIOWeight=weight.
2014-05-22 07:13:56 +09:00
Lennart Poettering 9bdb98c594 core: make sure to serialize jobs for all units
Previously we wouldn't serialize jobs for units that themselves have
nothing to serialize.

http://lists.freedesktop.org/archives/systemd-devel/2014-May/019051.html
2014-05-16 01:15:03 +02:00
Zbigniew Jędrzejewski-Szmek 12ed81d9c8 Make systemctl --root look for files in the proper places
Running systemctl enable/disable/set-default/... with the --root
option under strace reveals that it accessed various files and
directories in the main fs, and not underneath the specified root.
This can lead to correct results only when the layout and
configuration in the container are identical, which often is not the
case. Fix this by adding the specified root to all file access
operations.

This patch does not handle some corner cases: symlinks which point
outside of the specified root might be interpreted differently than
they would be by the kernel if the specified root was the real root.
But systemctl does not create such symlinks by itself, and I think
this is enough of a corner case not to be worth the additional
complexity of reimplementing link chasing in systemd.

Also, simplify the code in a few places and remove an hypothetical
memory leak on error.
2014-05-15 15:29:58 +02:00
Lennart Poettering b2f8b02ec2 core: expose CFS CPU time quota as high-level unit properties 2014-04-25 13:27:25 +02:00
Kay Sievers 530a9662aa core: do not read system boot timestamps in systemd --user mode
Before:
  $ systemd-analyze --user
  Startup finished in 2.810s (firmware) + 48ms (loader) + 122ms (userspace) = 122ms

After:
  $ systemd-analyze --user
  Startup finished in 122ms (userspace) = 122ms
2014-03-26 03:47:03 +01:00
Lennart Poettering bd8f585b99 core: add a setting to globally control the default for timer unit accuracy 2014-03-24 16:24:07 +01:00
Lennart Poettering 3d94f76c99 util: replace close_pipe() with new safe_close_pair()
safe_close_pair() is more like safe_close(), except that it handles
pairs of fds, and doesn't make and misleading allusion, as it works
similarly well for socketpairs() as for pipe()s...
2014-03-24 03:22:44 +01:00
Lennart Poettering 6a0f1f6d5a sd-event: rework API to support CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM, too 2014-03-24 02:58:41 +01:00
Lennart Poettering 7181dbdb2e core: move notify sockets to /run and $XDG_RUNTIME_DIR
A service with PrivateNetwork= cannot access abstract namespace sockets
of the host anymore, hence let's better not use abstract namespace
sockets for this, since we want to make sure that PrivateNetwork=
is useful and doesn't break sd_notify().
2014-03-19 22:46:45 +01:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Lennart Poettering 0851062751 manager: use system state enum where appropriate 2014-03-12 22:27:13 +01:00
Lennart Poettering f755e3b74b core: introduce system state enum
The system state knows the states starting →
running/degraded/maintenance → stopping, where:

starting = system startup
running = normal operation
degraded = at least one unit is currently in failed state
maintenance = rescue/emergency mode is active or queued
stopping = system shutdown
2014-03-12 20:55:13 +01:00
Daniel Mack b2cdc6664e manager: flush memory stream before using the buffer
When the manager receives a SIGUSR2 signal, it opens a memory stream
with open_memstream(), uses the returned file handle for logging, and
dumps the logged content with log_dump().

However, the char* buffer is only safe to use after the file handle has
been flushed with fflush, as the man pages states:

  When the stream is closed (fclose(3)) or flushed (fflush(3)), the
  locations pointed to by ptr and sizeloc are updated to contain,
  respectively, a pointer to the buffer and the current size of  the
  buffer.
  These values remain valid only as long as the caller performs no
  further output on the stream.  If further output is performed, then the
  stream must again be flushed before trying to access these variables.

Without that call, dump remains NULL and the daemon crashes in
log_dump().
2014-03-07 15:15:56 +01:00
Lennart Poettering aa62a8936f util: add timeout to generator execution 2014-03-06 04:00:42 +01:00
Lennart Poettering 517d56b1d0 missing: if RLIMIT_RTTIME is not defined by the libc, then we need a new define for the max number of rlimits, too 2014-03-05 02:31:09 +01:00
Lennart Poettering e66cf1a3f9 core: introduce new RuntimeDirectory= and RuntimeDirectoryMode= unit settings
As discussed on the ML these are useful to manage runtime directories
below /run for services.
2014-03-03 17:55:32 +01:00
Lennart Poettering 8f8f05a919 bus: add sd_bus_track object for tracking peers, and port core over to it
This is primarily useful for services that need to track clients which
reference certain objects they maintain, or which explicitly want to
subscribe to certain events. Something like this is done in a large
number of services, and not trivial to do. Hence, let's unify this at
one place.

This also ports over PID 1 to use this to ensure that subscriptions to
job and manager events are correctly tracked. As a side-effect this
makes sure we properly serialize and restore the track list across
daemon reexec/reload, which didn't work correctly before.

This also simplifies how we distribute messages to broadcast to the
direct busses: we only track subscriptions for the API bus and
implicitly assume that all direct busses are subscribed. This should be
a pretty OK simplification since clients connected via direct bus
connections are shortlived anyway.
2014-03-03 02:34:13 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Zbigniew Jędrzejewski-Szmek 4daf54a851 journald: log provenience of signals 2014-02-11 19:14:47 -05:00
Zbigniew Jędrzejewski-Szmek 49888ca9ef manager: fix initialization of plymouth socket
I'm not sure why this makes a difference...
2014-02-08 16:19:22 -05:00
Zbigniew Jędrzejewski-Szmek 2ba110900a core: use automatic cleanup in two functions 2014-02-08 13:07:39 -05:00
Lennart Poettering 5ba6985b6c core: allow PIDs to be watched by two units at the same time
In some cases it is interesting to map a PID to two units at the same
time. For example, when a user logs in via a getty, which is reexeced to
/sbin/login that binary will be explicitly referenced as main pid of the
getty service, as well as implicitly referenced as part of the session
scope.
2014-02-07 15:14:36 +01:00
Lennart Poettering a911bb9ab2 core: watch SIGCHLD more closely to track processes of units with no reliable cgroup empty notifier
When a process dies that we can associate with a specific unit, start
watching all other processes of that unit, so that we can associate
those processes with the unit too.

Also, for service units start doing this as soon as we get the first
SIGCHLD for either control or main process, so that we can follow the
processes of the service from one to the other, as long as process that
remain are processes of the ones we watched that died and got reassigned
to us as parent.

Similar, for scope units start doing this as soon as the scope
controller abandons the unit, and thus management entirely reverts to
systemd. To abandon a unit introduce a new Abandon() scope unit method
call.
2014-02-07 15:14:36 +01:00
Zbigniew Jędrzejewski-Szmek 75cb8502df transaction: print more information about conflicting jobs
Also remove some debug statement that should not have been committed.
2014-02-06 00:46:15 -05:00
Kay Sievers 486e99a387 bus: update kdbus.h (ABI break) 2014-02-01 17:21:36 +01:00
Zbigniew Jędrzejewski-Szmek 6b02bce759 manager: remove "debugging" "feature" 2014-01-28 21:57:42 -05:00
Zbigniew Jędrzejewski-Szmek e5723c894d manager: requeue the cylon eye for 5s later when a job finishes
We'd reqeue the next status update very soon after. Change it so that we wait
for full 5s without any job status changes until we print anything.
2014-01-28 19:07:13 -05:00
Zbigniew Jędrzejewski-Szmek 8bb310c3c6 manager: print ephemeral information about running jobs' timeouts (v2)
This reverts commit 28c758de94
but makes job_coldplug smarter.

In (v1) I changed the job start timestamp to be always set, so the
start time can be reported in the cylon eye message.  The bug was that
when deserializing jobs, they would be ignored if their start
timestamp was unset which was synonymous with no timeout. But after
the change, jobs would have a start timestamp set despite having no
timeout. After deserialization they would be considered immediately
expired. Fix this by checking if the timeout is not zero when
considering jobs for expiration.
2014-01-28 19:07:13 -05:00
Kay Sievers 28c758de94 Revert "manager: print ephemeral information about running jobs' timeouts"
This reverts commit 2cba2e0352.

It breaks bootup with dracut, the transition to the real rootfs fails.
2014-01-28 12:03:23 +01:00
Zbigniew Jędrzejewski-Szmek cb8ccb2271 manager: also turn on output on unit failure 2014-01-27 23:17:03 -05:00
Zbigniew Jędrzejewski-Szmek d450b6f2a9 manager: add systemd.show_status=auto mode
When set to auto, status will shown when the first ephemeral message
is shown (a job has been running for five seconds). Then until the
boot or shutdown ends, status messages will be shown.

No indication about the switch is done: I think it should be clear
for the user that first the cylon eye and the ephemeral messages appear,
and afterwards messages are displayed.

The initial arming of the event source was still wrong, but now should
really be fixed.
2014-01-27 23:17:03 -05:00
Zbigniew Jędrzejewski-Szmek 8e33886ec5 Replace mkostemp+unlink with open(O_TMPFILE)
This will only work on Linux >= 3.11, and probably not on all
filesystems. Fallback code is provided.
2014-01-27 23:17:02 -05:00
Zbigniew Jędrzejewski-Szmek fd08a8403f manager: rearm jobs timer
It would fire just once.

Also fix units from sec to usec as appropriate.

Decrease the switching interval to 1/3 s, so that when the time
remaining is displayed with 1s precision, it doesn't jump by 2s every
once in a while. Also, the system is feels noticably faster when the
status changes couple of times per second instead of every few
seconds.
2014-01-27 01:23:16 -05:00
Zbigniew Jędrzejewski-Szmek 2cba2e0352 manager: print ephemeral information about running jobs' timeouts
Produces output like:
[  *** ] (1 of 2) A start job is running for slow.service (33s / 1min 30s)

The first nubmer is the time since job start, the second is the job timeout.
2014-01-27 01:23:16 -05:00
Lennart Poettering f069efb471 core: don't allow setting NOTIFY_SOCKET and similar env vars we need ourselves via SetEnvironment bus calls
We just quietly eat them up, so that simple environment importing still
works without error.
2014-01-12 20:10:40 +08:00