[systemd-commits] 6 commits - src/bus-driverd src/core src/hostname src/libsystemd-bus src/locale src/machine src/shared src/timedate
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Dec 19 13:21:11 PST 2013
src/bus-driverd/bus-driverd.c | 9 ++++++-
src/core/service.c | 46 +++++++++++++++++----------------------
src/hostname/hostnamed.c | 2 -
src/libsystemd-bus/bus-control.c | 2 -
src/libsystemd-bus/bus-util.c | 18 ++++++++++++---
src/libsystemd-bus/bus-util.h | 4 ++-
src/libsystemd-bus/sd-event.c | 2 -
src/locale/localed.c | 2 -
src/machine/machined.c | 29 +++++++++++-------------
src/shared/def.h | 5 +++-
src/timedate/timedated.c | 2 -
11 files changed, 69 insertions(+), 52 deletions(-)
New commits:
commit f7cf00fa51937e3449b40f098d34569d41170077
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Dec 19 22:12:53 2013 +0100
def: lower exit-on-idle time
diff --git a/src/shared/def.h b/src/shared/def.h
index 825db95..d196af7 100644
--- a/src/shared/def.h
+++ b/src/shared/def.h
@@ -30,7 +30,10 @@
#define DEFAULT_START_LIMIT_INTERVAL (10*USEC_PER_SEC)
#define DEFAULT_START_LIMIT_BURST 5
-#define DEFAULT_EXIT_USEC (5*USEC_PER_MINUTE)
+/* The default time after which exit-on-idle services exit. This
+ * should be kept lower than the watchdog timeout, because otherwise
+ * the watchdog pings will keep the loop busy. */
+#define DEFAULT_EXIT_USEC (30*USEC_PER_SEC)
#define SYSTEMD_CGROUP_CONTROLLER "name=systemd"
commit ff0031069ffeb0ccda209297b6b39c4786ac770b
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Dec 19 21:38:52 2013 +0100
sd-event: return 1 in sd_event_run() when we hit EINTR
That way we can distuingish timeouts from EINTR
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 727528b..a1baac5 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -1986,7 +1986,7 @@ _public_ int sd_event_run(sd_event *e, uint64_t timeout) {
m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max,
timeout == (uint64_t) -1 ? -1 : (int) ((timeout + USEC_PER_MSEC - 1) / USEC_PER_MSEC));
if (m < 0) {
- r = errno == EAGAIN || errno == EINTR ? 0 : -errno;
+ r = errno == EAGAIN || errno == EINTR ? 1 : -errno;
goto finish;
}
commit 30b5275ac775264fa94490ac88c1e35bc6b90b40
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Dec 19 21:34:09 2013 +0100
service: don't send out PropertiesChanged message for each watchdog notification
diff --git a/src/core/service.c b/src/core/service.c
index fa47061..6c82ced 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -3342,6 +3342,7 @@ static void service_notify_cgroup_empty_event(Unit *u) {
static void service_notify_message(Unit *u, pid_t pid, char **tags) {
Service *s = SERVICE(u);
const char *e;
+ bool notify_dbus = false;
assert(u);
@@ -3359,8 +3360,7 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
return;
}
- log_debug_unit(u->id,
- "%s: Got message", u->id);
+ log_debug_unit(u->id, "%s: Got message", u->id);
/* Interpret MAINPID= */
if ((e = strv_find_prefix(tags, "MAINPID=")) &&
@@ -3370,24 +3370,20 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
s->state == SERVICE_RELOAD)) {
if (parse_pid(e + 8, &pid) < 0)
- log_warning_unit(u->id,
- "Failed to parse notification message %s", e);
+ log_warning_unit(u->id, "Failed to parse notification message %s", e);
else {
- log_debug_unit(u->id,
- "%s: got %s", u->id, e);
+ log_debug_unit(u->id, "%s: got %s", u->id, e);
service_set_main_pid(s, pid);
unit_watch_pid(UNIT(s), pid);
+ notify_dbus = true;
}
}
/* Interpret READY= */
- if (s->type == SERVICE_NOTIFY &&
- s->state == SERVICE_START &&
- strv_find(tags, "READY=1")) {
- log_debug_unit(u->id,
- "%s: got READY=1", u->id);
-
+ if (s->type == SERVICE_NOTIFY && s->state == SERVICE_START && strv_find(tags, "READY=1")) {
+ log_debug_unit(u->id, "%s: got READY=1", u->id);
service_enter_start_post(s);
+ notify_dbus = true;
}
/* Interpret STATUS= */
@@ -3396,39 +3392,39 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
char *t;
if (e[7]) {
-
if (!utf8_is_valid(e+7)) {
- log_warning_unit(u->id,
- "Status message in notification is not UTF-8 clean.");
+ log_warning_unit(u->id, "Status message in notification is not UTF-8 clean.");
return;
}
+ log_debug_unit(u->id, "%s: got %s", u->id, e);
+
t = strdup(e+7);
if (!t) {
- log_error_unit(u->id,
- "Failed to allocate string.");
+ log_oom();
return;
}
- log_debug_unit(u->id,
- "%s: got %s", u->id, e);
+ } else
+ t = NULL;
+ if (!streq_ptr(s->status_text, t)) {
free(s->status_text);
s->status_text = t;
- } else {
- free(s->status_text);
- s->status_text = NULL;
- }
-
+ notify_dbus = true;
+ } else
+ free(t);
}
+ /* Interpet WATCHDOG= */
if (strv_find(tags, "WATCHDOG=1")) {
log_debug_unit(u->id, "%s: got WATCHDOG=1", u->id);
service_reset_watchdog(s);
}
/* Notify clients about changed status or main pid */
- unit_add_to_dbus_queue(u);
+ if (notify_dbus)
+ unit_add_to_dbus_queue(u);
}
#ifdef HAVE_SYSV_COMPAT
commit d9e34bfda3d34dcde00a876cb052e7de0655e1cb
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Dec 19 21:15:08 2013 +0100
machined: implement exit-on-idle
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 6550075..6eeb053 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -275,26 +275,23 @@ int manager_startup(Manager *m) {
return 0;
}
-int manager_run(Manager *m) {
- int r;
-
- assert(m);
+static bool check_idle(void *userdata) {
+ Manager *m = userdata;
- for (;;) {
- r = sd_event_get_state(m->event);
- if (r < 0)
- return r;
- if (r == SD_EVENT_FINISHED)
- return 0;
+ manager_gc(m, true);
- manager_gc(m, true);
+ return hashmap_isempty(m->machines);
+}
- r = sd_event_run(m->event, (uint64_t) -1);
- if (r < 0)
- return r;
- }
+int manager_run(Manager *m) {
+ assert(m);
- return 0;
+ return bus_event_loop_with_idle(
+ m->event,
+ m->bus,
+ "org.freedesktop.machine1",
+ DEFAULT_EXIT_USEC,
+ check_idle, m);
}
int main(int argc, char *argv[]) {
commit 37224a5ff522a366b353e8a01e2c2eee1e5416e5
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Dec 19 21:14:52 2013 +0100
bus: fix exit-on-idle for driverd
diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index d4126a9..46ee349 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -772,6 +772,13 @@ static int connect_bus(Context *c) {
return 0;
}
+static bool check_idle(void *userdata) {
+ Context *c = userdata;
+ assert(c);
+
+ return hashmap_isempty(c->clients);
+}
+
int main(int argc, char *argv[]) {
Context context = {};
Client *c;
@@ -799,7 +806,7 @@ int main(int argc, char *argv[]) {
if (r < 0)
goto finish;
- r = bus_event_loop_with_idle(context.event, context.bus, "org.freedesktop.DBus", DEFAULT_EXIT_USEC);
+ r = bus_event_loop_with_idle(context.event, context.bus, "org.freedesktop.DBus", DEFAULT_EXIT_USEC, check_idle, &context);
if (r < 0) {
log_error("Failed to run event loop: %s", strerror(-r));
goto finish;
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index eb2b35f..e57891b 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -639,7 +639,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC);
+ r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC, NULL, NULL);
if (r < 0) {
log_error("Failed to run event loop: %s", strerror(-r));
goto finish;
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index 4c87e16..f96c293 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -87,7 +87,13 @@ int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {
return 0;
}
-int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout) {
+int bus_event_loop_with_idle(
+ sd_event *e,
+ sd_bus *bus,
+ const char *name,
+ usec_t timeout,
+ check_idle_t check_idle,
+ void *userdata) {
bool exiting = false;
int r, code;
@@ -96,14 +102,20 @@ int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t
assert(name);
for (;;) {
+ bool idle;
+
r = sd_event_get_state(e);
if (r < 0)
return r;
-
if (r == SD_EVENT_FINISHED)
break;
- r = sd_event_run(e, exiting ? (uint64_t) -1 : timeout);
+ if (check_idle)
+ idle = check_idle(userdata);
+ else
+ idle = true;
+
+ r = sd_event_run(e, exiting || !idle ? (uint64_t) -1 : timeout);
if (r < 0)
return r;
diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h
index 9a90c2a..51e1613 100644
--- a/src/libsystemd-bus/bus-util.h
+++ b/src/libsystemd-bus/bus-util.h
@@ -54,7 +54,9 @@ int bus_map_all_properties(sd_bus *bus,
int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name);
-int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout);
+typedef bool (*check_idle_t)(void *userdata);
+
+int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout, check_idle_t check_idle, void *userdata);
int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error);
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 2c90180..a1e0ab6 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -1149,7 +1149,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- r = bus_event_loop_with_idle(event, bus, "org.freedesktop.locale1", DEFAULT_EXIT_USEC);
+ r = bus_event_loop_with_idle(event, bus, "org.freedesktop.locale1", DEFAULT_EXIT_USEC, NULL, NULL);
if (r < 0) {
log_error("Failed to run event loop: %s", strerror(-r));
goto finish;
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 8ac933c..d85ce57 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -857,7 +857,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- r = bus_event_loop_with_idle(event, bus, "org.freedesktop.timedate1", DEFAULT_EXIT_USEC);
+ r = bus_event_loop_with_idle(event, bus, "org.freedesktop.timedate1", DEFAULT_EXIT_USEC, NULL, NULL);
if (r < 0) {
log_error("Failed to run event loop: %s", strerror(-r));
goto finish;
commit ff2ea19264b016bd34232cd9c4820c9547413a9a
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Dec 19 21:13:01 2013 +0100
bus: reenable id change subscriptions
diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 5540d85..dc7237a 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -851,7 +851,7 @@ static int add_name_change_match(sd_bus *bus,
item = m->items;
item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change);
- /* item->id_change.id = name_id; */
+ item->id_change.id = name_id;
/* If the old name is unset or empty, then this can
* match against added ids */
More information about the systemd-commits
mailing list