diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2012-10-30 14:29:38 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2012-10-30 15:41:15 +0100 |
commit | f8b69d1dfc307562a353f6aa923b7c2b915aaddb (patch) | |
tree | 79a9776e85e7f9ad9ca944665cc428be480789f3 /src/core/dbus-manager.c | |
parent | 26acfdae44e3605788420432d28a7264214d1213 (diff) |
shared, core: do not always accept numbers in string lookups
The behaviour of the common name##_from_string conversion is surprising.
It accepts not only the strings from name##_table but also any number
that falls within the range of the table. The order of items in most of
our tables is an internal affair. It should not be visible to the user.
I know of a case where the surprising numeric conversion leads to a crash.
We will allow the direct numeric conversion only for the tables where the
mapping of strings to numeric values has an external meaning. This holds
for the following lookup tables:
- netlink_family, ioprio_class, ip_tos, sched_policy - their numeric
values are stable as they are defined by the Linux kernel interface.
- log_level, log_facility_unshifted - the well-known syslog interface.
We allow the user to use numeric values whose string names systemd does
not know. For instance, the user may want to test a new kernel featuring
a scheduling policy that did not exist when his systemd version was
released. A slightly unpleasant effect of this is that the
name##_to_string conversion cannot return pointers to constant strings
anymore. The strings have to be allocated on demand and freed by the
caller.
Diffstat (limited to 'src/core/dbus-manager.c')
-rw-r--r-- | src/core/dbus-manager.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index ed9784b58f..2010241e6a 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -352,17 +352,21 @@ static int bus_manager_set_log_target(DBusMessageIter *i, const char *property, } static int bus_manager_append_log_level(DBusMessageIter *i, const char *property, void *data) { - const char *t; + char *t; + int r; assert(i); assert(property); - t = log_level_to_string(log_get_max_level()); + r = log_level_to_string_alloc(log_get_max_level(), &t); + if (r < 0) + return r; if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t)) - return -ENOMEM; + r = -ENOMEM; - return 0; + free(t); + return r; } static int bus_manager_set_log_level(DBusMessageIter *i, const char *property, void *data) { |