[systemd-commits] 7 commits - TODO src/bus-proxyd src/libsystemd src/machine
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Jan 7 11:48:56 PST 2015
TODO | 4 +
src/bus-proxyd/bus-proxyd.c | 4 -
src/libsystemd/sd-bus/bus-control.c | 14 ++++++
src/libsystemd/sd-bus/bus-kernel.c | 80 +++++++++++++++++++++++-------------
src/libsystemd/sd-bus/bus-message.c | 20 +++++++++
src/libsystemd/sd-bus/bus-message.h | 3 +
src/libsystemd/sd-bus/busctl.c | 8 +++
src/libsystemd/sd-bus/sd-bus.c | 27 ++++++------
src/machine/machinectl.c | 60 +++++++++++++++++++++++----
9 files changed, 168 insertions(+), 52 deletions(-)
New commits:
commit 92d66625794057081046f051f7564e0789de0ace
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 20:42:14 2015 +0100
busctl: exit cleanly when the bus connection is severed
diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c
index c9eeb91..c0d51e0 100644
--- a/src/libsystemd/sd-bus/busctl.c
+++ b/src/libsystemd/sd-bus/busctl.c
@@ -1127,6 +1127,8 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL
return log_error_errno(r, "Failed to add match: %m");
}
+ log_info("Monitoring bus message stream.");
+
for (;;) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
@@ -1136,6 +1138,12 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL
if (m) {
dump(m, stdout);
+
+ if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected") > 0) {
+ log_info("Connection terminated, exiting.");
+ return 0;
+ }
+
continue;
}
commit 52cd587789b9452e6e7d5f2f9b2ea652f9ad036e
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 20:36:23 2015 +0100
sd-bus: when we synthesize messages, initialize timestamps ourselves
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 4b1c60e..15180d0 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -1528,6 +1528,16 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
assert(b);
assert(m);
+ /* Fake some timestamps, if they were requested, and not
+ * already initialized */
+ if (b->attach_flags & KDBUS_ATTACH_TIMESTAMP) {
+ if (m->realtime <= 0)
+ m->realtime = now(CLOCK_REALTIME);
+
+ if (m->monotonic <= 0)
+ m->monotonic = now(CLOCK_MONOTONIC);
+ }
+
/* The bus specification says the serial number cannot be 0,
* hence let's fill something in for synthetic messages. Since
* synthetic messages might have a fake sender and we don't
@@ -1535,7 +1545,6 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
* pick a fixed, artificial one. We use (uint32_t) -1 rather
* than (uint64_t) -1 since dbus1 only had 32bit identifiers,
* even though kdbus can do 64bit. */
-
return bus_message_seal(m, 0xFFFFFFFFULL, 0);
}
@@ -2237,6 +2246,11 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
if (r < 0)
return r;
+ /* Copy over original timestamp */
+ synthetic_reply->realtime = m->realtime;
+ synthetic_reply->monotonic = m->monotonic;
+ synthetic_reply->seqnum = m->seqnum;
+
r = bus_seal_synthetic_message(bus, synthetic_reply);
if (r < 0)
return r;
commit d29ae2914e1146f45ff4104faafef5331837bed7
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 20:25:30 2015 +0100
sd-bus: unify how we set the sender of synthetic messages
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 4dcea8e..7c946e6 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -379,15 +379,6 @@ fail:
return r;
}
-static void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m) {
- assert(bus);
- assert(m);
-
- m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus";
- m->creds.well_known_names_driver = true;
- m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
-}
-
static void unset_memfds(struct sd_bus_message *m) {
struct bus_body_part *part;
unsigned i;
@@ -1274,7 +1265,6 @@ static int translate_reply(
if (r < 0)
return r;
- bus_message_set_sender_driver(bus, m);
message_set_timestamp(bus, m, ts);
r = bus_seal_synthetic_message(bus, m);
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index 0f9334b..f352c72 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -754,6 +754,24 @@ _public_ int sd_bus_message_new_method_errnof(
return sd_bus_message_new_method_error(call, m, &berror);
}
+void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) {
+ assert(bus);
+ assert(m);
+
+ m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus.Local";
+ m->creds.well_known_names_local = true;
+ m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
+}
+
+void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m) {
+ assert(bus);
+ assert(m);
+
+ m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus";
+ m->creds.well_known_names_driver = true;
+ m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
+}
+
int bus_message_new_synthetic_error(
sd_bus *bus,
uint64_t cookie,
@@ -796,6 +814,8 @@ int bus_message_new_synthetic_error(
t->error._need_free = -1;
+ bus_message_set_sender_driver(bus, t);
+
*m = t;
return 0;
diff --git a/src/libsystemd/sd-bus/bus-message.h b/src/libsystemd/sd-bus/bus-message.h
index 4dd280d..b4cdce7 100644
--- a/src/libsystemd/sd-bus/bus-message.h
+++ b/src/libsystemd/sd-bus/bus-message.h
@@ -235,3 +235,6 @@ int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_e
int bus_message_remarshal(sd_bus *bus, sd_bus_message **m);
int bus_message_append_sender(sd_bus_message *m, const char *sender);
+
+void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m);
+void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m);
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index a8d03b8..4b1c60e 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -2140,8 +2140,6 @@ static int process_timeout(sd_bus *bus) {
if (r < 0)
return r;
- m->sender = "org.freedesktop.DBus";
-
r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;
@@ -2544,15 +2542,6 @@ null_message:
return r;
}
-static void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) {
- assert(bus);
- assert(m);
-
- m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus.Local";
- m->creds.well_known_names_local = true;
- m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
-}
-
static int process_closing(sd_bus *bus, sd_bus_message **ret) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
struct reply_callback *c;
commit 76877fb9ccb7f9f921ea921cf692f4d2774d590c
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 19:53:39 2015 +0100
sd-bus: make use of the newly added timestamps on kdbus kernel messages
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 5b193be..4dcea8e 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -400,6 +400,21 @@ static void unset_memfds(struct sd_bus_message *m) {
part->memfd = -1;
}
+static void message_set_timestamp(sd_bus *bus, sd_bus_message *m, const struct kdbus_timestamp *ts) {
+ assert(bus);
+ assert(m);
+
+ if (!ts)
+ return;
+
+ if (!(bus->attach_flags & KDBUS_ATTACH_TIMESTAMP))
+ return;
+
+ m->realtime = ts->realtime_ns / NSEC_PER_USEC;
+ m->monotonic = ts->monotonic_ns / NSEC_PER_USEC;
+ m->seqnum = ts->seqnum;
+}
+
static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
sd_bus_message *m = NULL;
struct kdbus_item *d;
@@ -620,13 +635,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
break;
case KDBUS_ITEM_TIMESTAMP:
-
- if (bus->attach_flags & KDBUS_ATTACH_TIMESTAMP) {
- m->realtime = d->timestamp.realtime_ns / NSEC_PER_USEC;
- m->monotonic = d->timestamp.monotonic_ns / NSEC_PER_USEC;
- m->seqnum = d->timestamp.seqnum;
- }
-
+ message_set_timestamp(bus, m, &d->timestamp);
break;
case KDBUS_ITEM_PID_COMM:
@@ -1154,7 +1163,13 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
return 1;
}
-static int push_name_owner_changed(sd_bus *bus, const char *name, const char *old_owner, const char *new_owner) {
+static int push_name_owner_changed(
+ sd_bus *bus,
+ const char *name,
+ const char *old_owner,
+ const char *new_owner,
+ const struct kdbus_timestamp *ts) {
+
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
int r;
@@ -1174,6 +1189,7 @@ static int push_name_owner_changed(sd_bus *bus, const char *name, const char *ol
return r;
bus_message_set_sender_driver(bus, m);
+ message_set_timestamp(bus, m, ts);
r = bus_seal_synthetic_message(bus, m);
if (r < 0)
@@ -1185,7 +1201,12 @@ static int push_name_owner_changed(sd_bus *bus, const char *name, const char *ol
return 1;
}
-static int translate_name_change(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *d) {
+static int translate_name_change(
+ sd_bus *bus,
+ const struct kdbus_msg *k,
+ const struct kdbus_item *d,
+ const struct kdbus_timestamp *ts) {
+
char new_owner[UNIQUE_NAME_MAX], old_owner[UNIQUE_NAME_MAX];
assert(bus);
@@ -1206,10 +1227,15 @@ static int translate_name_change(sd_bus *bus, struct kdbus_msg *k, struct kdbus_
} else
sprintf(new_owner, ":1.%llu", (unsigned long long) d->name_change.new_id.id);
- return push_name_owner_changed(bus, d->name_change.name, old_owner, new_owner);
+ return push_name_owner_changed(bus, d->name_change.name, old_owner, new_owner, ts);
}
-static int translate_id_change(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *d) {
+static int translate_id_change(
+ sd_bus *bus,
+ const struct kdbus_msg *k,
+ const struct kdbus_item *d,
+ const struct kdbus_timestamp *ts) {
+
char owner[UNIQUE_NAME_MAX];
assert(bus);
@@ -1221,10 +1247,16 @@ static int translate_id_change(sd_bus *bus, struct kdbus_msg *k, struct kdbus_it
return push_name_owner_changed(
bus, owner,
d->type == KDBUS_ITEM_ID_ADD ? NULL : owner,
- d->type == KDBUS_ITEM_ID_ADD ? owner : NULL);
+ d->type == KDBUS_ITEM_ID_ADD ? owner : NULL,
+ ts);
}
-static int translate_reply(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *d) {
+static int translate_reply(
+ sd_bus *bus,
+ const struct kdbus_msg *k,
+ const struct kdbus_item *d,
+ const struct kdbus_timestamp *ts) {
+
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
int r;
@@ -1243,6 +1275,7 @@ static int translate_reply(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *
return r;
bus_message_set_sender_driver(bus, m);
+ message_set_timestamp(bus, m, ts);
r = bus_seal_synthetic_message(bus, m);
if (r < 0)
@@ -1255,9 +1288,7 @@ static int translate_reply(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *
}
static int bus_kernel_translate_message(sd_bus *bus, struct kdbus_msg *k) {
- struct kdbus_item *d, *found = NULL;
-
- static int (* const translate[])(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *d) = {
+ static int (* const translate[])(sd_bus *bus, const struct kdbus_msg *k, const struct kdbus_item *d, const struct kdbus_timestamp *ts) = {
[KDBUS_ITEM_NAME_ADD - _KDBUS_ITEM_KERNEL_BASE] = translate_name_change,
[KDBUS_ITEM_NAME_REMOVE - _KDBUS_ITEM_KERNEL_BASE] = translate_name_change,
[KDBUS_ITEM_NAME_CHANGE - _KDBUS_ITEM_KERNEL_BASE] = translate_name_change,
@@ -1269,13 +1300,16 @@ static int bus_kernel_translate_message(sd_bus *bus, struct kdbus_msg *k) {
[KDBUS_ITEM_REPLY_DEAD - _KDBUS_ITEM_KERNEL_BASE] = translate_reply,
};
+ struct kdbus_item *d, *found = NULL;
+ struct kdbus_timestamp *ts = NULL;
+
assert(bus);
assert(k);
assert(k->payload_type == KDBUS_PAYLOAD_KERNEL);
KDBUS_ITEM_FOREACH(d, k, items) {
if (d->type == KDBUS_ITEM_TIMESTAMP)
- continue;
+ ts = &d->timestamp;
if (d->type >= _KDBUS_ITEM_KERNEL_BASE && d->type < _KDBUS_ITEM_KERNEL_BASE + ELEMENTSOF(translate)) {
if (found)
@@ -1290,7 +1324,7 @@ static int bus_kernel_translate_message(sd_bus *bus, struct kdbus_msg *k) {
return 0;
}
- return translate[found->type - _KDBUS_ITEM_KERNEL_BASE](bus, k, found);
+ return translate[found->type - _KDBUS_ITEM_KERNEL_BASE](bus, k, found, ts);
}
int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority) {
commit 210a68826fac0f6525719cc6044c7858c655986a
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 19:29:14 2015 +0100
sd-bus: always catch name requests for the special names "org.freedesktop.DBus" and "org.freedesktop.DBus.Local" and refuse them
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index fc70cce..a7818f5 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -829,10 +829,6 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic
if (r < 0)
return synthetic_reply_method_errno(m, r, NULL);
- if (streq(name, "org.freedesktop.DBus"))
- return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS,
- "Connection is not allowed to own the org.freedesktop.DBus service."));
-
if (policy && !policy_check_own(policy, ucred->uid, ucred->gid, name))
return synthetic_reply_method_errno(m, -EPERM, NULL);
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index b2394db..2db1afb 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -137,6 +137,10 @@ _public_ int sd_bus_request_name(sd_bus *bus, const char *name, uint64_t flags)
assert_return(service_name_is_valid(name), -EINVAL);
assert_return(name[0] != ':', -EINVAL);
+ /* Don't allow requesting the special driver and local names */
+ if (STR_IN_SET(name, "org.freedesktop.DBus", "org.freedesktop.DBus.Local"))
+ return -EINVAL;
+
if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN;
@@ -215,6 +219,10 @@ _public_ int sd_bus_release_name(sd_bus *bus, const char *name) {
assert_return(service_name_is_valid(name), -EINVAL);
assert_return(name[0] != ':', -EINVAL);
+ /* Don't allow requesting the special driver and local names */
+ if (STR_IN_SET(name, "org.freedesktop.DBus", "org.freedesktop.DBus.Local"))
+ return -EINVAL;
+
if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN;
@@ -614,6 +622,9 @@ int bus_get_name_creds_kdbus(
uint64_t id;
int r;
+ if (streq(name, "org.freedesktop.DBus"))
+ return -ENOTSUP;
+
r = bus_kernel_parse_unique_name(name, &id);
if (r < 0)
return r;
@@ -871,6 +882,9 @@ _public_ int sd_bus_get_name_creds(
assert_return(service_name_is_valid(name), -EINVAL);
assert_return(bus->bus_client, -ENODATA);
+ if (streq(name, "org.freedesktop.DBus.Local"))
+ return -EINVAL;
+
if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN;
commit b80c66ba9836456de5260e4a1b696ba25561f613
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 19:18:04 2015 +0100
update TODO
diff --git a/TODO b/TODO
index 605d6b9..7a7e4df 100644
--- a/TODO
+++ b/TODO
@@ -45,6 +45,10 @@ Release 219 preparations:
Features:
+* "machinectl list-images" should show os-release data
+
+* should we set nocow chattr attribute on journal files by default? does this have any drawbacks?
+
* nspawn: when start a container "foobar" look for its configuration in a file "foobar.nspawn" in /etc/systemd/nspawn/ as well as next to the actualy directory or image to boot
* Port various tools to make use of verbs.[ch], where applicable
commit 0b63e2789f984e84f40bf6e49f5da15c87298ced
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 19:13:48 2015 +0100
machinectl: prettify "machinectl list" output
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index be3896a..c80114c 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -74,13 +74,27 @@ static void pager_open_if_enabled(void) {
pager_open(false);
}
+typedef struct MachineInfo {
+ const char *name;
+ const char *class;
+ const char *service;
+} MachineInfo;
+
+static int compare_machine_info(const void *a, const void *b) {
+ const MachineInfo *x = a, *y = b;
+
+ return strcmp(x->name, y->name);
+}
+
static int list_machines(int argc, char *argv[], void *userdata) {
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ size_t max_name = strlen("MACHINE"), max_class = strlen("CLASS"), max_service = strlen("SERVICE");
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ _cleanup_free_ MachineInfo *machines = NULL;
const char *name, *class, *service, *object;
+ size_t n_machines = 0, n_allocated = 0, j;
sd_bus *bus = userdata;
- unsigned k = 0;
int r;
assert(bus);
@@ -101,17 +115,33 @@ static int list_machines(int argc, char *argv[], void *userdata) {
return r;
}
- if (arg_legend)
- printf("%-32s %-9s %-16s\n", "MACHINE", "CONTAINER", "SERVICE");
-
r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssso)");
if (r < 0)
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(reply, "(ssso)", &name, &class, &service, &object)) > 0) {
- printf("%-32s %-9s %-16s\n", name, class, service);
+ size_t l;
+
+ if (!GREEDY_REALLOC(machines, n_allocated, n_machines + 1))
+ return log_oom();
+
+ machines[n_machines].name = name;
+ machines[n_machines].class = class;
+ machines[n_machines].service = service;
+
+ l = strlen(name);
+ if (l > max_name)
+ max_name = l;
- k++;
+ l = strlen(class);
+ if (l > max_class)
+ max_class = l;
+
+ l = strlen(service);
+ if (l > max_service)
+ max_service = l;
+
+ n_machines ++;
}
if (r < 0)
return bus_log_parse_error(r);
@@ -120,8 +150,22 @@ static int list_machines(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
+ qsort_safe(machines, n_machines, sizeof(MachineInfo), compare_machine_info);
+
+ if (arg_legend)
+ printf("%-*s %-*s %-*s\n",
+ (int) max_name, "MACHINE",
+ (int) max_class, "CLASS",
+ (int) max_service, "SERVICE");
+
+ for (j = 0; j < n_machines; j++)
+ printf("%-*s %-*s %-*s\n",
+ (int) max_name, machines[j].name,
+ (int) max_class, machines[j].class,
+ (int) max_service, machines[j].service);
+
if (arg_legend)
- printf("\n%u machines listed.\n", k);
+ printf("\n%zu machines listed.\n", n_machines);
return 0;
}
More information about the systemd-commits
mailing list