diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-04-29 08:47:51 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-05-06 16:54:06 +0200 |
commit | be32732168e07b7d52ec77fa67cf93a80a9a8293 (patch) | |
tree | 0feb0a006050702078fd41b5fea2eee9c4d00b08 /src/shared/logs-show.c | |
parent | 0894f08bf14b09ef0436ed11268d43dbcdd88ee7 (diff) | |
download | systemd-be32732168e07b7d52ec77fa67cf93a80a9a8293.tar.gz |
basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.
hashmap_put_strdup() was already doing something similar.
(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)
No functional change intended.
Diffstat (limited to 'src/shared/logs-show.c')
-rw-r--r-- | src/shared/logs-show.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 6737cda1d2..eade4dfbfd 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1133,30 +1133,25 @@ int show_journal_entry( const size_t highlight[2], bool *ellipsized) { - int ret; - _cleanup_set_free_free_ Set *fields = NULL; + _cleanup_set_free_ Set *fields = NULL; + int r; + assert(mode >= 0); assert(mode < _OUTPUT_MODE_MAX); if (n_columns <= 0) n_columns = columns(); - if (output_fields) { - fields = set_new(&string_hash_ops); - if (!fields) - return log_oom(); - - ret = set_put_strdupv(fields, output_fields); - if (ret < 0) - return ret; - } + r = set_put_strdupv(&fields, output_fields); + if (r < 0) + return r; - ret = output_funcs[mode](f, j, mode, n_columns, flags, fields, highlight); + r = output_funcs[mode](f, j, mode, n_columns, flags, fields, highlight); - if (ellipsized && ret > 0) + if (ellipsized && r > 0) *ellipsized = true; - return ret; + return r; } static int maybe_print_begin_newline(FILE *f, OutputFlags *flags) { |