summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-05-09 16:05:22 +0200
committerMike Yuan <me@yhndnzj.com>2024-06-20 19:03:44 +0200
commit9c025022d98787d7ad4e46b57f709434531e55a1 (patch)
treeb0a7ca29300579463e55795c67e74017936b728d /src
parentsd-bus/bus-error: inline iterator var, use assert_return (diff)
downloadsystemd-9c025022d98787d7ad4e46b57f709434531e55a1.tar.xz
systemd-9c025022d98787d7ad4e46b57f709434531e55a1.zip
core/service: store BUSERROR= & VARLINKERROR= received through notification
Closes #6073
Diffstat (limited to 'src')
-rw-r--r--src/core/dbus-service.c2
-rw-r--r--src/core/service.c51
-rw-r--r--src/core/service.h2
3 files changed, 53 insertions, 2 deletions
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
index ff970df957..cf7e2fe0eb 100644
--- a/src/core/dbus-service.c
+++ b/src/core/dbus-service.c
@@ -351,6 +351,8 @@ const sd_bus_vtable bus_service_vtable[] = {
SD_BUS_PROPERTY("FileDescriptorStorePreserve", "s", bus_property_get_exec_preserve_mode, offsetof(Service, fd_store_preserve_mode), 0),
SD_BUS_PROPERTY("StatusText", "s", NULL, offsetof(Service, status_text), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("StatusErrno", "i", bus_property_get_int, offsetof(Service, status_errno), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("StatusBusError", "s", NULL, offsetof(Service, status_bus_error), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("StatusVarlinkError", "s", NULL, offsetof(Service, status_varlink_error), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Service, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("ReloadResult", "s", property_get_result, offsetof(Service, reload_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("CleanResult", "s", property_get_result, offsetof(Service, clean_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
diff --git a/src/core/service.c b/src/core/service.c
index f37a941a6d..937729cd06 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -468,6 +468,8 @@ static void service_done(Unit *u) {
s->pid_file = mfree(s->pid_file);
s->status_text = mfree(s->status_text);
+ s->status_bus_error = mfree(s->status_bus_error);
+ s->status_varlink_error = mfree(s->status_varlink_error);
s->exec_runtime = exec_runtime_free(s->exec_runtime);
@@ -1045,6 +1047,14 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f, "%sStatus Errno: %s\n",
prefix, STRERROR(s->status_errno));
+ if (s->status_bus_error)
+ fprintf(f, "%sStatus Bus Error: %s\n",
+ prefix, s->status_bus_error);
+
+ if (s->status_varlink_error)
+ fprintf(f, "%sStatus Varlink Error: %s\n",
+ prefix, s->status_varlink_error);
+
if (s->n_fd_store_max > 0)
fprintf(f,
"%sFile Descriptor Store Max: %u\n"
@@ -2765,6 +2775,8 @@ static int service_start(Unit *u) {
s->status_text = mfree(s->status_text);
s->status_errno = 0;
+ s->status_bus_error = mfree(s->status_bus_error);
+ s->status_varlink_error = mfree(s->status_varlink_error);
s->notify_access_override = _NOTIFY_ACCESS_INVALID;
s->notify_state = NOTIFY_UNKNOWN;
@@ -3036,6 +3048,8 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
return r;
(void) serialize_item_format(f, "status-errno", "%d", s->status_errno);
+ (void) serialize_item(f, "status-bus-error", s->status_bus_error);
+ (void) serialize_item(f, "status-varlink-error", s->status_varlink_error);
(void) serialize_dual_timestamp(f, "watchdog-timestamp", &s->watchdog_timestamp);
@@ -3370,6 +3384,14 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
else
s->status_errno = i;
+ } else if (streq(key, "status-bus-error")) {
+ if (free_and_strdup(&s->status_bus_error, value) < 0)
+ log_oom_debug();
+
+ } else if (streq(key, "status-varlink-error")) {
+ if (free_and_strdup(&s->status_varlink_error, value) < 0)
+ log_oom_debug();
+
} else if (streq(key, "watchdog-timestamp"))
(void) deserialize_dual_timestamp(value, &s->watchdog_timestamp);
else if (streq(key, "watchdog-original-usec"))
@@ -4353,7 +4375,7 @@ static void service_notify_message(
if (DEBUG_LOGGING) {
_cleanup_free_ char *cc = strv_join(tags, ", ");
- log_unit_debug(u, "Got notification message from PID "PID_FMT" (%s)", ucred->pid, empty_to_na(cc));
+ log_unit_debug(u, "Got notification message from PID "PID_FMT": %s", ucred->pid, empty_to_na(cc));
}
usec_t monotonic_usec = USEC_INFINITY;
@@ -4479,7 +4501,7 @@ static void service_notify_message(
else {
t = strdup(e);
if (!t)
- log_oom();
+ log_oom_warning();
}
}
@@ -4523,10 +4545,35 @@ static void service_notify_message(
}
}
+ static const struct {
+ const char *tag;
+ size_t status_offset;
+ } status_errors[] = {
+ { "BUSERROR=", offsetof(Service, status_bus_error) },
+ { "VARLINKERROR=", offsetof(Service, status_varlink_error) },
+ };
+
+ FOREACH_ELEMENT(i, status_errors) {
+ e = strv_find_startswith(tags, i->tag);
+ if (!e)
+ continue;
+
+ char **status_error = (char**) ((uint8_t*) s + i->status_offset);
+
+ e = empty_to_null(e);
+
+ if (e && !string_is_safe_ascii(e)) {
+ _cleanup_free_ char *escaped = cescape(e);
+ log_unit_warning(u, "Got invalid %s string, ignoring: %s", i->tag, strna(escaped));
+ } else if (free_and_strdup_warn(status_error, e) > 0)
+ notify_dbus = true;
+ }
+
/* Interpret EXTEND_TIMEOUT= */
e = strv_find_startswith(tags, "EXTEND_TIMEOUT_USEC=");
if (e) {
usec_t extend_timeout_usec;
+
if (safe_atou64(e, &extend_timeout_usec) < 0)
log_unit_warning(u, "Failed to parse EXTEND_TIMEOUT_USEC=%s", e);
else
diff --git a/src/core/service.h b/src/core/service.h
index 55ea413f40..1d67d13fda 100644
--- a/src/core/service.h
+++ b/src/core/service.h
@@ -198,6 +198,8 @@ struct Service {
char *bus_name;
char *status_text;
+ char *status_bus_error;
+ char *status_varlink_error;
int status_errno;
sd_event_source *timer_event_source;