summaryrefslogtreecommitdiffstats
path: root/src/shared/clock-util.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* time-util: rework localtime_or_gmtime() into localtime_or_gmtime_usec()Lennart Poettering2024-09-051-3/+5
| | | | | | | | | | | | We typically want to deal in usec_t, hence let's change the prototype accordingly, and do proper range checks. Also, make sure are not confused by negative times. Do something similar for mktime_or_timegm(). This is a more comprehensive alternative to #34065 Replaces: #34065
* shared/clock-util: small modernizationZbigniew Jędrzejewski-Szmek2024-06-151-27/+22
|
* Move two functions only used in timesyncd from libshared to the binaryZbigniew Jędrzejewski-Szmek2024-06-121-35/+0
|
* Move two functions only used in pid1 from libshared to the binaryZbigniew Jędrzejewski-Szmek2024-06-121-48/+0
| | | | | | | | | | Anything that is part of src/shared becomes part of the shared library, which is wasteful, because the library is linked into almost all binaries. The library is also forms a separate link unit, so this prevents the function from being inlined or such. Also, move logging into the function. Now that it's not a library function, there is no reason not to do that.
* timesync: make public defines for clock epoch filesZbigniew Jędrzejewski-Szmek2024-06-051-4/+2
| | | | | | | | No functional change yet, just moving stuff around and message format adjustments. EPOCH_CLOCK_FILE is also made public for consistency, even though I don't plan to use it outside of the one location.
* timedate: handle gracefully if RTC lost time because of power lossLennart Poettering2024-04-201-3/+4
| | | | | | | Apparently some RTC drivers return EINVAL in that case when we try to read it. Handle that reasonably gracefully. Fixes: #31854
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-2/+2
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* core: allow disabling system time correction if rtc returns time far in the ↵Franck Bui2022-08-241-1/+1
| | | | | | | | | | | | | future There might be (embedded) systems that get never updated (things like e.g. entertainment systems of trains, for example) and where the adjustment of the system clock (introduced by b10abe4bba61aebe4c667c412741193f11886298) would do the wrong thing even if the difference between the systemd build time and the rtc is 15 years or more. This patch allows disabling the adjustment by setting 'clock-valid-range-usec-max' meson option to 0 or to a negative value.
* time-util: add macros around timespec_store() that operates on compund ↵Lennart Poettering2022-03-181-3/+2
| | | | | | | | literal allocated timespec struct This way we can convert usec_t to timespec on-the-fly, without a buffer. No actual behaviour change just some shortening of code.
* tree-wide: use new RET_NERRNO() helper at various placesLennart Poettering2021-11-161-8/+2
|
* time-set: adjust system clock if rtc is far in futureEgor Ignatov2021-08-021-3/+15
|
* tree-wide: avoid uninitialized warning on _cleanup_ variablesLuca Boccassi2021-04-141-1/+1
| | | | | | | With some versions of the compiler, the _cleanup_ attr makes it think the variable might be freed/closed when uninitialized, even though it cannot happen. The added cost is small enough to be worth the benefit, and optimized builds will help reduce it even further.
* clock-util: modernize settimeofday() timezone callsLennart Poettering2021-02-101-26/+21
| | | | | | | Let's use structured initialization, and avoid the weird `tv_null` indirection. No changes in behaviour, just some clean-ups.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* clock-util: trivial clean-upsLennart Poettering2020-10-221-2/+2
|
* clock-util: read timestamp from /usr/lib/clock-epochDaniel Mack2020-08-281-3/+13
| | | | | | | | | | | On systems without an RTC, systemd currently sets the clock to a compile-time epoch value, derived from the NEWS file in the repository. This is not ideal as the initial clock hence depends on the last time systemd was built, not when the image was compiled. Let's provide a different way here and look at `/usr/lib/clock-epoch`. If that file exists, it's timestamp for the last modification will be used instead of the compile-time default.
* util: split out errno related stuffLennart Poettering2019-03-141-1/+1
|
* Move various files that don't need to be in basic/ to shared/Zbigniew Jędrzejewski-Szmek2018-11-201-0/+157
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This doesn't have much effect on the final build, because we link libbasic.a into libsystemd-shared.so, so in the end, all the object built from basic/ end up in libsystemd-shared. And when the static library is linked into binaries, any objects that are included in it but are not used are trimmed. Hence, the size of output artifacts doesn't change: $ du -sb /var/tmp/inst* 54181861 /var/tmp/inst1 (old) 54207441 /var/tmp/inst1s (old split-usr) 54182477 /var/tmp/inst2 (new) 54208041 /var/tmp/inst2s (new split-usr) (The negligible change in size is because libsystemd-shared.so is bigger by a few hundred bytes. I guess it's because symbols are named differently or something like that.) The effect is on the build process, in particular partial builds. This change effectively moves the requirements on some build steps toward the leaves of the dependency tree. Two effects: - when building items that do not depend on libsystemd-shared, we build less stuff for libbasic.a (which wouldn't be used anyway, so it's a net win). - when building items that do depend on libshared, we reduce libbasic.a as a synchronization point, possibly allowing better parallelism. Method: 1. copy list of .h files from src/basic/meson.build to /tmp/basic 2. $ for i in $(grep '.h$' /tmp/basic); do echo $i; git --no-pager grep "include \"$i\"" src/basic/ 'src/lib*' 'src/nss-*' 'src/journal/sd-journal.c' |grep -v "${i%.h}.c";echo ;done | less
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-142/+0
| | | | | | | | | | basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-13/+0
| | | | | | This patch removes includes that are not used. The removals were found with include-what-you-use which checks if any of the symbols from a header is in use.
* shared: correct spacing near eol in code commentsTorstein Husebø2014-12-111-2/+2
|
* core: only set the kernel's timezone when the RTC runs in local timeKay Sievers2014-07-271-7/+8
| | | | | | | | | | | | | | | | | | | We can not reliably manage any notion of local time. Every daylight saving time change or time zone change by traveling will make the time jump, and the local time might jump backwards which creates unsolvable problems with file timestamps. We will no longer tell the kernel our local time zone and leave everything set to UTC. This will effectively turn FAT timestamps into UTC timestamps. If and only if the machine is configured to read the RTC in local time mode, the kernel's time zone will be configured, but systemd-timesysnc will disable the kernel's system time to RTC syncing. In this mode, the RTC will not be managed, and external tools like Windows bootups are expected to manage the RTC's time. https://bugs.freedesktop.org/show_bug.cgi?id=81538
* clock-util: clock_[sg]et_time() -> clock_[sg]et_hwclock()Kay Sievers2014-05-241-2/+2
|
* timesyncd: only update stamp file when we are synchronizedKay Sievers2014-05-241-1/+1
| | | | | | | | Create initial stamp file with compiled-in time to prevent bootups with clocks in the future from storing invalid timestamps. At shutdown, only update the timestamp if we got an authoritative time to store.
* shared: rename hwclock.[ch] to clock-util.[ch]Kay Sievers2014-05-241-0/+154