mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 06:25:37 +03:00
timesyncd: use structured initialization more
This commit is contained in:
parent
40f35786b0
commit
40c6b5143b
@ -244,7 +244,7 @@ static int manager_clock_watch_setup(Manager *m) {
|
||||
}
|
||||
|
||||
static int manager_adjust_clock(Manager *m, double offset, int leap_sec) {
|
||||
struct timex tmx = {};
|
||||
struct timex tmx;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -254,21 +254,22 @@ static int manager_adjust_clock(Manager *m, double offset, int leap_sec) {
|
||||
* clock to the NTP time, larger deltas are just directly set.
|
||||
*/
|
||||
if (fabs(offset) < NTP_MAX_ADJUST) {
|
||||
tmx.modes = ADJ_STATUS | ADJ_NANO | ADJ_OFFSET | ADJ_TIMECONST | ADJ_MAXERROR | ADJ_ESTERROR;
|
||||
tmx.status = STA_PLL;
|
||||
tmx.offset = offset * NSEC_PER_SEC;
|
||||
tmx.constant = log2i(m->poll_interval_usec / USEC_PER_SEC) - 4;
|
||||
tmx.maxerror = 0;
|
||||
tmx.esterror = 0;
|
||||
tmx = (struct timex) {
|
||||
.modes = ADJ_STATUS | ADJ_NANO | ADJ_OFFSET | ADJ_TIMECONST | ADJ_MAXERROR | ADJ_ESTERROR,
|
||||
.status = STA_PLL,
|
||||
.offset = offset * NSEC_PER_SEC,
|
||||
.constant = log2i(m->poll_interval_usec / USEC_PER_SEC) - 4,
|
||||
};
|
||||
|
||||
log_debug(" adjust (slew): %+.3f sec", offset);
|
||||
} else {
|
||||
tmx.modes = ADJ_STATUS | ADJ_NANO | ADJ_SETOFFSET | ADJ_MAXERROR | ADJ_ESTERROR;
|
||||
tmx = (struct timex) {
|
||||
.modes = ADJ_STATUS | ADJ_NANO | ADJ_SETOFFSET | ADJ_MAXERROR | ADJ_ESTERROR,
|
||||
|
||||
/* ADJ_NANO uses nanoseconds in the microseconds field */
|
||||
tmx.time.tv_sec = (long)offset;
|
||||
tmx.time.tv_usec = (offset - tmx.time.tv_sec) * NSEC_PER_SEC;
|
||||
tmx.maxerror = 0;
|
||||
tmx.esterror = 0;
|
||||
/* ADJ_NANO uses nanoseconds in the microseconds field */
|
||||
.time.tv_sec = (long)offset,
|
||||
.time.tv_usec = (offset - (double) (long) offset) * NSEC_PER_SEC,
|
||||
};
|
||||
|
||||
/* the kernel expects -0.3s as {-1, 7000.000.000} */
|
||||
if (tmx.time.tv_usec < 0) {
|
||||
@ -1098,21 +1099,27 @@ int manager_new(Manager **ret) {
|
||||
|
||||
assert(ret);
|
||||
|
||||
m = new0(Manager, 1);
|
||||
m = new(Manager, 1);
|
||||
if (!m)
|
||||
return -ENOMEM;
|
||||
|
||||
m->root_distance_max_usec = NTP_ROOT_DISTANCE_MAX_USEC;
|
||||
m->poll_interval_min_usec = NTP_POLL_INTERVAL_MIN_USEC;
|
||||
m->poll_interval_max_usec = NTP_POLL_INTERVAL_MAX_USEC;
|
||||
*m = (Manager) {
|
||||
.root_distance_max_usec = NTP_ROOT_DISTANCE_MAX_USEC,
|
||||
.poll_interval_min_usec = NTP_POLL_INTERVAL_MIN_USEC,
|
||||
.poll_interval_max_usec = NTP_POLL_INTERVAL_MAX_USEC,
|
||||
|
||||
m->connection_retry_usec = DEFAULT_CONNECTION_RETRY_USEC;
|
||||
.connection_retry_usec = DEFAULT_CONNECTION_RETRY_USEC,
|
||||
|
||||
m->server_socket = m->clock_watch_fd = -1;
|
||||
.server_socket = -1,
|
||||
.clock_watch_fd = -1,
|
||||
|
||||
m->ratelimit = (RateLimit) { RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST };
|
||||
.ratelimit = (RateLimit) {
|
||||
RATELIMIT_INTERVAL_USEC,
|
||||
RATELIMIT_BURST
|
||||
},
|
||||
|
||||
m->save_time_interval_usec = DEFAULT_SAVE_TIME_INTERVAL_USEC;
|
||||
.save_time_interval_usec = DEFAULT_SAVE_TIME_INTERVAL_USEC,
|
||||
};
|
||||
|
||||
r = sd_event_default(&m->event);
|
||||
if (r < 0)
|
||||
|
@ -16,16 +16,19 @@ int server_address_new(
|
||||
assert(socklen >= offsetof(struct sockaddr, sa_data));
|
||||
assert(socklen <= sizeof(union sockaddr_union));
|
||||
|
||||
a = new0(ServerAddress, 1);
|
||||
a = new(ServerAddress, 1);
|
||||
if (!a)
|
||||
return -ENOMEM;
|
||||
|
||||
*a = (ServerAddress) {
|
||||
.name = n,
|
||||
.socklen = socklen,
|
||||
};
|
||||
|
||||
memcpy(&a->sockaddr, sockaddr, socklen);
|
||||
a->socklen = socklen;
|
||||
|
||||
LIST_FIND_TAIL(addresses, n->addresses, tail);
|
||||
LIST_INSERT_AFTER(addresses, n->addresses, tail, a);
|
||||
a->name = n;
|
||||
|
||||
if (ret)
|
||||
*ret = a;
|
||||
@ -58,12 +61,16 @@ int server_name_new(
|
||||
assert(m);
|
||||
assert(string);
|
||||
|
||||
n = new0(ServerName, 1);
|
||||
n = new(ServerName, 1);
|
||||
if (!n)
|
||||
return -ENOMEM;
|
||||
|
||||
n->type = type;
|
||||
n->string = strdup(string);
|
||||
*n = (ServerName) {
|
||||
.manager = m,
|
||||
.type = type,
|
||||
.string = strdup(string),
|
||||
};
|
||||
|
||||
if (!n->string) {
|
||||
free(n);
|
||||
return -ENOMEM;
|
||||
@ -81,8 +88,6 @@ int server_name_new(
|
||||
} else
|
||||
assert_not_reached();
|
||||
|
||||
n->manager = m;
|
||||
|
||||
if (type != SERVER_FALLBACK &&
|
||||
m->current_server_name &&
|
||||
m->current_server_name->type == SERVER_FALLBACK)
|
||||
|
Loading…
Reference in New Issue
Block a user