chiark / gitweb /
timesyncd: make use of floating event sources for signal handling
[elogind.git] / src / timesync / timesyncd.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2014 Kay Sievers, Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "list.h"
23 #include "socket-util.h"
24 #include "ratelimit.h"
25 #include "sd-event.h"
26 #include "sd-resolve.h"
27 #include "sd-network.h"
28
29 typedef struct Manager Manager;
30 typedef struct ServerAddress ServerAddress;
31 typedef struct ServerName ServerName;
32
33 struct ServerAddress {
34         union sockaddr_union sockaddr;
35         socklen_t socklen;
36         LIST_FIELDS(ServerAddress, addresses);
37 };
38
39 struct ServerName {
40         char *string;
41         LIST_HEAD(ServerAddress, addresses);
42         LIST_FIELDS(ServerName, names);
43 };
44
45 struct Manager {
46         sd_event *event;
47         sd_resolve *resolve;
48
49         LIST_HEAD(ServerName, servers);
50
51         RateLimit ratelimit;
52
53         /* network */
54         sd_event_source *network_event_source;
55         sd_network_monitor *network_monitor;
56
57         /* peer */
58         sd_resolve_query *resolve_query;
59         sd_event_source *event_receive;
60         ServerName *current_server_name;
61         ServerAddress *current_server_address;
62         int server_socket;
63         uint64_t packet_count;
64         sd_event_source *event_timeout;
65
66         /* last sent packet */
67         struct timespec trans_time_mon;
68         struct timespec trans_time;
69         usec_t retry_interval;
70         bool pending;
71
72         /* poll timer */
73         sd_event_source *event_timer;
74         usec_t poll_interval_usec;
75         bool poll_resync;
76
77         /* history data */
78         struct {
79                 double offset;
80                 double delay;
81         } samples[8];
82         unsigned int samples_idx;
83         double samples_jitter;
84
85         /* last change */
86         bool jumped;
87         int drift_ppm;
88
89         /* watch for time changes */
90         sd_event_source *event_clock_watch;
91         int clock_watch_fd;
92
93         /* Retry connections */
94         sd_event_source *event_retry;
95 };
96
97 const struct ConfigPerfItem* timesyncd_gperf_lookup(const char *key, unsigned length);
98
99 int config_parse_servers(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);