Commit Graph

92 Commits

Author SHA1 Message Date
Lennart Poettering 39cf0351c5 tree-wide: make use of new relative time events in sd-event.h 2020-07-28 11:24:55 +02:00
Lennart Poettering fb29cdbef2 tree-wide: make sure our control buffers are properly aligned
We always need to make them unions with a "struct cmsghdr" in them, so
that things properly aligned. Otherwise we might end up at an unaligned
address and the counting goes all wrong, possibly making the kernel
refuse our buffers.

Also, let's make sure we initialize the control buffers to zero when
sending, but leave them uninitialized when reading.

Both the alignment and the initialization thing is mentioned in the
cmsg(3) man page.
2020-05-07 14:39:44 +02:00
Lennart Poettering 3691bcf3c5 tree-wide: use recvmsg_safe() at various places
Let's be extra careful whenever we return from recvmsg() and see
MSG_CTRUNC set. This generally means we ran into a programming error, as
we didn't size the control buffer large enough. It's an error condition
we should at least log about, or propagate up. Hence do that.

This is particularly important when receiving fds, since for those the
control data can be of any size. In particular on stream sockets that's
nasty, because if we miss an fd because of control data truncation we
cannot recover, we might not even realize that we are one off.

(Also, when failing early, if there's any chance the socket might be
AF_UNIX let's close all received fds, all the time. We got this right
most of the time, but there were a few cases missing. God, UNIX is hard
to use)
2020-04-23 09:41:47 +02:00
Zbigniew Jędrzejewski-Szmek 105a1a36cd tree-wide: fix spelling of lookup and setup verbs
"set up" and "look up" are the verbs, "setup" and "lookup" are the nouns.
2020-03-03 15:02:53 +01:00
Lennart Poettering ce96c9cb1a timesyncd: log louder when we refuse a server due to root distance
This is something people should know about, since it's caused by
misconfiguration.

Fixes: #13912
2020-01-21 15:20:17 +01:00
Yu Watanabe 92133d2878 tree-wide: drop socket.h when socket-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe f21e58b47d tree-wide: drop time.h when time-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe f5947a5e92 tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
cbzxt 37afb0ac78 Updated log message when the timesync happens for the first time (#13624) 2019-09-26 00:02:46 +09:00
Zbigniew Jędrzejewski-Szmek 8c227e7f2b Drop RATELIMIT macros
Using plain structure initialization is both shorter _and_ more clearer.
We get type safety for free.
2019-09-20 16:05:53 +02:00
Frantisek Sumsal 55033662f9 tree-wide: drop !! casts to booleans
Done by coccinelle/bool-cast.cocci
2019-04-28 14:32:19 +02:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Niklas Hambüchen 3a1e46f7ae timesyncd: Improve sync log message. Fixes #11548.
This makes it clear that the user should not expect more log messages
each time the time is synchronised.
2019-01-24 23:52:24 +01:00
Lennart Poettering 92e31da100 tree-wide: make sure to flush/close all bus connections when our daemons exit
Let's make sure everything is written out ebfore we exit, so that no
messages keep our bus connections referenced.

Fixes: #11462
2019-01-17 16:12:38 +01:00
Yu Watanabe 7082bb05ad timesync: use typesafe resolve_getaddrinfo() 2018-12-17 10:02:36 +09:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Yu Watanabe 14cb109d45 tree-wide: replace 'unsigned int' with 'unsigned' 2018-10-19 22:19:12 +02:00
Yu Watanabe 9e5b649655 tree-wide: use setsockopt_int() more 2018-10-19 05:52:42 +09:00
Lennart Poettering 2ff48e981e tree-wide: introduce setsockopt_int() helper and make use of it everywhere
As suggested by @heftig:

6d5e65f645 (commitcomment-30938667)
2018-10-18 19:50:29 +02:00
Lennart Poettering 6d5e65f645 tree-wide: add a single version of "static const int one = 1"
All over the place we define local variables for the various sockopts
that take a bool-like "int" value. Sometimes they are const, sometimes
static, sometimes both, sometimes neither.

Let's clean this up, introduce a common const variable "const_int_one"
(as well as one matching "const_int_zero") and use it everywhere, all
acorss the codebase.
2018-10-15 19:40:51 +02:00
Yu Watanabe 8b7140dbd0 timesync: voidify sd_event_add_signal() and sd_event_set_watchdog() 2018-07-20 11:30:11 +09:00
Yu Watanabe a9061d97a7 timesync: update log message
Fixes #9388.
2018-06-25 10:27:18 +02:00
Yu Watanabe 75ca1621db timesync: changes type of drift_freq to int64_t
drift_freq is used for storing timex.freq, and is a 64bit integer.
To support x32 ABI, this changes the type of drift_freq to int64_t.

Fixes #9387.
2018-06-25 10:27:18 +02:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
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
Yu Watanabe ba0c011eee timesync: add more log messages in manager_network_read_link_servers() 2018-06-13 14:05:26 +09:00
Yu Watanabe dcb37458cb timesync: check validity of NTP server name or address 2018-06-13 13:51:17 +09:00
Lennart Poettering 4f811d27d6 time-util: introduce common implementation of TFD_TIMER_CANCEL_ON_SET client code
We now use pretty much the same code at three places, let's unify that.
2018-06-06 10:55:45 +02:00
Zbigniew Jędrzejewski-Szmek 7994ac1d85 Rename ratelimit_test to ratelimit_below
When I see "test", I have to think three times what the return value
means. With "below" this is immediately clear. ratelimit_below(&limit)
sounds almost like English and is imho immediately obvious.

(I also considered ratelimit_ok, but this strongly implies that being under the
limit is somehow better. Most of the times this is true, but then we use the
ratelimit to detect triple-c-a-d, and "ok" doesn't fit so well there.)

C.f. a1bcaa07.
2018-05-13 22:08:30 +02:00
Yu Watanabe 66086a4030 timesync: save and expose NTP responce on bus 2018-05-03 18:05:14 +09:00
Yu Watanabe e7dd394767 timesync: expose manager properties on bus 2018-05-03 18:05:14 +09:00
Yu Watanabe 0630eb1bcc timesync: establish connection when network become online and the manager is not connected yet (#8727)
This also introduces `manager_is_connected()` helper function, which
returns true when the manager is sending a request, resolving a server
name, or in a poll interval.

Follow-up for 3e85ec0721.
Fixes #8719.
2018-04-17 20:56:12 +02:00
Peter A. Bigot 2dd79846dd time-wait-sync: use watchfile to coordinate with timesyncd
Systems that have an accurate real-time clock may have an initial
unsynchronized time that is close enough to the synchronized time that
the final adjustment doesn't trigger a waking "clock set" event.  Have
timesyncd touch a file in its runtime directory as a secondary signal
for synchronization.  Continue to support the timerfd-based trigger as a
sufficient condition when the watchfile is not present.

Closes issue #8683
2018-04-14 09:52:40 -05: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 3e85ec0721 timesync: on network event do not establish connection when NTP servers are not changed (#8611)
Fixes #8603.
2018-03-29 16:15:56 +02:00
Zbigniew Jędrzejewski-Szmek edd50d5e24 timesyncd: avoid signed/unsigned comparison (#7842)
be32toh() returns uint32_t, and m->trans_time.tv_nsec is defined as long in struct timespec.
Let's add a cast to avoid the warning.

Fixes #7789.
2018-01-10 11:35:00 +01:00
Lennart Poettering f95b0be742 man: "systemd" is to be written in all lower-case, even at beginnings of sentences
This very important commit is very important.
2017-12-13 17:42:04 +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
Yu Watanabe a4465d0d4c timesync: make poll interval configurable
This adds PollIntervalMinSec= and PollIntervalMaxSec= to timesyncd.conf

Closes #7262.
2017-11-08 01:47:38 +09:00
Yu Watanabe f907cc1620 timesync: add RootDistanceMaxSec= to timesyncd.conf (#7215)
Closes #7211.
2017-11-05 07:39:34 +01:00
Yu Watanabe 53d133ea1b timesync: move stamp file to /var/lib/systemd/timesync/clock 2017-08-30 15:59:57 +09:00
Torstein Husebø ed88a9007a treewide: fix typos (#6566) 2017-08-08 10:05:29 -04:00
Zbigniew Jędrzejewski-Szmek 36484c0341 test-timesync: ignore failure to listen on /run/systemd/netif/links/ (#6463)
Fixes #6353.
2017-07-28 09:33:43 +02:00
Michael Biebl 3745770ae4 timesyncd: don't use compiled-in list if FallbackNTP has been configured explicitly
Parse the config files first and only apply the compiled-in list of
fallback servers if no NTP server was configured via FallbackNTP.

Closes: #5091
2017-05-24 17:45:46 +02:00
Matija Skala 0060bb8f5b timesync/timesyncd-manager: fix format-specifier issue
timex::time::tv_sec can have different sizes depending on the
host architecture. On x32 in particular, it is 8 bytes
long while the long int type is only 4 bytes  long. Hence,
using li as a format specifier will trigger a format
error. Thus, better use PRI_TIME instead of li which is
actually the right format specifier to use for time_t.
2017-05-19 14:40:07 +02:00
Matija Skala 3bd7ef833c timesync/timesyncd-manager: fix format-specifier issues
timex::time::tv_usec and timex::freq can have different sizes
depending on the host architecture. On x32 in particular,
it is 8 bytes long while the long int type is only 4 bytes
long. Hence, using li as a format specifier will trigger
a format error. Thus, introduce a new format specifier
PRI_TIMEX which is defined as PRIi64 on x32 and li
everywhere else.
2017-05-19 14:38:25 +02:00
akochetkov 5f36e3d303 timesyncd: clear ADJ_MAXERROR to keep STA_UNSYNC cleared after jump adjust (#4626)
NTP use jump adjust if system has incorrect time read from RTC during boot.
It is desireble to update RTC time as soon as NTP set correct system time.
Sometimes kernel failed to update RTC due to STA_UNSYNC get set before RTC
update finised. In that case RTC time wouldn't be updated within long time.
The commit makes RTC updates stable.

When NTP do jump time adjust using ADJ_SETOFFSET it clears STA_UNSYNC flag.
If don't clear ADJ_MAXERROR, STA_UNSYNC will be set again by kernel within
1 second (by second_overflow() function). STA_UNSYNC flag prevent RTC updates
in kernel. Sometimes the kernel is able to update RTC withing 1 second,
but sometimes it falied.
2016-11-11 18:50:46 +01:00