Commit Graph

740 Commits

Author SHA1 Message Date
Zachary Cook 4f8d551ff0 systemd: record efi timestamps after /sys is mounted
This partially reverts commit c3a170f3, which moved
efi_get_boot_timestamps too early in main(), before
/sys is assured to be mounted

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

[tomegun: in particular /sys/firmware/efi/efivars needs to be
mounted, which is not a problem if a systemd-initramfs containing
the correct module is being used. But not everyone uses an
initramfs...]
2013-05-29 15:36:05 +02:00
Eelco Dolstra f49fd1d57a Start ctrl-alt-del.target irreversibly
This makes ctrl-alt-del reboots more robust, just like "systemctl
reboot".
2013-05-09 18:13:33 -04:00
Lennart Poettering 31afa0a44c unit: rework stop pending logic
When a trigger unit wants to know if a stop is queued for it, we should
just check precisely that and do not check whether it is actually
stopped already. This is because we use these checks usually from state
change calls where the state variables are not updated yet.

This change splits unit_pending_inactive() into two calls
unit_inactive_or_pending() and unit_stop_pending(). The former checks
state and pending jobs, the latter only pending jobs.
2013-04-25 22:01:49 -03:00
Harald Hoyer c3a170f3d3 systemd: record the timestamps as early as possible
The time for systemd initialization and selinux policy loading
is accounted to the initrd or the kernel, which is wrong.

Instead of:

Startup finished in 5.559s (firmware) + 36ms (loader) + 665ms (kernel) +
975ms (initrd) + 1.410s (userspace) = 8.647s

the more correct output is:

Startup finished in 5.559s (firmware) + 36ms (loader) + 665ms (kernel) +
475ms (initrd) + 1.910s (userspace) = 8.647s
2013-04-25 09:13:05 +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
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
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
Harald Hoyer b3680f49e2 Do not serialize environment, when switching root
When switching root, i.e. LANG can be set to the locale of the initramfs
or "C", if it was unset. When systemd deserializes LANG in the real root
this would overwrite the setting previously gathered by locale_set().

To reproduce, boot with an initramfs without locale.conf or change
/etc/locale.conf to a different language than the initramfs and check a
daemon started by systemd:

$ tr "$\000" '\n' </proc/$(pidof sshd)/environ | grep LANG
LANG=C

To prevent that, serialization of environment variables is skipped, when
serializing for switching root.

https://bugzilla.redhat.com/show_bug.cgi?id=949525
2013-04-08 14:45:19 +02:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Lennart Poettering 5c0d398dfc util: add a bit of syntactic sugar to run short code fragments with a different umask 2013-04-04 03:39:39 +02:00
Lennart Poettering 2fa4092c28 util: make time formatting a bit smarter
Instead of outputting "5h 55s 50ms 3us" we'll now output "5h
55.050003s". Also, while outputting the accuracy is configurable.

Basically we now try use "dot notation" for all time values > 1min. For
>= 1s we use 's' as unit, otherwise for >= 1ms we use 'ms' as unit, and
finally 'us'.

This should give reasonably values in most cases.
2013-04-04 02:56:56 +02:00
Zbigniew Jędrzejewski-Szmek 7989e1f2d7 Partially revert e62d8c3944
The ~80 chars per line part wasn't well received.
2013-03-31 19:50:30 -04:00
Zbigniew Jędrzejewski-Szmek e62d8c3944 Modernization
Use _cleanup_ and wrap lines to ~80 chars and such.
2013-03-31 14:36:12 -04:00
Michal Sekletar c17ec25e4d core: reuse the same /tmp, /var/tmp and inaccessible dir
All Execs within the service, will get mounted the same
/tmp and /var/tmp directories, if service is configured with
PrivateTmp=yes. Temporary directories are cleaned up by service
itself in addition to systemd-tmpfiles. Directory which is mounted
as inaccessible is created at runtime in /run/systemd.
2013-03-15 22:56:40 -04:00
Michal Schmidt 6282c859bd util, manager: and mempset() and use it
Just like mempcpy() is almost identical to memcpy() except the useful
return value, so is the relation of mempset() to memset().
2013-03-13 14:14:13 +01:00
Michal Schmidt 5052495bba manager: use more stpcpy() 2013-03-13 14:14:00 +01:00
Michal Schmidt 5b176ee064 manager: push back animation timer whenever a job finishes
The running jobs animation is supposed to hide itself when jobs are
progressing sufficiently fast.
2013-03-13 00:13:24 +01:00
Enrico Scholz f1324eaa68 manager: remove timer fd explicitly from epoll
Forked processes can keep the old fd alive triggering epoll over and
over again else.

https://bugs.freedesktop.org/show_bug.cgi?id=61697
2013-03-06 17:16:13 +01:00
Michal Schmidt a0b6422689 core/manager: fix conditions to start and stop watching running jobs
Harald encountered division by zero in manager_print_jobs_in_progress.
Clearly we had the watch enabled when we shouldn't - there were no
running jobs in m->jobs, only waiting ones. This is either a deadlock,
or maybe some of them would be detected as runnable in the next dispatch
of the run queue. In any case we mustn't crash.

Fix it by starting and stopping the watch based on n_running_jobs
instead of the number of all jobs.
2013-03-04 14:51:32 +01:00
Michal Schmidt e970a72e94 manager: turn a superfluous check into assert
The crash that the check prevented has been fixed by commit 9e9e2b7.
2013-03-02 12:57:42 +01:00
Lukas Nykryn 34bf02818d manager: print p and then free it 2013-03-01 16:43:57 -05:00
Michal Schmidt 9e9e2b722c core: fix running jobs counters after reload/reexec
All active units will call unit_notify() during coldplug, so we just
make sure we're counting from zero again and get the correct result for
n_on_console.

For n_running_jobs we likewise reset it to zero and then count
the running jobs as we encounter them in deserialization.
2013-03-01 18:38:22 +01:00
Harald Hoyer 5a82a91a99 manager: prevent segfault in manager_print_jobs_in_progress() 2013-03-01 15:05:28 +01:00
Michal Schmidt 03b717a3c4 core/manager: print status messages about running jobs
Sometimes the boot gets stuck until a timeout hits. The usual timeouts
are on the order of minutes, so users may lose patience.

Print animated status messages telling the names of units with running
jobs to make it easy to see what systemd is waiting for.

The animation looks cooler with a shorter interval, but 1 s is OK and
should not be too hard on slow serial console users.
2013-02-28 02:24:02 +01:00
Michal Schmidt 984a2be450 util, core: add support for ephemeral status lines
Ephemeral status lines do not end with a newline and they expect to be
overwritten by the next printed status line.
2013-02-28 02:23:27 +01:00
Michal Schmidt 6084e22e57 core/manager: make a couple of functions static
They're not used outside manager.c anymore.
2013-02-28 02:23:14 +01:00
Michal Schmidt 25cee55076 core: add manager_status_printf()
unit_status_printf() checks the state of the manager, not of the unit
as such. Move it to manager.c and rename it to manager_status_printf().

Temporarily keep unit_status_printf as a wrapper macro.
2013-02-28 00:14:40 +01:00
Michal Schmidt 23ade460e5 core, systemctl: add support for irreversible jobs
Add a new job mode: replace-irreversibly. Jobs enqueued using this mode
cannot be implicitly canceled by later enqueued conflicting jobs.
They can however still be canceled with an explicit "systemctl cancel"
call.
2013-02-22 16:06:17 +01:00
Lennart Poettering b872e9a059 build-sys: make EFI support build-time optional 2013-02-13 23:08:25 +01:00
Oleksii Shevchuk 4a9fd066f0 manager: pass environment over daemon-reexec
Fixes this bug:
alxchk > systemctl --user set-environment A=B
alxchk > systemctl --user show-environment | grep ^A=
A=B
alxchk > systemctl --user daemon-reexec
alxchk > systemctl --user show-environment | grep ^A=
alxchk >
2013-02-13 00:17:17 +01:00
Lennart Poettering 8b55b8c4e7 manager: clean environment before passing it on to others 2013-02-11 23:54:30 +01:00
Zbigniew Jędrzejewski-Szmek 7ad94c716d systemd: raise level of message about lookup paths
This can be pretty important for the user, and is not trivial
to figure out in all cases.

Also show failing path in error messages.
2013-02-06 23:16:17 -05:00
Zbigniew Jędrzejewski-Szmek 874310b7b6 systemd: do not remove empty paths from unit lookup path
The ability to start a new unit with 'systemctl start ...' should not
depend on whether there are other units in the directory. Previously,
an additional 'systemctl daemon-reload' would be necessary to tell
systemd to update the list of unit lookup paths.
2013-02-06 23:16:16 -05:00
Zbigniew Jędrzejewski-Szmek c3e31c7ba1 Replace autoconf int max test with simple define 2013-01-22 23:20:15 -05:00
Eelco Dolstra 2813720202 Fix some typos 2013-01-22 10:03:16 -05:00
Lennart Poettering 2e3d069236 core: if the bootloader supports it, determine firmware and boot loader delay
This allows us to print simple performance data of all parts of the boot now:

- firmware
- boot loader
- kernel
- initrd
- userspace

This only works for bootloaders which support passing TSC data via EFI
variables. As of now that's only gummiboot.
2013-01-19 04:22:09 +01:00
Zbigniew Jędrzejewski-Szmek d6a195a3c3 build-sys: add autoconf macro to pick macro for x32 compatibility 2013-01-18 17:04:50 -05:00
Lennart Poettering cae0c5e042 core: properly initialize kernel timestamp 2013-01-08 01:27:39 +01:00
Zbigniew Jędrzejewski-Szmek 66870f90de systemd: use unit logging macros 2013-01-06 13:52:48 -05:00
Zbigniew Jędrzejewski-Szmek bd0af84999 core/manager: modernize style 2013-01-06 13:52:47 -05:00
Lennart Poettering 57cb4adf4e nspawn: try to orderly shutdown container when receiving SIGTERM 2012-12-22 22:17:58 +01:00
Lennart Poettering 01e10de3c2 socket: support socket activation of containers 2012-12-22 22:17:58 +01:00
Lennart Poettering 8a3a1704c7 manager: fix build on 32bit systems 2012-11-25 19:46:16 +01:00
Lennart Poettering 8742514c1a timer: recalculate next elapse for calendar timer units when the system clock is changed 2012-11-25 00:33:59 +01:00
Lennart Poettering 68b29a9fca manager: introduce watch_init() initializer for watches 2012-11-22 00:45:22 +01:00
Lennart Poettering 600b704eb0 manager: connect SIGRTMIN+24 to terminating --user instances 2012-10-18 01:19:35 +02:00
Zbigniew Jędrzejewski-Szmek 1ca6783f5e log: introduce a macro to format message id
The MESSAGE_ID=... stanza will appear in countless number of places.
It is just too long to write it out in full each time.

Incidentally, this also fixes a typo of MESSSAGE is three places.
2012-10-13 14:26:30 +02:00
Lennart Poettering c1165f822c audit: turn the audit fd into a static variable
As audit is pretty much just a special kind of logging we should treat
it similar, and manage the audit fd in a static variable.

This simplifies the audit fd sharing with the SELinux access checking
code quite a bit.
2012-10-02 17:40:09 -04:00
Zbigniew Jędrzejewski-Szmek 67445f4e22 core: move ManagerRunningAs to shared
Note: I did s/MANAGER/SYSTEMD/ everywhere, even though it makes the
patch quite verbose. Nevertheless, keeping MANAGER prefix in some
places, and SYSTEMD prefix in others would just lead to confusion down
the road. Better to rip off the band-aid now.
2012-09-18 19:53:34 +02:00
Lennart Poettering c309067483 selinux: use existing library calls for audit data 2012-09-18 01:55:49 +02:00
Lennart Poettering c999977392 main: newer kernels return EINVAL if we invoke reboot() in a container lacking perms, deal with it 2012-09-17 19:05:33 +02:00
Lennart Poettering 7ceba24134 manager: fix the build 2012-09-13 19:29:46 +02:00
Lennart Poettering 915b375388 manager: extend performance measurement interface to include firmware/loader times
This only adds the fields to the D-Bus interfaces but doesn't fill them
in with anything useful yet. Gummiboot exposes the necessary bits of
information to use however and as soon as I get my fingers on a proper
UEFI laptop I'll hook up the remaining bits.

Since we want to stabilize the D-Bus interface soon and include it in
the stability promise we should get the last fixes in, hence this change
now.
2012-09-13 18:54:32 +02:00
Lennart Poettering 81270860a5 journal: suppress structured messages if they'd go to the console 2012-09-03 18:59:04 -07:00
Lennart Poettering 877d54e9b0 journal: generate structured journal messages for a number of events 2012-09-03 18:59:04 -07:00
Shawn Landden 0d0f0c50d3 log.h: new log_oom() -> int -ENOMEM, use it
also a number of minor fixups and bug fixes: spelling, oom errors
that didn't print errors, not properly forwarding error codes,
few more consistency issues, et cetera
2012-07-26 11:48:26 +02:00
Shawn Landden 669241a076 use "Out of memory." consistantly (or with "\n")
glibc/glib both use "out of memory" consistantly so maybe we should
consider that instead of this.

Eliminates one string out of a number of binaries. Also fixes extra newline
in udev/scsi_id
2012-07-25 11:23:57 +02:00
Lennart Poettering 31f92a7df4 manager: use a private notify sockets in containers to avoid problems with shared abstract socket namespaces 2012-07-19 02:17:50 +02:00
Lennart Poettering 6b78f9b435 unit: don't serialize job state, only unit state across switch-root 2012-07-18 01:46:52 +02:00
Lennart Poettering b7def68494 util: rename join() to strjoin()
This is to match strappend() and the other string related functions.
2012-07-13 13:41:01 +02:00
Lennart Poettering 5f73969991 unit-name: remove unit_name_is_valid_no_type() and move unit_name_is_valid() to unit-name.h 2012-07-10 17:07:32 +02:00
Lennart Poettering 26a1efdf61 core: mention if we are run from an initial RAM disk 2012-07-02 11:38:32 +02:00
Lennart Poettering 29252e9e5b manager: turn notify socket into abstract namespace socket again
sd_notify() should work for daemons that chroot() as part of their
initilization, hence it's a good idea to use an abstract namespace
socket which is not affected by chroot.
2012-07-02 10:43:57 +02:00
Lennart Poettering 33c5fae939 manager: serialize/deserialize job counters across reexec/reload 2012-06-29 19:47:38 +02:00
Lennart Poettering af6da548aa core: make systemd.confirm_spawn=1 actually work
This adds a timeout if the TTY cannot be acquired and makes sure we
always output the question to the console, never to the TTY of the
respective service.
2012-06-26 12:21:43 +02:00
Kay Sievers d2e54fae5c mkdir: append _label to all mkdir() calls that explicitly set the selinux context 2012-05-31 12:40:20 +02:00
Lennart Poettering 07719a21b6 manager: rework generator logic
Previously generated units were always placed at the end of the search
path. With this change there will be three unit dirs instead of one, to
place generated entries at the beginning, in the middle and at the end
of the search path:

beginning: for units that need to override all configuration, regardless
of user or vendor. Example use: system-update-generator uses this to
temporarily redirect default.target.

middle: for units that need to override vendor configuration, but not
vendor configuration. Example use: /etc/fstab should override vendor
supplied configuration (think /tmp), but should not override native user
configuration.

end: does not override anything but is available as well. Possible usage
might be to convert D-Bus bus service files to native units but allowing
vendor supplied native units to win.
2012-05-23 03:43:29 +02:00
Frederic Crozat c93ff2e913 main: allow system wide limits for services 2012-05-21 21:13:27 +02:00
Harald Hoyer f38ed06060 manager: only serialize the timestamps for the initramfs if in_initrd() 2012-05-21 18:49:31 +02:00
Michal Schmidt 80fbf05e75 dbus-unit: always load the unit before handling a message for it
We need to be able to show the properties even of inactive units.
systemctl loads the unit before getting its properties, but this is racy
as the garbage collector may kick in right after the loading.

Fix it by always loading the unit before handling a message for it.

https://bugzilla.redhat.com/show_bug.cgi?id=814966#c6
2012-05-21 12:54:34 +02:00
Lennart Poettering 664f88a7e6 manager: introduce SwitchRoot bus call for initrd/main transition 2012-05-09 01:24:50 +02:00
Kay Sievers 9eb977db5b util: split-out path-util.[ch] 2012-05-08 02:33:10 +02:00
Michal Schmidt e0209d83e7 core: add NOP jobs, job type collapsing
Two of our current job types are special:
JOB_TRY_RESTART, JOB_RELOAD_OR_START.

They differ from other job types by being sensitive to the unit active state.
They perform some action when the unit is active and some other action
otherwise. This raises a question: when exactly should the unit state be
checked to make the decision?

Currently the unit state is checked when the job becomes runnable. It's more
sensible to check the state immediately when the job is added by the user.
When the user types "systemctl try-restart foo.service", he really intends
to restart the service if it's running right now. If it isn't running right
now, the restart is pointless.

Consider the example (from Bugzilla[1]):

sleep.service takes some time to start.
hello.service has After=sleep.service.
Both services get started. Two jobs will appear:
 hello.service/start  waiting
 sleep.service/start  running
Then someone runs "systemctl try-restart hello.service".

Currently the try-restart operation will block and wait for
sleep.service/start to complete.

The correct result is to complete the try-restart operation immediately
with success, because hello.service is not running. The two original
jobs must not be disturbed by this.

To fix this we introduce two new concepts:
- a new job type: JOB_NOP
  A JOB_NOP job does not do anything to the unit. It does not pull in any
  dependencies. It is always immediately runnable. When installed to a unit,
  it sits in a special slot (u->nop_job) where it never conflicts with
  the installed job (u->job) of a different type. It never merges with jobs
  of other types, but it can merge into an already installed JOB_NOP job.

- "collapsing" of job types
  When a job of one of the two special types is added, the state of the unit
  is checked immediately and the job type changes:
  JOB_TRY_RESTART     -> JOB_RESTART or JOB_NOP
  JOB_RELOAD_OR_START -> JOB_RELOAD or JOB_START
  Should a job type JOB_RELOAD_OR_START appear later during job merging, it
  collapses immediately afterwards.
  Collapsing actually makes some things simpler, because there are now fewer
  job types that are allowed in the transaction.

[1] Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=753586
2012-04-25 18:38:27 +02:00
Lennart Poettering f2b6878955 service: introduce Type=idle and use it for gettys
Type=idle is much like Type=simple, however between the fork() and the
exec() in the child we wait until PID 1 informs us that no jobs are
left.

This is mostly a cosmetic fix to make gettys appear only after all boot
output is finished and complete.

Note that this does not impact the normal job logic as we do not delay
the completion of any jobs. We just delay the invocation of the actual
binary, and only for services that otherwise would be of Type=simple.
2012-04-24 14:42:24 +02:00
Michal Schmidt 5273510e9f transaction: cancel jobs non-recursively on isolate
Recursive cancellation of jobs would trigger OnFailure actions of
dependent jobs. This is not desirable when isolating.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=798328
2012-04-23 08:13:02 +02:00
Michal Schmidt b94fbd3078 transaction: maintain anchor_job
Track which job is the anchor in the transaction.
2012-04-20 17:12:28 +02:00
Michal Schmidt 75778e21df manager: split transaction.[ch]
manager.c takes care of the main loop, unit management, signal handling, ...
transaction.c computes transactions.

After split:
manager.c:     65 KB
transaction.c: 40 KB
2012-04-20 17:12:27 +02:00
Michal Schmidt 7527cb5275 manager: Transaction as an object
This makes it obvious that transactions are short-lived. They are created in
manager_add_job() and destroyed after the application of jobs.
It also prepares for a split of the transaction code to a new source.
2012-04-20 17:12:27 +02:00
Michal Schmidt 97e7d748d1 job: job_uninstall()
Split the uninstallation of the job from job_free() into a separate function.
Adjust the callers.

job_free() now only works on unlinked and uninstalled jobs. This enforces clear
thinking about job lifetimes.
2012-04-20 17:12:27 +02:00
Michal Schmidt 121b3b3180 manager: simplify transaction_abort()
This is equivalent.
2012-04-20 17:12:27 +02:00
Michal Schmidt 02a3bcc6b4 job: allow job_free() only on already unlinked jobs
job_free() is IMO too helpful when it unlinks the job from the transaction.
The callers should ensure the job is already unlinked before freeing.
The added assertions check if anyone gets it wrong.
2012-04-20 17:12:27 +02:00
Michal Schmidt 153bda8f03 manager: fix comment 2012-04-20 17:12:27 +02:00
Lennart Poettering b59e246565 logind: remove redundant entries from logind's default controller lists too 2012-04-16 19:15:00 +02:00
Lennart Poettering 9156e799a2 manager: remove unavailable/redundant entries from default controllers list 2012-04-16 18:59:07 +02:00
Lennart Poettering c757a65b6a watchdog: make watchdog dbus properties writable 2012-04-13 21:37:59 +02:00
Lennart Poettering 44785992c3 audit: ignore if we get EPERM
if auditing access is not available, then don't complain about it, in
order to play nice with systems lacking CAP_SYS_AUDIT
2012-04-13 18:52:53 +02:00
Lennart Poettering a41b539efc manager: support systems lacking /dev/tty0 2012-04-13 18:52:52 +02:00
Lennart Poettering 7ea07dcdda fix a couple of things found with the llvm static analyzer 2012-04-13 13:58:50 +02:00
Lennart Poettering 5430f7f2bc relicense to LGPLv2.1 (with exceptions)
We finally got the OK from all contributors with non-trivial commits to
relicense systemd from GPL2+ to LGPL2.1+.

Some udev bits continue to be GPL2+ for now, but we are looking into
relicensing them too, to allow free copy/paste of all code within
systemd.

The bits that used to be MIT continue to be MIT.

The big benefit of the relicensing is that closed source code may now
link against libsystemd-login.so and friends.
2012-04-12 00:24:39 +02:00
Kay Sievers b30e2f4c18 move libsystemd_core.la sources into core/ 2012-04-11 16:03:51 +02:00
Renamed from src/manager.c (Browse further)