LIST_HEAD(UnitStatusInfo, units);
} Context;
+#define log_unit_full(unit, level, error, ...) \
+ ({ \
+ const UnitStatusInfo *_u = (unit); \
+ log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, \
+ "UNIT=", _u->name, NULL, NULL, ##__VA_ARGS__); \
+ })
+
+#define log_unit_debug(unit, ...) log_unit_full(unit, LOG_DEBUG, 0, ##__VA_ARGS__)
+#define log_unit_info(unit, ...) log_unit_full(unit, LOG_INFO, 0, ##__VA_ARGS__)
+#define log_unit_notice(unit, ...) log_unit_full(unit, LOG_NOTICE, 0, ##__VA_ARGS__)
+#define log_unit_warning(unit, ...) log_unit_full(unit, LOG_WARNING, 0, ##__VA_ARGS__)
+#define log_unit_error(unit, ...) log_unit_full(unit, LOG_ERR, 0, ##__VA_ARGS__)
+
+#define log_unit_debug_errno(unit, error, ...) log_unit_full(unit, LOG_DEBUG, error, ##__VA_ARGS__)
+#define log_unit_info_errno(unit, error, ...) log_unit_full(unit, LOG_INFO, error, ##__VA_ARGS__)
+#define log_unit_notice_errno(unit, error, ...) log_unit_full(unit, LOG_NOTICE, error, ##__VA_ARGS__)
+#define log_unit_warning_errno(unit, error, ...) log_unit_full(unit, LOG_WARNING, error, ##__VA_ARGS__)
+#define log_unit_error_errno(unit, error, ...) log_unit_full(unit, LOG_ERR, error, ##__VA_ARGS__)
+
static void unit_status_info_clear(UnitStatusInfo *p) {
assert(p);
}
}
-static int context_add_ntp_service(Context *c, const char *s) {
+static int context_add_ntp_service(Context *c, const char *s, const char *source) {
UnitStatusInfo *u;
if (!unit_name_is_valid(s, UNIT_NAME_PLAIN))
}
LIST_APPEND(units, c->units, u);
+ log_unit_debug(u, "added from %s.", source);
return 0;
}
if (!env)
return 0;
- log_debug("Using list of ntp services from environment variable $SYSTEMD_TIMEDATED_NTP_SERVICES.");
+ log_debug("Using list of ntp services from environment variable $SYSTEMD_TIMEDATED_NTP_SERVICES=%s.", env);
for (p = env;;) {
_cleanup_free_ char *word = NULL;
break;
}
- r = context_add_ntp_service(c, word);
+ r = context_add_ntp_service(c, word, "$SYSTEMD_TIMEDATED_NTP_SERVICES");
if (r < 0)
log_warning_errno(r, "Failed to add NTP service \"%s\", ignoring: %m", word);
}
if (isempty(word) || startswith("#", word))
continue;
- r = context_add_ntp_service(c, word);
+ r = context_add_ntp_service(c, word, *f);
if (r < 0)
log_warning_errno(r, "Failed to add NTP service \"%s\", ignoring: %m", word);
}
NULL,
u);
if (r < 0)
- return log_error_errno(r, "Failed to get properties: %s", bus_error_message(&error, r));
+ return log_unit_error_errno(u, r, "Failed to get properties: %s", bus_error_message(&error, r));
}
return 0;
if (n == 0) {
c->slot_job_removed = sd_bus_slot_unref(c->slot_job_removed);
- (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "NTP", NULL);
+ (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m),
+ "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "NTP",
+ NULL);
}
return 0;
"ss",
u->name,
"replace");
+ log_unit_full(u, r < 0 ? LOG_WARNING : LOG_DEBUG, r,
+ "%s unit: %m", start ? "Starting" : "Stopping");
if (r < 0)
return r;
/* Call context_update_ntp_status() to update UnitStatusInfo before calling this. */
- if (streq(u->unit_file_state, "enabled") == enable)
+ if (streq(u->unit_file_state, "enabled") == enable) {
+ log_unit_debug(u, "already %sd.", enable_disable(enable));
return 0;
+ }
+
+ log_unit_info(u, "%s unit.", enable ? "Enabling" : "Disabling");
if (enable)
r = sd_bus_call_method(
"DAYLIGHT=%i", daylight,
LOG_MESSAGE("Changed time zone to '%s' (%s).", c->zone, tzname[daylight]));
- (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "Timezone", NULL);
+ (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m),
+ "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "Timezone",
+ NULL);
return sd_bus_reply_method_return(m, NULL);
}
/* 1. Write new configuration file */
r = context_write_data_local_rtc(c);
if (r < 0) {
- log_error_errno(r, "Failed to set RTC to local/UTC: %m");
- return sd_bus_error_set_errnof(error, r, "Failed to set RTC to local/UTC: %m");
+ log_error_errno(r, "Failed to set RTC to %s: %m", lrtc ? "local" : "UTC");
+ return sd_bus_error_set_errnof(error, r, "Failed to set RTC to %s: %m", lrtc ? "local" : "UTC");
}
/* 2. Tell the kernel our timezone */
log_info("RTC configured to %s time.", c->local_rtc ? "local" : "UTC");
- (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "LocalRTC", NULL);
+ (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m),
+ "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "LocalRTC",
+ NULL);
return sd_bus_reply_method_return(m, NULL);
}
sd_bus *bus = sd_bus_message_get_bus(m);
Context *c = userdata;
UnitStatusInfo *u;
+ const UnitStatusInfo *selected = NULL;
int enable, interactive, q, r;
assert(m);
continue;
r = unit_start_or_stop(u, bus, error, enable);
+ selected = u;
break;
}
continue;
r = unit_start_or_stop(u, bus, error, enable);
+ selected = u;
break;
}
if (r < 0)
return r;
+ if (enable && !selected)
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "No NTP service found to enable.");
if (slot)
c->slot_job_removed = TAKE_PTR(slot);
- log_info("Set NTP to %sd", enable_disable(enable));
+ if (selected)
+ log_info("Set NTP to enabled (%s).", selected->name);
+ else
+ log_info("Set NTP to disabled.");
return sd_bus_reply_method_return(m, NULL);
}