about summary refs log tree commit diff
path: root/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/connections.c10
-rw-r--r--cli/src/nmcli.c12
-rw-r--r--cli/src/nmcli.h4
-rw-r--r--cli/src/utils.c14
4 files changed, 29 insertions, 11 deletions
diff --git a/cli/src/connections.c b/cli/src/connections.c
index 8e654864..4776e1a6 100644
--- a/cli/src/connections.c
+++ b/cli/src/connections.c
@@ -1230,7 +1230,7 @@ find_device_for_connection (NmCli *nmc,
 				active = nm_device_get_active_connection (*device);
 
 			if (!active) {
-				g_set_error (error, 0, 0, _("no active connection on device '%s'"), iface);
+				g_set_error (error, NMCLI_ERROR, 0, _("no active connection on device '%s'"), iface);
 				return FALSE;
 			}
 			*spec_object = nm_object_get_path (NM_OBJECT (active));
@@ -1238,7 +1238,7 @@ find_device_for_connection (NmCli *nmc,
 		} else {
 			active = get_default_active_connection (nmc, device);
 			if (!active) {
-				g_set_error (error, 0, 0, _("no active connection or device"));
+				g_set_error_literal (error, NMCLI_ERROR, 0, _("no active connection or device"));
 				return FALSE;
 			}
 			*spec_object = nm_object_get_path (NM_OBJECT (active));
@@ -1309,9 +1309,11 @@ find_device_for_connection (NmCli *nmc,
 			return TRUE;
 		} else {
 			if (iface)
-				g_set_error (error, 0, 0, _("device '%s' not compatible with connection '%s'"), iface, nm_setting_connection_get_id (s_con));
+				g_set_error (error, NMCLI_ERROR, 0, _("device '%s' not compatible with connection '%s'"),
+				             iface, nm_setting_connection_get_id (s_con));
 			else
-				g_set_error (error, 0, 0, _("no device found for connection '%s'"), nm_setting_connection_get_id (s_con));
+				g_set_error (error, NMCLI_ERROR, 0, _("no device found for connection '%s'"),
+				             nm_setting_connection_get_id (s_con));
 			return FALSE;
 		}
 	}
diff --git a/cli/src/nmcli.c b/cli/src/nmcli.c
index f51779e6..a7888aaa 100644
--- a/cli/src/nmcli.c
+++ b/cli/src/nmcli.c
@@ -57,6 +57,18 @@ typedef struct {
 GMainLoop *loop = NULL;
 
 
+/* Get an error quark for use with GError */
+GQuark
+nmcli_error_quark (void)
+{
+	static GQuark error_quark = 0;
+
+	if (G_UNLIKELY (error_quark == 0))
+		error_quark = g_quark_from_static_string ("nmcli-error-quark");
+
+	return error_quark;
+}
+
 static void
 usage (const char *prog_name)
 {
diff --git a/cli/src/nmcli.h b/cli/src/nmcli.h
index 9ffa42ed..8928126b 100644
--- a/cli/src/nmcli.h
+++ b/cli/src/nmcli.h
@@ -119,4 +119,8 @@ typedef struct _NmCli {
 	gboolean nocheck_ver;                             /* Don't check nmcli and NM versions: option '--nocheck' */
 } NmCli;
 
+/* Error quark for GError domain */
+#define NMCLI_ERROR (nmcli_error_quark ())
+GQuark nmcli_error_quark (void);
+
 #endif /* NMC_NMCLI_H */
diff --git a/cli/src/utils.c b/cli/src/utils.c
index 8030d5e1..4054fe13 100644
--- a/cli/src/utils.c
+++ b/cli/src/utils.c
@@ -100,7 +100,7 @@ nmc_ip4_address_as_string (guint32 ip, GError **error)
 	if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) {
 		return g_strdup (buf);
 	} else {
-		g_set_error (error, 0, 0, _("Error converting IP4 address '0x%X' to text form"),
+		g_set_error (error, NMCLI_ERROR, 0, _("Error converting IP4 address '0x%X' to text form"),
 		             ntohl (tmp_addr.s_addr));
 		return NULL;
 	}
@@ -128,7 +128,7 @@ nmc_ip6_address_as_string (const struct in6_addr *ip, GError **error)
 			g_string_append_printf (ip6_str, "%02X", ip->s6_addr[0]);
 			for (j = 1; j < 16; j++)
 				g_string_append_printf (ip6_str, " %02X", ip->s6_addr[j]);
-			g_set_error (error, 0, 0, _("Error converting IP6 address '%s' to text form"),
+			g_set_error (error, NMCLI_ERROR, 0, _("Error converting IP6 address '%s' to text form"),
 			             ip6_str->str);
 			g_string_free (ip6_str, TRUE);
 		}
@@ -229,10 +229,10 @@ parse_output_fields (const char *fields_str, const NmcOutputField fields_array[]
 		}
 		if (fields_array[i].name == NULL) {
 			if (!strcasecmp (*iter, "all") || !strcasecmp (*iter, "common"))
-				g_set_error (error, 0, 0, _("field '%s' has to be alone"), *iter);
+				g_set_error (error, NMCLI_ERROR, 0, _("field '%s' has to be alone"), *iter);
 
 			else
-				g_set_error (error, 0, 1, _("invalid field '%s'"), *iter);
+				g_set_error (error, NMCLI_ERROR, 1, _("invalid field '%s'"), *iter);
 			g_array_free (array, TRUE);
 			array = NULL;
 			goto done;
@@ -251,11 +251,11 @@ nmc_terse_option_check (NMCPrintOutput print_output, const char *fields, GError
 
 	if (print_output == NMC_PRINT_TERSE) {
 		if (!fields) {
-			g_set_error (error, 0, 0, _("Option '--terse' requires specifying '--fields'"));
+			g_set_error_literal (error, NMCLI_ERROR, 0, _("Option '--terse' requires specifying '--fields'"));
 			return FALSE;
 		} else if (   !strcasecmp (fields, "all")
 		           || !strcasecmp (fields, "common")) {
-			g_set_error (error, 0, 0, _("Option '--terse' requires specific '--fields' option values , not '%s'"), fields);
+			g_set_error (error, NMCLI_ERROR, 0, _("Option '--terse' requires specific '--fields' option values , not '%s'"), fields);
 			return FALSE;
 		}
 	}
@@ -468,7 +468,7 @@ nmc_is_nm_running (NmCli *nmc, GError **error)
 		g_string_printf (nmc->return_text, _("Error: Couldn't create D-Bus object proxy for org.freedesktop.DBus"));
 		nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
 		if (error)
-			g_set_error (error, 0, 0, "%s", nmc->return_text->str);
+			g_set_error_literal (error, NMCLI_ERROR, 0, nmc->return_text->str);
 		goto done;
 	}