• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

systemd / systemd / 15232239991

24 May 2025 08:01PM UTC coverage: 72.053% (-0.02%) from 72.07%
15232239991

push

github

web-flow
docs: add man pages for sd_device_enumerator_[new,ref,unref,unrefp] (#37586)

For #20929.

299160 of 415197 relevant lines covered (72.05%)

703671.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/shared/clock-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdio.h>
4
#include <sys/time.h>
5

6
#include "alloc-util.h"
7
#include "clock-util.h"
8
#include "fd-util.h"
9
#include "fileio.h"
10
#include "string-util.h"
11
#include "time-util.h"
12

13
int clock_is_localtime(const char *adjtime_path) {
211✔
14
        int r;
211✔
15

16
        if (!adjtime_path)
211✔
17
                adjtime_path = "/etc/adjtime";
201✔
18

19
        /*
20
         * The third line of adjtime is "UTC" or "LOCAL" or nothing.
21
         *   # /etc/adjtime
22
         *   0.0 0 0
23
         *   0
24
         *   UTC
25
         */
26
        _cleanup_fclose_ FILE *f = fopen(adjtime_path, "re");
422✔
27
        if (!f) {
211✔
28
                if (errno != ENOENT)
202✔
29
                        return -errno;
×
30

31
                /* adjtime_path not present → default to UTC */
32
                return false;
33
        }
34

35
        _cleanup_free_ char *line = NULL;
9✔
36
        for (unsigned i = 0; i < 2; i++) { /* skip the first two lines */
25✔
37
                r = read_line(f, LONG_LINE_MAX, NULL);
18✔
38
                if (r < 0)
18✔
39
                        return r;
40
                if (r == 0)
18✔
41
                        return false; /* less than three lines → default to UTC */
42
        }
43

44
        r = read_line(f, LONG_LINE_MAX, &line);
7✔
45
        if (r < 0)
7✔
46
                return r;
47
        if (r == 0)
7✔
48
                return false; /* less than three lines → default to UTC */
49

50
        return streq(line, "LOCAL");
5✔
51
}
52

53
int clock_set_timezone(int *ret_minutesdelta) {
25✔
54
        struct tm tm;
25✔
55
        int r;
25✔
56

57
        r = localtime_or_gmtime_usec(now(CLOCK_REALTIME), /* utc= */ false, &tm);
25✔
58
        if (r < 0)
25✔
59
                return r;
25✔
60

61
        int minutesdelta = tm.tm_gmtoff / 60;
25✔
62

63
        struct timezone tz = {
25✔
64
                .tz_minuteswest = -minutesdelta,
25✔
65
                .tz_dsttime = 0, /* DST_NONE */
66
        };
67

68
        /* If the RTC does not run in UTC but in local time, the very first call to settimeofday() will set
69
         * the kernel's timezone and will warp the system clock, so that it runs in UTC instead of the local
70
         * time we have read from the RTC. */
71
        if (settimeofday(NULL, &tz) < 0)
25✔
72
                return -errno;
21✔
73

74
        if (ret_minutesdelta)
4✔
75
                *ret_minutesdelta = minutesdelta;
×
76

77
        return 0;
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc