Commit Graph

33877 Commits

Author SHA1 Message Date
Lennart Poettering ec6bdf7259 copy: rework copy_file_atomic() to copy the specified file via O_TMPFILE if possible 2018-06-07 17:40:14 +02:00
Lennart Poettering 3f40303993 util: allow mkdtemp_malloc() to be called with NULL pattern
In that case simply place the directory in /tmp.
2018-06-07 17:38:49 +02:00
Lennart Poettering c640710883 update TODO
The three ancient entries marked "bugfixes" are already fixed (in two
cases), or are not really bugs (in the other case). Let's clean this up
a bit.
2018-06-07 17:36:01 +02:00
Lennart Poettering 3ceca73a59
Merge pull request #9200 from poettering/device-state-fix
core: rework device state serialization/enumeration
2018-06-07 17:04:57 +02:00
Lennart Poettering ce3ec07f41
Merge pull request #9165 from ssahani/networkd-netdevsim
networkd: introduce netdev "Netdevsim" Driver
2018-06-07 16:56:32 +02:00
Zbigniew Jędrzejewski-Szmek d40f5cc498 CODING_STYLE: allow c99-style mixed code and declarations
We already allowed variables to be declared in the middle of a function
(whenever a new scope was opened), so this isn't such a big change. Sometimes
we would open a scope just to work around this prohibition.

But sometimes the code can be much clearer if the variable is declared
somewhere in the middle of a scope, in particular if the declaration is
combined with initialization or acquisition of some resources. So let's allow
this, but keep things in the old style, unless there's a good reason to move
the variable declaration to a different place.
2018-06-07 16:42:34 +02:00
Zbigniew Jędrzejewski-Szmek e02a33c2b7
Merge pull request #9222 from poettering/code-quality-docs
let's document the code quality tools we have set up
2018-06-07 16:30:56 +02:00
Lennart Poettering ecb462dbf5 HACKING: link up CODE_QUALITY.md 2018-06-07 16:26:00 +02:00
Lennart Poettering 7c2c028c85 doc: add a list of code quality tools we have set up
Also, as a reminder all of these exist to myself.
2018-06-07 16:22:22 +02:00
Lennart Poettering 12b74c38e2 tools: make various scripts find the top-levle git dir automatically 2018-06-07 16:22:16 +02:00
Lennart Poettering bb527e1137 update TODO 2018-06-07 15:29:17 +02:00
Lennart Poettering cb209a0489 swap: trivial log message improvements 2018-06-07 15:29:17 +02:00
Lennart Poettering a7f8be01aa core: be a bit stricter when validating SYSTEMD_ALIAS udev props 2018-06-07 15:29:17 +02:00
Lennart Poettering b8b846d7b4 tree-wide: fix a number of log calls that use %m but have no errno set
This is mostly fall-out from d1a1f0aaf0,
however some cases are older bugs.

There might be more issues lurking, this was a simple grep for "%m"
across the tree, with all lines removed that mention "errno" at all.
2018-06-07 15:29:17 +02:00
Lennart Poettering 04eb582acc core: enumerate perpetual units in a separate per-unit-type method
Previously the enumerate() callback defined for each unit type would do
two things:

1. It would create perpetual units (i.e. -.slice, system.slice, -.mount and
   init.scope)

2. It would enumerate units from /proc/self/mountinfo, /proc/swaps and
   the udev database

With this change these two parts are split into two seperate methods:
enumerate() now only does #2, while enumerate_perpetual() is responsible
for #1. Why make this change? Well, perpetual units should have a
slightly different effect that those found through enumeration: as
perpetual units should be up unconditionally, perpetually and thus never
change state, they should also not pull in deps by their state changing,
not even when the state is first set to active. Thus, their state is
generally initialized through the per-device coldplug() method in
similar  fashion to the deserialized state from a previous run would be
put into place. OTOH units found through regular enumeration should
result in state changes (and thus pull in deps due to state changes),
hence their state should be put in effect in the catchup() method
instead. Hence, given this difference, let's also separate the
functions, so that the rule is:

1. What is created in enumerate_perpetual() should be started in
   coldplug()

2. What is created in enumerate() should be started in catchup().
2018-06-07 15:29:17 +02:00
Lennart Poettering 244f805549 core: tighten when we unset the sysfs path of device units
Make sure that whenever we enter "dead" state we unset the sysfs path,
not just when we are changing to it due to "found" mask changes.
2018-06-07 15:29:17 +02:00
Lennart Poettering 66f3fdbb07 core: rework how device units get set up
This reworks how device units are "powered on".

This makes sure that any device changes that might have happened while
we were restarting/reloading will be noticed properly. For that we'll
now properly serialize/deserialize both the device unit state and the
device "found" flags, and restore these initially in the "coldplug"
phase of the manager deserialization. While enumerating the udev devices
during startup we'll put together a new "found" flags mask, which we'll
the switch to in the "catchup" phase of the manager deserialization,
which follows the "coldplug" phase.

Note that during the "coldplug" phase no unit state change events are
generated, which is different for the "catchall" phase which will do
that. Thus we correctly make sure that the deserialized state won't pull
in new deps, but any device's change while we were reloading would.

Fixes: #8832
Replaces: #8675
2018-06-07 15:29:17 +02:00
Lennart Poettering 69ce73d18d device: simplify device_found_to_string_many() a tiny bit
No need to maintain a NULL marker at the end of the table if we know the
size of the array anyway.
2018-06-07 15:28:50 +02:00
Lennart Poettering f0831ed2a0 core: add a new unit method "catchup()"
This is very similar to the existing unit method coldplug() but is
called a bit later. The idea is that that coldplug() restores the unit
state from before any prior reload/restart, i.e. puts the deserialized
state in effect. The catchup() call is then called a bit later, to
catch up with the system state for which we missed notifications while
we were reloading. This is only really useful for mount, swap and device
mount points were we should be careful to generate all missing unit
state change events (i.e. call unit_notify() appropriately) for
everything that happened while we were reloading.
2018-06-07 15:28:50 +02:00
Lennart Poettering 62b0cbb358 core: use safe_fclose() where appropriate 2018-06-07 13:36:19 +02:00
Lennart Poettering 159f1e7666 core: split out early-boot preset logic into a function of its own 2018-06-07 13:36:19 +02:00
Lennart Poettering e5ca27b772 udev: add helper udev_device_new_from_stat_rdev()
This is a simple wrapper around udev_device_new_from_devnum(), and uses
the data from a struct stat's .st_rdev field to derive the udev_device
object.
2018-06-07 13:36:19 +02:00
Lennart Poettering 34c20ee09f core: split out device validation from device_found_node()
Let's separate the validate step out. Also, let's update some comments
which have long ceased to be true.

No change in behaviour.
2018-06-07 13:36:19 +02:00
Lennart Poettering 485ae697ba core: rework device_found_node() prototype
let's drop the "now" argument, it's exactly what MANAGER_IS_RUNNING()
returns, hence let's use that instead to simplify things.

Moreover, let's change the add/found argument pair to become found/mask,
which allows us to change multiple flags at the same time into opposing
directions, which will be useful later on.

Also, let's change the return type to void. It's a notifier call where
callers will ignore the return value anyway as it is nothing actionable.

Should not change behaviour.
2018-06-07 13:36:19 +02:00
Lennart Poettering 87934b36b1 core: split out reload propagation into its own function 2018-06-07 13:36:19 +02:00
Lennart Poettering 8bb2c8c94d core: improve error logging a bit 2018-06-07 13:36:19 +02:00
Lennart Poettering 9d4c195c64 core: split out bus initialization from manager_setup() 2018-06-07 13:36:19 +02:00
Lennart Poettering 86cdffd106 core: log when unit_add_dependency() fails for some reason
Also, proceed, as there's little we can do in this case.
2018-06-07 13:36:19 +02:00
Lennart Poettering ea8ec43bb5 core: modernize device_update_description() a bit 2018-06-07 13:36:19 +02:00
Lennart Poettering 43ba7d71e5 core: use device_found_to_string_many() result only on success 2018-06-07 13:36:19 +02:00
Lennart Poettering 6e0f878ee2 core: use FLAGS_SET() macro at one more place 2018-06-07 13:36:19 +02:00
Lennart Poettering ccd419f0e7 core: modernize device_set_sysfs() a bit 2018-06-07 13:36:19 +02:00
Alessandro Casale b47837ac41 hwdb: HP ZBook Studio G4 wireless switch 2018-06-07 13:13:47 +02:00
Stefan Schweter 6a1bae8381 man: update url to latest 802.1AB (2016) standard 2018-06-07 10:30:23 +02:00
Lennart Poettering 81474cd4d3
Merge pull request #9208 from keszybz/async-callback-memleak
Async callback memleak fix and documentation cleanups
2018-06-07 10:29:05 +02:00
Lennart Poettering ef43c8b877
Merge pull request #9214 from poettering/systemctl-get-processes-fix
two small fixes for systemctl's process tree display
2018-06-07 09:17:01 +02:00
Ivan Shapovalov 35a14d754a hwdb: Logitech Anywhere MX wheel data (#9203) 2018-06-07 08:51:42 +10:00
Zbigniew Jędrzejewski-Szmek 869881a6cb test-bus-util: add a test for destroy callbacks 2018-06-06 23:01:57 +02:00
Zbigniew Jędrzejewski-Szmek 200bc75db9 shared/bus-util: use the new cleanup functionality to avoid a memleak
If the async callbacks didn't get a chance to finish properly, we'd leak
memory.

The output from test-bus-util with additional log line in the callbacks to show
what is happening:

$ build/test-bus-util

/* test_name_async (0) */
Bus test-bus: changing state UNSET → OPENING
Bus test-bus: changing state OPENING → AUTHENTICATING
Bus test-bus: changing state AUTHENTICATING → HELLO
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=2 reply_cookie=0 signature=su error-name=n/a error-message=n/a
Got message type=method_return sender=org.freedesktop.DBus destination=:1.732 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1 signature=s error-name=n/a error-message=n/a
Bus test-bus: changing state HELLO → RUNNING
Bus test-bus: changing state RUNNING → CLOSED
request_name_destroy_callback n_ref=1

/* test_name_async (20) */
Bus test-bus: changing state UNSET → OPENING
Bus test-bus: changing state OPENING → AUTHENTICATING
Bus test-bus: changing state AUTHENTICATING → HELLO
stage 0: sd_bus_process returned 1
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=2 reply_cookie=0 signature=su error-name=n/a error-message=n/a
stage 1: sd_bus_process returned 1
Got message type=method_return sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1 signature=s error-name=n/a error-message=n/a
Bus test-bus: changing state HELLO → RUNNING
stage 2: sd_bus_process returned 1
Got message type=signal sender=org.freedesktop.DBus.Local destination=n/a path=/org/freedesktop/DBus/Local interface=org.freedesktop.DBus.Local member=Connected cookie=4294967295 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
stage 3: sd_bus_process returned 1
Got message type=signal sender=org.freedesktop.DBus destination=:1.733 path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameAcquired cookie=4294967295 reply_cookie=0 signature=s error-name=n/a error-message=n/a
stage 4: sd_bus_process returned 1
Got message type=error sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=2 signature=s error-name=org.freedesktop.DBus.Error.AccessDenied error-message=Request to own name refused by policy
Unable to request name, will retry after reloading DBus configuration: Request to own name refused by policy
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=ReloadConfig cookie=3 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
request_name_destroy_callback n_ref=2
stage 5: sd_bus_process returned 1
Got message type=method_return sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=3 signature= error-name=n/a error-message=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=4 reply_cookie=0 signature=su error-name=n/a error-message=n/a
request_name_destroy_callback n_ref=1
stage 6: sd_bus_process returned 1
Got message type=error sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=4 signature=s error-name=org.freedesktop.DBus.Error.AccessDenied error-message=Request to own name refused by policy
Unable to request name, failing connection: Request to own name refused by policy
Bus test-bus: changing state RUNNING → CLOSING
stage 7: sd_bus_process returned 1
Bus test-bus: changing state CLOSING → CLOSED
stage 8: sd_bus_process returned 1
stage 9: sd_bus_process returned -104
Processing failed: Connection reset by peer
2018-06-06 23:01:57 +02:00
Zbigniew Jędrzejewski-Szmek fa17b4e8d9 bus: optionally call a callbacks for cleanup
This adds a function sd_bus_slot_set_destroy_callback() to set a function
which can free userdata or perform other cleanups.

sd_bus_slot_get_destory_callback() queries the callback, and is included
for completeness.

Without something like this, for floating asynchronous callbacks, which might
be called or not, depending on the sequence of events, it's hard to perform
resource cleanup. The alternative would be to always perform the cleanup from
the caller too, but that requires more coordination and keeping of some shared
state. It's nicer to keep the cleanup contained between the callback and the
function that requests the callback.
2018-06-06 23:01:57 +02:00
Zbigniew Jędrzejewski-Szmek e3736e0223 man: also mention EINVAL in sd_bus_slot_set_floating(3) 2018-06-06 23:01:25 +02:00
Zbigniew Jędrzejewski-Szmek 24924cc959 test-bus-util: add a simple test for bus_request_name_async_may_reload_dbus()
This shows a minor memleak:
==1883== 24 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1883==    at 0x4C2DBAB: malloc (vg_replace_malloc.c:299)
==1883==    by 0x4E9D385: malloc_multiply (alloc-util.h:69)
==1883==    by 0x4EA2959: bus_request_name_async_may_reload_dbus (bus-util.c:1841)
==1883==    by ...

The exchange of messages is truncated at two different points: once right
after the first callback is requested, and the second time after the full
sequence has run (usually resulting in an error because of policy).
2018-06-06 23:01:25 +02:00
Zbigniew Jędrzejewski-Szmek 83b6c1a6b1 bus-util: avoid unneeded initalization to zero 2018-06-06 23:01:25 +02:00
Zbigniew Jędrzejewski-Szmek 7d6b27238f man: xinclude the generic text to talk about libsystemd pkgconfig
The only difference is that functions are not individually listed by name,
but that seems completely pointless, since all functions that are documented
are always exported, so the generic text tells the user all she or he needs
to know.
2018-06-06 23:01:25 +02:00
Zbigniew Jędrzejewski-Szmek d5e9c5a2cd
Merge pull request #9201 from poettering/integration-test-unfuck
make the integration tests great again
2018-06-06 21:02:13 +02:00
Lennart Poettering 24715314fb pid: fix ENOENT error check 2018-06-06 20:22:41 +02:00
Lennart Poettering 950d6889c3 systemctl: when GetProcesses() doesn't work, say for which unit 2018-06-06 19:46:23 +02:00
Lennart Poettering 81f6d448ef
Merge pull request #9212 from keszybz/null-removal-part-two
Small follow-up to log_struct NULL removal
2018-06-06 17:18:19 +02:00
Zbigniew Jędrzejewski-Szmek bb74418bf1
Merge pull request #9197 from poettering/make-main-shorter
some smaller changes to make PID1's main() a bit shorter
2018-06-06 16:05:41 +02:00
Zbigniew Jędrzejewski-Szmek 2cda08fdf3 resolved: reformat message about a revoked trust anchor
LOG_MESSAGE is just a wrapper, but it keeps the arguments indented together
with the format string, so put the argument inside of the macro invocation.
(No functional change.)

Also use lowercase for "trust anchor" — it should either be all capitaled or not
at all, and it's not a proper name, so let's make it all lowercase.
Also, add a newline, to make the string more readable. "%s" can expand to
something that is quite long.
2018-06-06 14:55:31 +02:00