1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-05 09:17:44 +03:00

timedated: manage systemd-timesyncd directly instead of lists of alternatives

Alternative NTP implementations should add a:
  Conflicts=systemd-timesyncd.service
to take over the built-in NTP functionality of systemd.
This commit is contained in:
Kay Sievers 2014-07-09 14:29:20 +02:00
parent efab8d0b0e
commit b72ddf0f4f
3 changed files with 116 additions and 184 deletions

View File

@ -106,7 +106,6 @@ udevrulesdir=$(udevlibexecdir)/rules.d
udevhwdbdir=$(udevlibexecdir)/hwdb.d udevhwdbdir=$(udevlibexecdir)/hwdb.d
catalogdir=$(prefix)/lib/systemd/catalog catalogdir=$(prefix)/lib/systemd/catalog
kernelinstalldir = $(prefix)/lib/kernel/install.d kernelinstalldir = $(prefix)/lib/kernel/install.d
ntpunitsdir=$(prefix)/lib/systemd/ntp-units.d
# And these are the special ones for / # And these are the special ones for /
rootprefix=@rootprefix@ rootprefix=@rootprefix@
@ -4320,10 +4319,6 @@ dist_systemunit_DATA += \
polkitpolicy_files += \ polkitpolicy_files += \
src/timedate/org.freedesktop.timedate1.policy src/timedate/org.freedesktop.timedate1.policy
INSTALL_DIRS += \
$(prefix)/lib/systemd/ntp-units.d \
$(sysconfdir)/systemd/ntp-units.d
SYSTEM_UNIT_ALIASES += \ SYSTEM_UNIT_ALIASES += \
systemd-timedated.service dbus-org.freedesktop.timedate1.service systemd-timedated.service dbus-org.freedesktop.timedate1.service
@ -4397,10 +4392,6 @@ EXTRA_DIST += \
CLEANFILES += \ CLEANFILES += \
src/timesync/timesyncd.conf src/timesync/timesyncd.conf
dist_ntpunits_DATA = \
src/timesync/90-systemd.list
endif endif
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

7
NEWS
View File

@ -1,5 +1,12 @@
systemd System and Service Manager systemd System and Service Manager
CHANGES WITH 216:
* timedated does no longer read NTP unit names from
/usr/lib/systemd/ntp-units.d/*.list. Alternative NTP
implementations should add a:
Conflicts=systemd-timesyncd.service
to take over and replace systemd's NTP functionality.
CHANGES WITH 215: CHANGES WITH 215:
* A new tool systemd-sysusers has been added. This tool * A new tool systemd-sysusers has been added. This tool

View File

@ -180,68 +180,15 @@ static int context_write_data_local_rtc(Context *c) {
return write_string_file_atomic_label("/etc/adjtime", w); return write_string_file_atomic_label("/etc/adjtime", w);
} }
static char** get_ntp_services(void) {
_cleanup_strv_free_ char **r = NULL, **files = NULL;
char **i;
int k;
k = conf_files_list(&files, ".list", NULL,
"/etc/systemd/ntp-units.d",
"/run/systemd/ntp-units.d",
"/usr/local/lib/systemd/ntp-units.d",
"/usr/lib/systemd/ntp-units.d",
NULL);
if (k < 0)
return NULL;
STRV_FOREACH(i, files) {
_cleanup_fclose_ FILE *f;
f = fopen(*i, "re");
if (!f)
continue;
for (;;) {
char line[PATH_MAX], *l;
if (!fgets(line, sizeof(line), f)) {
if (ferror(f))
log_error("Failed to read NTP unit file: %m");
break;
}
l = strstrip(line);
if (l[0] == 0 || l[0] == '#')
continue;
if (strv_extend(&r, l) < 0) {
log_oom();
return NULL;
}
}
}
i = r;
r = NULL; /* avoid cleanup */
return strv_uniq(i);
}
static int context_read_ntp(Context *c, sd_bus *bus) { static int context_read_ntp(Context *c, sd_bus *bus) {
_cleanup_strv_free_ char **l; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
char **i; sd_bus_message *reply = NULL;
const char *s;
int r; int r;
assert(c); assert(c);
assert(bus); assert(bus);
l = get_ntp_services();
STRV_FOREACH(i, l) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *reply = NULL;
const char *s;
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
"org.freedesktop.systemd1", "org.freedesktop.systemd1",
@ -251,12 +198,13 @@ static int context_read_ntp(Context *c, sd_bus *bus) {
&error, &error,
&reply, &reply,
"s", "s",
*i); "systemd-timesyncd.service");
if (r < 0) { if (r < 0) {
/* This implementation does not exist. Try the next one. */ if (sd_bus_error_has_name(&error, SD_BUS_ERROR_FILE_NOT_FOUND) ||
if (sd_bus_error_has_name(&error, SD_BUS_ERROR_FILE_NOT_FOUND)) sd_bus_error_has_name(&error, "org.freedesktop.systemd1.LoadFailed") ||
continue; sd_bus_error_has_name(&error, "org.freedesktop.systemd1.NoSuchUnit"))
return 0;
return r; return r;
} }
@ -271,21 +219,13 @@ static int context_read_ntp(Context *c, sd_bus *bus) {
return 0; return 0;
} }
return 0;
}
static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) { static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
char **i;
int r; int r;
assert(c); assert(c);
assert(bus); assert(bus);
assert(error); assert(error);
l = get_ntp_services();
STRV_FOREACH(i, l) {
if (c->use_ntp) if (c->use_ntp)
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -295,7 +235,9 @@ static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
"StartUnit", "StartUnit",
error, error,
NULL, NULL,
"ss", *i, "replace"); "ss",
"systemd-timesyncd.service",
"replace");
else else
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -305,38 +247,31 @@ static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
"StopUnit", "StopUnit",
error, error,
NULL, NULL,
"ss", *i, "replace"); "ss",
"systemd-timesyncd.service",
"replace");
if (r < 0) { if (r < 0) {
if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND) || if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND) ||
sd_bus_error_has_name(error, "org.freedesktop.systemd1.LoadFailed") || sd_bus_error_has_name(error, "org.freedesktop.systemd1.LoadFailed") ||
sd_bus_error_has_name(error, "org.freedesktop.systemd1.NoSuchUnit")) { sd_bus_error_has_name(error, "org.freedesktop.systemd1.NoSuchUnit")) {
/* This implementation does not exist. Try the next one. */ sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
sd_bus_error_free(error); return -ENOTSUP;
continue;
} }
return r; return r;
} }
return 1; return 0;
}
sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
return -ENOTSUP;
} }
static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) { static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
char **i;
int r; int r;
assert(c); assert(c);
assert(bus); assert(bus);
assert(error); assert(error);
l = get_ntp_services();
STRV_FOREACH(i, l) {
if (c->use_ntp) if (c->use_ntp)
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -346,7 +281,9 @@ static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
"EnableUnitFiles", "EnableUnitFiles",
error, error,
NULL, NULL,
"asbb", 1, *i, false, true); "asbb", 1,
"systemd-timesyncd.service",
false, true);
else else
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -356,13 +293,14 @@ static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
"DisableUnitFiles", "DisableUnitFiles",
error, error,
NULL, NULL,
"asb", 1, *i, false); "asb", 1,
"systemd-timesyncd.service",
false);
if (r < 0) { if (r < 0) {
if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND)) { if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND)) {
/* This implementation does not exist. Try the next one. */ sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
sd_bus_error_free(error); return -ENOTSUP;
continue;
} }
return r; return r;
@ -380,11 +318,7 @@ static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
if (r < 0) if (r < 0)
return r; return r;
return 1; return 0;
}
sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
return -ENOTSUP;
} }
static int property_get_rtc_time( static int property_get_rtc_time(