summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2022-03-08 12:02:40 +0100
committerLubomir Rintel <lkundrak@v3.sk>2022-03-13 18:23:44 +0100
commitb3f79ac3661532d105442937c18957eab0cad76d (patch)
tree55bcc774a3f83d25fdb03736e29a029e5bb3108c
parentf377114d6e2d07bb46cd22c027c175c64932bce9 (diff)
cli: connection: factor out warning from "add" callback
We sometimes emit warnings after a connection is added. Currently there's a warning when the connection ID collides with another one (and a suggestion to use an UUID instead). Let's move the check into a separate routine, so that we can reuse it elsewhere, such as on connection "modify" (in a following commit).
-rw-r--r--src/nmcli/connections.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c
index 81d051971a..fdfac3abaf 100644
--- a/src/nmcli/connections.c
+++ b/src/nmcli/connections.c
@@ -5241,14 +5241,47 @@ nmc_process_connection_properties(NmCli *nmc,
}
static void
+connection_warnings(NmCli *nmc, NMConnection *connection)
+{
+ const GPtrArray *connections;
+ guint i, found;
+ const char *id;
+
+ connections = nm_client_get_connections(nmc->client);
+ if (!connections)
+ return;
+
+ id = nm_connection_get_id(connection);
+ found = 0;
+ for (i = 0; i < connections->len; i++) {
+ NMConnection *candidate = NM_CONNECTION(connections->pdata[i]);
+
+ if ((NMConnection *) connection == candidate)
+ continue;
+ if (nm_streq0(nm_connection_get_id(candidate), id))
+ found++;
+ }
+
+ if (found > 0) {
+ g_printerr(g_dngettext(GETTEXT_PACKAGE,
+ "Warning: There is another connection with the name '%1$s'. "
+ "Reference the connection by its uuid '%2$s'\n",
+ "Warning: There are %3$u other connections with the name "
+ "'%1$s'. Reference the connection by its uuid '%2$s'\n",
+ found),
+ id,
+ nm_connection_get_uuid(NM_CONNECTION(connection)),
+ found);
+ }
+}
+
+static void
add_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data)
{
nm_auto_free_add_connection_info AddConnectionInfo *info = user_data;
NmCli *nmc = info->nmc;
NMRemoteConnection *connection;
GError *error = NULL;
- const GPtrArray *connections;
- guint i, found;
connection = nm_client_add_connection2_finish(NM_CLIENT(client), result, NULL, &error);
if (error) {
@@ -5259,29 +5292,7 @@ add_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data)
g_error_free(error);
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
} else {
- connections = nm_client_get_connections(nmc->client);
- if (connections) {
- found = 0;
- for (i = 0; i < connections->len; i++) {
- NMConnection *candidate = NM_CONNECTION(connections->pdata[i]);
-
- if ((NMConnection *) connection == candidate)
- continue;
- if (nm_streq0(nm_connection_get_id(candidate), info->new_id))
- found++;
- }
- if (found > 0) {
- g_printerr(g_dngettext(GETTEXT_PACKAGE,
- "Warning: There is another connection with the name '%1$s'. "
- "Reference the connection by its uuid '%2$s'\n",
- "Warning: There are %3$u other connections with the name "
- "'%1$s'. Reference the connection by its uuid '%2$s'\n",
- found),
- info->new_id,
- nm_connection_get_uuid(NM_CONNECTION(connection)),
- found);
- }
- }
+ connection_warnings(nmc, NM_CONNECTION(connection));
/* We print here human readable text, but as scripts might parse this output
* (with LANG=C), this is important to not change in the future. At least