mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-11 05:10:22 +01:00
clients,libnm,tests: merge branch '3v1n0:gtask-initables' (part 1)
Merge a subset of the patches from !263. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/263
This commit is contained in:
commit
1224bb19a6
4 changed files with 98 additions and 118 deletions
|
|
@ -1185,14 +1185,13 @@ nmc_parse_lldp_capabilities (guint value)
|
|||
static void
|
||||
command_done (GObject *object, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple = (GSimpleAsyncResult *)res;
|
||||
GTask *task = G_TASK (res);
|
||||
NmCli *nmc = user_data;
|
||||
GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, &error)) {
|
||||
if (!g_task_propagate_boolean (task, &error)) {
|
||||
nmc->return_value = error->code;
|
||||
g_string_assign (nmc->return_text, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
if (!nmc->should_wait)
|
||||
|
|
@ -1200,40 +1199,42 @@ command_done (GObject *object, GAsyncResult *res, gpointer user_data)
|
|||
}
|
||||
|
||||
typedef struct {
|
||||
NmCli *nmc;
|
||||
const NMCCommand *cmd;
|
||||
int argc;
|
||||
char **argv;
|
||||
GSimpleAsyncResult *simple;
|
||||
GTask *task;
|
||||
} CmdCall;
|
||||
|
||||
static void
|
||||
call_cmd (NmCli *nmc, GSimpleAsyncResult *simple, const NMCCommand *cmd, int argc, char **argv);
|
||||
call_cmd (NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, char **argv);
|
||||
|
||||
static void
|
||||
got_client (GObject *source_object, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gs_unref_object GTask *task = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
CmdCall *call = user_data;
|
||||
NmCli *nmc = call->nmc;
|
||||
NmCli *nmc;
|
||||
|
||||
task = g_steal_pointer (&call->task);
|
||||
nmc = g_task_get_task_data (task);
|
||||
|
||||
nmc->should_wait--;
|
||||
nmc->client = nm_client_new_finish (res, &error);
|
||||
|
||||
if (!nmc->client) {
|
||||
g_simple_async_result_set_error (call->simple, NMCLI_ERROR, NMC_RESULT_ERROR_UNKNOWN,
|
||||
_("Error: Could not create NMClient object: %s."), error->message);
|
||||
g_error_free (error);
|
||||
g_simple_async_result_complete (call->simple);
|
||||
g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_UNKNOWN,
|
||||
_("Error: Could not create NMClient object: %s."),
|
||||
error->message);
|
||||
} else {
|
||||
call_cmd (nmc, call->simple, call->cmd, call->argc, call->argv);
|
||||
call_cmd (nmc, g_steal_pointer (&task), call->cmd, call->argc, call->argv);
|
||||
}
|
||||
|
||||
g_slice_free (CmdCall, call);
|
||||
}
|
||||
|
||||
static void
|
||||
call_cmd (NmCli *nmc, GSimpleAsyncResult *simple, const NMCCommand *cmd, int argc, char **argv)
|
||||
call_cmd (NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, char **argv)
|
||||
{
|
||||
CmdCall *call;
|
||||
|
||||
|
|
@ -1241,20 +1242,23 @@ call_cmd (NmCli *nmc, GSimpleAsyncResult *simple, const NMCCommand *cmd, int arg
|
|||
|
||||
/* Check whether NetworkManager is running */
|
||||
if (cmd->needs_nm_running && !nm_client_get_nm_running (nmc->client)) {
|
||||
g_simple_async_result_set_error (simple, NMCLI_ERROR, NMC_RESULT_ERROR_NM_NOT_RUNNING,
|
||||
_("Error: NetworkManager is not running."));
|
||||
} else
|
||||
g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_NM_NOT_RUNNING,
|
||||
_("Error: NetworkManager is not running."));
|
||||
} else {
|
||||
nmc->return_value = cmd->func (nmc, argc, argv);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
}
|
||||
|
||||
g_object_unref (task);
|
||||
} else {
|
||||
nm_assert (nmc->client == NULL);
|
||||
|
||||
nmc->should_wait++;
|
||||
call = g_slice_new0 (CmdCall);
|
||||
call->nmc = nmc;
|
||||
call->cmd = cmd;
|
||||
call->argc = argc;
|
||||
call->argv = argv;
|
||||
call->simple = simple;
|
||||
call->task = task;
|
||||
nm_client_new_async (NULL, got_client, call);
|
||||
}
|
||||
}
|
||||
|
|
@ -1290,16 +1294,14 @@ void
|
|||
nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char **argv)
|
||||
{
|
||||
const NMCCommand *c;
|
||||
GSimpleAsyncResult *simple;
|
||||
gs_unref_object GTask *task = NULL;
|
||||
|
||||
simple = g_simple_async_result_new (NULL,
|
||||
command_done,
|
||||
nmc,
|
||||
nmc_do_cmd);
|
||||
task = g_task_new (NULL, NULL, command_done, nmc);
|
||||
g_task_set_source_tag (task, nmc_do_cmd);
|
||||
g_task_set_task_data (task, nmc, NULL);
|
||||
|
||||
if (argc == 0 && nmc->complete) {
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1309,8 +1311,7 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char
|
|||
g_print ("%s\n", c->cmd);
|
||||
}
|
||||
nmc_complete_help (cmd);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1325,32 +1326,26 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char
|
|||
nmc_complete_help (*(argv+1));
|
||||
if (!nmc->complete && c->usage && nmc_arg_is_help (*(argv+1))) {
|
||||
c->usage ();
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
} else {
|
||||
call_cmd (nmc, simple, c, argc, argv);
|
||||
call_cmd (nmc, g_steal_pointer (&task), c, argc, argv);
|
||||
}
|
||||
} else if (cmd) {
|
||||
/* Not a known command. */
|
||||
if (nmc_arg_is_help (cmd) && c->usage) {
|
||||
c->usage ();
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
} else {
|
||||
g_simple_async_result_set_error (simple, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
_("Error: argument '%s' not understood. Try passing --help instead."), cmd);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
_("Error: argument '%s' not understood. Try passing --help instead."), cmd);
|
||||
}
|
||||
} else if (c->func) {
|
||||
/* No command, run the default handler. */
|
||||
call_cmd (nmc, simple, c, argc, argv);
|
||||
call_cmd (nmc, g_steal_pointer (&task), c, argc, argv);
|
||||
} else {
|
||||
/* No command and no default handler. */
|
||||
g_simple_async_result_set_error (simple, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
_("Error: missing argument. Try passing --help."));
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
_("Error: missing argument. Try passing --help."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -425,15 +425,29 @@ class AsyncProcess():
|
|||
|
||||
self.start()
|
||||
|
||||
Util.popen_wait(self._p, 2000)
|
||||
error = False
|
||||
try:
|
||||
Util.popen_wait(self._p, 2000)
|
||||
except Exception as e:
|
||||
error = True
|
||||
raise e
|
||||
finally:
|
||||
(returncode, stdout, stderr) = (self._p.returncode,
|
||||
self._p.stdout.read(),
|
||||
self._p.stderr.read())
|
||||
|
||||
(returncode, stdout, stderr) = (self._p.returncode, self._p.stdout.read(), self._p.stderr.read())
|
||||
self._p.stdout.close()
|
||||
self._p.stderr.close()
|
||||
self._p = None
|
||||
|
||||
self._p.stdout.close()
|
||||
self._p.stderr.close()
|
||||
self._p = None
|
||||
if error:
|
||||
print(stdout)
|
||||
print(stderr)
|
||||
|
||||
self._complete_cb(self, returncode, stdout, stderr)
|
||||
try:
|
||||
self._complete_cb(self, returncode, stdout, stderr)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
|
|
|||
|
|
@ -978,70 +978,60 @@ init_common (NMSecretAgentOld *self)
|
|||
G_CALLBACK (name_owner_changed), self);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
NMSecretAgentOld *self;
|
||||
GCancellable *cancellable;
|
||||
GSimpleAsyncResult *simple;
|
||||
} InitData;
|
||||
|
||||
static void
|
||||
init_async_complete (InitData *init_data, GError *error)
|
||||
{
|
||||
if (!error)
|
||||
g_simple_async_result_set_op_res_gboolean (init_data->simple, TRUE);
|
||||
else
|
||||
g_simple_async_result_take_error (init_data->simple, error);
|
||||
|
||||
g_simple_async_result_complete_in_idle (init_data->simple);
|
||||
|
||||
g_object_unref (init_data->simple);
|
||||
g_clear_object (&init_data->cancellable);
|
||||
g_slice_free (InitData, init_data);
|
||||
}
|
||||
|
||||
static void
|
||||
init_async_registered (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
NMSecretAgentOld *self = NM_SECRET_AGENT_OLD (object);
|
||||
InitData *init_data = user_data;
|
||||
gs_unref_object GTask *task = user_data;
|
||||
NMSecretAgentOld *self = g_task_get_source_object (task);
|
||||
GError *error = NULL;
|
||||
|
||||
nm_secret_agent_old_register_finish (self, result, &error);
|
||||
init_async_complete (init_data, error);
|
||||
|
||||
if (error)
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_task_return_boolean (task, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
InitData *init_data = user_data;
|
||||
NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (init_data->self);
|
||||
gs_unref_object GTask *task = user_data;
|
||||
NMSecretAgentOld *self = g_task_get_source_object (task);
|
||||
NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self);
|
||||
GError *error = NULL;
|
||||
|
||||
priv->manager_proxy = nmdbus_agent_manager_proxy_new_finish (result, &error);
|
||||
if (!priv->manager_proxy) {
|
||||
init_async_complete (init_data, error);
|
||||
g_task_return_error (task, error);
|
||||
return;
|
||||
}
|
||||
|
||||
init_common (init_data->self);
|
||||
init_common (self);
|
||||
|
||||
if (priv->auto_register) {
|
||||
nm_secret_agent_old_register_async (init_data->self, init_data->cancellable,
|
||||
init_async_registered, init_data);
|
||||
} else
|
||||
init_async_complete (init_data, NULL);
|
||||
if (!priv->auto_register) {
|
||||
g_task_return_boolean (task, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
nm_secret_agent_old_register_async (self,
|
||||
g_task_get_cancellable (task),
|
||||
init_async_registered,
|
||||
task);
|
||||
g_steal_pointer (&task);
|
||||
}
|
||||
|
||||
static void
|
||||
init_async_got_bus (GObject *initable, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
InitData *init_data = user_data;
|
||||
NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (init_data->self);
|
||||
gs_unref_object GTask *task = user_data;
|
||||
NMSecretAgentOld *self = g_task_get_source_object (task);
|
||||
NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self);
|
||||
GError *error = NULL;
|
||||
|
||||
priv->bus = g_bus_get_finish (result, &error);
|
||||
if (!priv->bus) {
|
||||
init_async_complete (init_data, error);
|
||||
g_task_return_error (task, error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1050,8 +1040,10 @@ init_async_got_bus (GObject *initable, GAsyncResult *result, gpointer user_data)
|
|||
| G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
||||
NM_DBUS_SERVICE,
|
||||
NM_DBUS_PATH_AGENT_MANAGER,
|
||||
init_data->cancellable,
|
||||
init_async_got_proxy, init_data);
|
||||
g_task_get_cancellable (task),
|
||||
init_async_got_proxy,
|
||||
task);
|
||||
g_steal_pointer (&task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -1164,37 +1156,15 @@ init_async (GAsyncInitable *initable, int io_priority,
|
|||
GCancellable *cancellable, GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSecretAgentOld *self = NM_SECRET_AGENT_OLD (initable);
|
||||
InitData *init_data;
|
||||
GTask *task;
|
||||
|
||||
init_data = g_slice_new (InitData);
|
||||
*init_data = (InitData) {
|
||||
.self = self,
|
||||
.cancellable = nm_g_object_ref (cancellable),
|
||||
.simple = g_simple_async_result_new (G_OBJECT (initable),
|
||||
callback,
|
||||
user_data,
|
||||
init_async),
|
||||
};
|
||||
|
||||
if (cancellable)
|
||||
g_simple_async_result_set_check_cancellable (init_data->simple, cancellable);
|
||||
task = g_task_new (initable, cancellable, callback, user_data);
|
||||
g_task_set_priority (task, io_priority);
|
||||
|
||||
g_bus_get (_nm_dbus_bus_type (),
|
||||
cancellable,
|
||||
init_async_got_bus,
|
||||
init_data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
task);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1320,5 +1290,5 @@ static void
|
|||
nm_secret_agent_old_async_initable_iface_init (GAsyncInitableIface *iface)
|
||||
{
|
||||
iface->init_async = init_async;
|
||||
iface->init_finish = init_finish;
|
||||
/* Use default implementation for init_finish */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,9 +229,9 @@ if [[ -n "$BUILDDIR" ]]; then
|
|||
fi
|
||||
|
||||
if ! _is_true "$NMTST_USE_VALGRIND" 0; then
|
||||
export NM_TEST_UNDER_VALGRIND=0
|
||||
"${NMTST_DBUS_RUN_SESSION[@]}" \
|
||||
"$TEST" "$@"
|
||||
exit $?
|
||||
exec "$TEST" "$@"
|
||||
fi
|
||||
|
||||
if [[ -z "${NMTST_VALGRIND}" ]]; then
|
||||
|
|
@ -250,6 +250,7 @@ LOGFILE="${TEST}.valgrind-log"
|
|||
|
||||
export G_SLICE=always-malloc
|
||||
export G_DEBUG=gc-friendly
|
||||
export NM_TEST_UNDER_VALGRIND=1
|
||||
"${NMTST_DBUS_RUN_SESSION[@]}" \
|
||||
"${NMTST_LIBTOOL[@]}" \
|
||||
"$NMTST_VALGRIND" \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue