diff options
author | Ben Pfaff <blp@ovn.org> | 2017-12-13 11:32:28 -0800 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-12-13 11:32:29 -0800 |
commit | 3865965dd99325bd7bcd5bd3ab2a5d059dd4832e (patch) | |
tree | 53341d4fb9f22465871db4d83b92babb9012b5a2 /lib | |
parent | dc92f724d4641bcf9fce95db262f314264e473af (diff) | |
download | openvswitch-3865965dd99325bd7bcd5bd3ab2a5d059dd4832e.tar.gz |
ovsdb-error: New function ovsdb_error_to_string_free().
This allows slight code simplifications across the tree.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Tested-by: Yifeng Sun <pkusunyifeng@gmail.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ovsdb-data.c | 5 | ||||
-rw-r--r-- | lib/ovsdb-error.c | 29 | ||||
-rw-r--r-- | lib/ovsdb-error.h | 3 | ||||
-rw-r--r-- | lib/ovsdb-idl.c | 9 |
4 files changed, 30 insertions, 16 deletions
diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 5d560fd98..3ddf5f5bd 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -664,8 +664,7 @@ ovsdb_atom_from_string(union ovsdb_atom *atom, free(*range_end_atom); *range_end_atom = NULL; } - msg = ovsdb_error_to_string(error); - ovsdb_error_destroy(error); + msg = ovsdb_error_to_string_free(error); } return msg; } diff --git a/lib/ovsdb-error.c b/lib/ovsdb-error.c index d8161e6d7..9b1af68c6 100644 --- a/lib/ovsdb-error.c +++ b/lib/ovsdb-error.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2011, 2012, 2016, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,11 +153,9 @@ ovsdb_internal_error(struct ovsdb_error *inner_error, ds_put_format(&ds, " (%s %s)", program_name, VERSION); if (inner_error) { - char *s = ovsdb_error_to_string(inner_error); + char *s = ovsdb_error_to_string_free(inner_error); ds_put_format(&ds, " (generated from: %s)", s); free(s); - - ovsdb_error_destroy(inner_error); } error = ovsdb_error("internal error", "%s", ds_cstr(&ds)); @@ -223,6 +221,8 @@ ovsdb_error_to_json(const struct ovsdb_error *error) return json; } +/* Returns 'error' converted to a string suitable for use as an error message. + * The caller must free the returned string (with free()). */ char * ovsdb_error_to_string(const struct ovsdb_error *error) { @@ -240,6 +240,24 @@ ovsdb_error_to_string(const struct ovsdb_error *error) return ds_steal_cstr(&ds); } +/* Returns 'error' converted to a string suitable for use as an error message. + * The caller must free the returned string (with free()). + * + * If 'error' is NULL, returns NULL. + * + * Also, frees 'error'. */ +char * +ovsdb_error_to_string_free(struct ovsdb_error *error) +{ + if (error) { + char *s = ovsdb_error_to_string(error); + ovsdb_error_destroy(error); + return s; + } else { + return NULL; + } +} + const char * ovsdb_error_get_tag(const struct ovsdb_error *error) { @@ -254,9 +272,8 @@ ovsdb_error_assert(struct ovsdb_error *error) { if (error) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); - char *s = ovsdb_error_to_string(error); + char *s = ovsdb_error_to_string_free(error); VLOG_ERR_RL(&rl, "unexpected ovsdb error: %s", s); free(s); - ovsdb_error_destroy(error); } } diff --git a/lib/ovsdb-error.h b/lib/ovsdb-error.h index da91b7499..ff9b889a8 100644 --- a/lib/ovsdb-error.h +++ b/lib/ovsdb-error.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2011, 2016, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,6 +64,7 @@ struct ovsdb_error *ovsdb_error_clone(const struct ovsdb_error *) OVS_WARN_UNUSED_RESULT; char *ovsdb_error_to_string(const struct ovsdb_error *); +char *ovsdb_error_to_string_free(struct ovsdb_error *); struct json *ovsdb_error_to_json(const struct ovsdb_error *); const char *ovsdb_error_get_tag(const struct ovsdb_error *); diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 2a3405b6f..96e5c1f58 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -1455,10 +1455,9 @@ ovsdb_idl_send_schema_request(struct ovsdb_idl *idl) static void log_error(struct ovsdb_error *error) { - char *s = ovsdb_error_to_string(error); + char *s = ovsdb_error_to_string_free(error); VLOG_WARN("error parsing database schema: %s", s); free(s); - ovsdb_error_destroy(error); } /* Frees 'schema', which is in the format returned by parse_schema(). */ @@ -1976,12 +1975,11 @@ ovsdb_idl_row_change__(struct ovsdb_idl_row *row, const struct json *row_json, ovsdb_datum_destroy(&datum, &column->type); } else { - char *s = ovsdb_error_to_string(error); + char *s = ovsdb_error_to_string_free(error); VLOG_WARN_RL(&syntax_rl, "error parsing column %s in row "UUID_FMT " in table %s: %s", column_name, UUID_ARGS(&row->uuid), table->class_->name, s); free(s); - ovsdb_error_destroy(error); } } return changed; @@ -4186,11 +4184,10 @@ ovsdb_idl_txn_process_insert_reply(struct ovsdb_idl_txn_insert *insert, error = ovsdb_atom_from_json(&uuid, &uuid_type, json_uuid, NULL); if (error) { - char *s = ovsdb_error_to_string(error); + char *s = ovsdb_error_to_string_free(error); VLOG_WARN_RL(&syntax_rl, "\"insert\" reply \"uuid\" is not a JSON " "UUID: %s", s); free(s); - ovsdb_error_destroy(error); return false; } |