Commit graph

131 commits

Author SHA1 Message Date
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 5d904a6aaa tree-wide: drop !! casts to booleans
They are not needed, because anything that is non-zero is converted
to true.

C11:
> 6.3.1.2: When any scalar value is converted to _Bool, the result is 0 if the
> value compares equal to 0; otherwise, the result is 1.

https://stackoverflow.com/questions/31551888/casting-int-to-bool-in-c-c
2018-06-13 10:52:40 +02:00
Filipe Brandenburger df560cf6b1 analyze: use _cleanup_ for struct unit_times
This introduces a has_data boolean field in struct unit_files which can
be used to detect the end of the array.

Use a _cleanup_ for struct unit_files in acquire_time_data and its
callers. Code for acquire_time_data is also simplified by replacing
goto's with straight returns.

Tested: By running the commands below, also checking them under valgrind.
  - build/systemd-analyze blame
  - build/systemd-analyze critical-chain
  - build/systemd-analyze plot

Fixes: Coverity finding CID 996464.
2018-06-08 15:46:07 +02:00
David Tardon c0a1bfacfe systemd-analyze: make dump work for large # of units
If there is a large number of units, the size of the generated dump
string can overstep DBus message size limit. So let's pass that string
via a fd.
2018-05-11 08:11:02 -07:00
Lennart Poettering cb91deaf77 terminal-util: add a function that shows a pretty separator line
Follow-up for #8824
2018-05-11 08:15:33 +02:00
Lennart Poettering 81321f51cf
Merge pull request #8824 from keszybz/analyze-show-config
systemd-analyze show-config
2018-05-10 11:14:23 -07:00
Yu Watanabe fb507898a3 bus-util: print a friendly message when PID1 is not systemd
Follow-up for 861f16d267.

Fixes #8913.
2018-05-09 17:07:37 +09:00
Yu Watanabe f7e2933677 analyze: merge acquire_full_bus() and acquire_systemd_bus()
Follow-up for 5c69b31c13.
2018-05-09 17:07:37 +09:00
Zbigniew Jędrzejewski-Szmek 971f6ea551 analyze: allow full paths for cat-config
$ systemd-analyze cat-config systemd/logind.conf
$ systemd-analyze cat-config /etc/systemd/logind.conf
$ systemd-analyze cat-config /usr/lib/systemd/logind.conf
are all equvalent,
$ systemd-analyze cat-config /var/systemd/logind.conf
is an error.
2018-05-07 18:17:36 +02:00
Zbigniew Jędrzejewski-Szmek 2e1ec10a62 analyze: seperate config file groups by underline
When multiple configuration file groups are shown together (e.g.
systemd-analyze cat-config systemd/system.conf systemd/user.conf), it's nice
to separate them visually.

I tried first to write a line of spaces and underline that. This does not look
too good, because the line is too low. Then I tried a block of blue-background
spaces. In this version, there are two lines, one is full of spaces and
underlined, so visually we get an empty line in the middle.

I then tried underlining the last line of the previous file. This does not look
right, unless the line is full width, i.e. unless spaces are written out until
the end of the line. But when those spaces are added, it's not clear if they
were part of the original file or not. Here, the spaces are between groups, so
it seems less likely that somebody will mistake those spaces for part of the
configuration file.
2018-05-07 18:15:29 +02:00
Zbigniew Jędrzejewski-Szmek 46d8646a9f analyze: add --root option for cat-config 2018-04-27 10:06:24 +02:00
Zbigniew Jędrzejewski-Szmek 854a42fb2e analyze: add 'cat-config' verb
This is used as 'systemd-analyze show-config systemd/logind.conf', which
will dump
   /etc/systemd/system/user@.service
   /etc/systemd/system/user@.service.d/*.conf
   /run/systemd/system/user@.service.d/*.conf
   /usr/local/lib/systemd/system/user@.service.d/*.conf
   /usr/lib/systemd/system/user@.service.d/*.conf

The idea is to make it easy to dump the configuration using the same locations
and order that systemd programs use themselves (including masking, in the right
order, etc.). This is the generic variant that works with any configuration
scheme that follows the same general rules:

$ systemd-analyze cat-config systemd/system.conf
$ systemd-analyze cat-config systemd/user.conf
$ systemd-analyze cat-config systemd/logind.conf
$ systemd-analyze cat-config systemd/sleep.conf
$ systemd-analyze cat-config systemd/journald.conf
$ systemd-analyze cat-config systemd/journal-remote.conf
$ systemd-analyze cat-config systemd/journal-upload.conf
$ systemd-analyze cat-config systemd/coredump.conf
$ systemd-analyze cat-config systemd/resolved.conf
$ systemd-analyze cat-config systemd/timesyncd.conf
$ systemd-analyze cat-config udev/udev.conf
2018-04-27 10:06:24 +02:00
Lennart Poettering 8e766630f0 tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.

In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.

Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.

Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.

Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00
Lennart Poettering 4d09e1c8ba
Merge pull request #8676 from keszybz/drop-license-boilerplate
Drop license boilerplate
2018-04-10 14:53:31 +02:00
Zbigniew Jędrzejewski-Szmek 1e9f0ccadf analyze: give a hint what is it means that boot is still active
$ build/systemd-analyze time
Bootup is not yet finished (org.freedesktop.systemd1.Manager.FinishTimestampMonotonic=0).
Please try again later.
Hint: Use 'systemctl list-jobs' to see active jobs
2018-04-07 20:05:58 +02:00
Guillem Jover 5c69b31c13 analyze: Do no require a full d-bus bus for the plot command (#8539)
The plot command requires a full d-bus bus to fetch the host
information, which seems rather optional, and having a running dbus
daemon is not always desirable. So instead, we try to acquire a full
bus, and if that fails we acquire the systemd bus, in which case we
omit the host information from the output.

We refactor acquire_bus() into two new functions which in addition
makes the call sites clearer.
2018-04-07 20:02:20 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Yu Watanabe a7e4861c74 bus-util: add flags for bus_map_all_properties() (#8546)
This adds flags BUS_MAP_STRDUP and BUS_MAP_BOOLEAN_AS_BOOL.
If BUS_MAP_STRDUP is set, then each "s" message is duplicated.
If BUS_MAP_BOOLEAN_AS_BOOL is set, then each "b" message is
written to a bool pointer.

Follow-up for #8488.
See https://github.com/systemd/systemd/pull/8488#discussion_r175816270.
2018-03-28 13:37:27 +02:00
Yu Watanabe f37f8a61c0 bus-util: make bus_map_all_properties() not copy string 2018-03-20 00:42:48 +09:00
Yu Watanabe ee5324aa04 tree-wide: voidify pager_open()
Even if pager_open() fails, in general, we should continue the operations.
All erroneous cases in pager_open() show log message in the function.
So, it is not necessary to check the returned value.
2018-03-19 21:04:02 +09:00
Douglas Christman 3a6a6889e1 analyze: fix typo in error message 2018-03-01 21:50:38 +08:00
Zbigniew Jędrzejewski-Szmek 94e91c8319 analyze: fix typo in error message 2018-02-13 10:03:09 +01:00
Zbigniew Jędrzejewski-Szmek 230cc99a0f analyze: slight simplification 2018-02-09 12:27:34 +01:00
Zbigniew Jędrzejewski-Szmek baa4880bac analyze: remove implicit conversions of numbers to booleans 2018-02-09 12:27:34 +01:00
Zbigniew Jędrzejewski-Szmek 31a5924ed8 analyze: add unit-paths verb 2018-02-09 12:27:27 +01:00
Zbigniew Jędrzejewski-Szmek 28b35ef23a analyze: add --global option
This is somewhat useful for 'verify', and will be used later with 'unit-paths'.
2018-02-08 16:35:24 +01:00
Boucman d21b0c826f do not report total time when kernel time is not provided (#8063)
the whole systemd-analyze time logic is based on the fact that monotonic
time 0 is the start of the kernel.

If the firmware does not provide a correct time, firmware_time degrades to
0, which is the start of the kernel. The diference between FinishTime and
firmware_time is thus correct.

That assumption is still true with containers, but the start time of the
kernel is not what the user expects : It's the time when the host booted.

The total is thus still correct, but highly misleading. Containers can be
easily detected (and, in fact, already are) by systemd not reporting any
kernel non-monotonic timestamp.

This patch simply avoids printing a misleading time when it can detect that
case
2018-02-02 15:58:40 +01:00
Yu Watanabe 90657286fc analyze: merge {get,set}-log-{level,target} to log-{level,target} (#8020)
Also, service-watchdogs now shows current watchdog state when
no optional argument is provided.
2018-01-27 13:51:32 +01:00
Jan Klötzke 889d695d6c systemd-analyze: add service-watchdogs verb
New debug verb that enables or disables the service runtime watchdogs
and emergency actions during runtime. This is the systemd-analyze
version of the systemd.service_watchdogs command line option.
2018-01-22 18:10:12 +01:00
Boucman da933f7dcf fix systemd-analyze time when default.target is not reached (#7764)
Also, better error messages.
2018-01-03 15:52:13 +01:00
Lennart Poettering ad552e587f analyze: fix prototype mismatch on libseccomp-less builds (#7768)
This fixes a compiler warning that matters, if people build systemd
without libseccomp.

Follow-up for a6bcef2957
2018-01-01 13:24:41 +09:00
Lennart Poettering bc6695ec7e analyze: correct help text where we take unit name arguments 2017-12-26 16:04:10 +01:00
Lennart Poettering 8486c92394 analyze: fix indentation in one case 2017-12-26 16:04:10 +01:00
Lennart Poettering 8efbce138a analyze: add some logging to some error cases 2017-12-26 16:04:10 +01:00
Lennart Poettering f72b7018d2 analyze: arg_host can be "const char*", hence make it so. 2017-12-26 16:04:10 +01:00
Lennart Poettering a6bcef2957 analyze: port verb dispatching to verbs.[ch] API
Let's unify the code for parsing command line verbs, and reuse the
common verbs.[ch] API in systemd-analyze too.

This adds a couple of error messages when people pass too many
arguments. Moreover thus pushes bus allocation into the verb functions,
which corrects a couple of cases where we previously allocated a bus but
really didn't need to.

Other than that behaviour shouldn't really change.
2017-12-26 16:04:10 +01:00
Zbigniew Jędrzejewski-Szmek bf0e0a4df2 analyze: use normal bus connection for "plot" verb (#7685)
We need to connect to hostnamed, so a private bus connection is no good.
It'd be simpler to use the normal bus connection unconditionally, but
that'd mean that e.g. systemd-analyze set-log-level might not work in
emergency mode. So let's keep trying to use the private connection except
for "plot".

Fixes #7667.
2017-12-18 19:35:03 +01:00
Lennart Poettering 234519ae6d tree-wide: drop a few == NULL and != NULL comparison
Our CODING_STYLE suggests not comparing with NULL, but relying on C's
downgrade-to-bool feature for that. Fix up some code to match these
guidelines. (This is not comprehensive, the coccinelle output for this
is unfortunately kinda borked)
2017-12-11 16:05:40 +01:00
Boucman bd07d3d0b4 Print the time to reach default.target in systemd-analyze time (#7383)
Example output (last line is new):
$ systemd-analyze time
Startup finished in 12.879s (firmware) + 36.999s (loader) + 1.313s (kernel) + 22.672s (initrd) + 3min 1.755s (userspace) = 4min 15.619s
graphical.target reached after 1min 39.377s in userspace
2017-12-05 10:20:40 +01:00
Lennart Poettering 6d86f4bd11 analyze: add new "calendar" command
This little new command can parse, validate, normalize calendar events,
and calculate when they will elapse next. This should be useful for
anyone writing calendar events and who'd like to validate the expression
before running them as timer units.
2017-11-20 10:57:41 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Zbigniew Jędrzejewski-Szmek 641c0fd14e analyze-verify: add --generators switch to enable generators again 2017-09-19 20:14:22 +02:00
Lucas Werkmeister ef5a8cb1a7 analyze: add get-log-level, get-log-target verbs
They’re counterparts to the existing set-log-level and set-log-target
verbs, simply printing the current value to stdout. This makes it
slightly easier to temporarily change the log level and/or target and
then restore the old value(s).
2017-09-07 23:55:59 +02:00
Zbigniew Jędrzejewski-Szmek 948aaa7c52 tree-wide: standardize on $(PACKAGE_VERSION) for the version string
We defined both $(VERSION) and $(PACKAGE_VERSION) with the same contents.
$(PACKAGE_VERSION) is slightly more descriptive, so settle on that, and
drop the other define.
2017-04-04 20:36:09 -04:00
Lucas Werkmeister cc7de2ba32 tree-wide: add man: to manpage references (#5402)
Found with:

    git grep '"[^"]*[a-z0-9]([0-9]\+p\?)' src/ | grep -vF man:
2017-02-20 18:45:35 -05:00
Lennart Poettering f9e0eefc7c tree-wide: make bus_map_all_properties return a proper sd_bus_error
And then show it, to make things a bit friendlier to the user if we fail
acquiring some props.

In fact, this fixes a number of actual bugs, where we used an error
structure for output that we actually never got an error in.
2017-02-09 16:13:07 +01:00