diff options
Diffstat (limited to 'clients/cloud-setup/nm-cloud-setup-utils.c')
-rw-r--r-- | clients/cloud-setup/nm-cloud-setup-utils.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/clients/cloud-setup/nm-cloud-setup-utils.c b/clients/cloud-setup/nm-cloud-setup-utils.c index ff059e7ace..5705c63179 100644 --- a/clients/cloud-setup/nm-cloud-setup-utils.c +++ b/clients/cloud-setup/nm-cloud-setup-utils.c @@ -6,6 +6,7 @@ #include "nm-glib-aux/nm-time-utils.h" #include "nm-glib-aux/nm-logging-base.h" +#include "nm-glib-aux/nm-str-buf.h" /*****************************************************************************/ @@ -257,7 +258,6 @@ _poll_task_data_free (gpointer data) static void _poll_return (PollTaskData *poll_task_data, - gboolean success, GError *error_take) { nm_clear_g_source_inst (&poll_task_data->source_next_poll); @@ -270,7 +270,7 @@ _poll_return (PollTaskData *poll_task_data, if (error_take) g_task_return_error (poll_task_data->task, g_steal_pointer (&error_take)); else - g_task_return_boolean (poll_task_data->task, success); + g_task_return_boolean (poll_task_data->task, TRUE); g_object_unref (poll_task_data->task); } @@ -301,7 +301,7 @@ _poll_done_cb (GObject *source, if ( error || is_finished) { - _poll_return (poll_task_data, TRUE, g_steal_pointer (&error)); + _poll_return (poll_task_data, g_steal_pointer (&error)); return; } @@ -345,8 +345,8 @@ _poll_timeout_cb (gpointer user_data) { PollTaskData *poll_task_data = user_data; - _poll_return (poll_task_data, FALSE, nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN, - "timeout expired")); + _poll_return (poll_task_data, nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN, + "timeout expired")); return G_SOURCE_CONTINUE; } @@ -356,23 +356,22 @@ _poll_cancelled_cb (GObject *object, gpointer user_data) PollTaskData *poll_task_data = user_data; GError *error = NULL; - _LOGD (">> poll cancelled"); nm_clear_g_signal_handler (g_task_get_cancellable (poll_task_data->task), &poll_task_data->cancellable_id); nm_utils_error_set_cancelled (&error, FALSE, NULL); - _poll_return (poll_task_data, FALSE, error); + _poll_return (poll_task_data, error); } /** * nmcs_utils_poll: * @poll_timeout_ms: if >= 0, then this is the overall timeout for how long we poll. - * When this timeout expires, the request completes with failure (but no error set). + * When this timeout expires, the request completes with failure (and error set). * @ratelimit_timeout_ms: if > 0, we ratelimit the starts from one prope_start_fcn * call to the next. * @sleep_timeout_ms: if > 0, then we wait after a probe finished this timeout * before the next. Together with @ratelimit_timeout_ms this determines how * frequently we probe. - * @probe_start_fcn: used to start a (asynchrnous) probe. A probe must be completed + * @probe_start_fcn: used to start a (asynchronous) probe. A probe must be completed * by calling the provided callback. While a probe is in progress, we will not * start another. This function is already invoked the first time synchronously, * during nmcs_utils_poll(). @@ -459,7 +458,8 @@ nmcs_utils_poll (int poll_timeout_ms, * %FALSE will be returned. * If the probe returned a failure, this returns %FALSE and the error * provided by @probe_finish_fcn. - * If the request times out, this returns %FALSE without error set. + * If the request times out, this returns %FALSE with error set. + * Error is always set if (and only if) the function returns %FALSE. */ gboolean nmcs_utils_poll_finish (GAsyncResult *result, @@ -565,15 +565,13 @@ nmcs_utils_uri_build_concat_v (const char *base, const char **components, gsize n_components) { - GString *uri; + NMStrBuf strbuf = NM_STR_BUF_INIT (NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE); nm_assert (base); nm_assert (base[0]); nm_assert (!NM_STR_HAS_SUFFIX (base, "/")); - uri = g_string_sized_new (100); - - g_string_append (uri, base); + nm_str_buf_append (&strbuf, base); if ( n_components > 0 && components[0] @@ -583,18 +581,18 @@ nmcs_utils_uri_build_concat_v (const char *base, * * We only do that for the first component. */ } else - g_string_append_c (uri, '/'); + nm_str_buf_append_c (&strbuf, '/'); while (n_components > 0) { if (!components[0]) { - /* we allow NULL, to indicate nothing to append*/ + /* we allow NULL, to indicate nothing to append */ } else - g_string_append (uri, components[0]); + nm_str_buf_append (&strbuf, components[0]); components++; n_components--; } - return g_string_free (uri, FALSE); + return nm_str_buf_finalize (&strbuf, NULL); } /*****************************************************************************/ |