diff options
Diffstat (limited to 'cli/src/utils.c')
-rw-r--r-- | cli/src/utils.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cli/src/utils.c b/cli/src/utils.c index bcc51bbd8..3c4e4f369 100644 --- a/cli/src/utils.c +++ b/cli/src/utils.c @@ -17,6 +17,9 @@ * (C) Copyright 2010 - 2011 Red Hat, Inc. */ +/* Generated configuration file */ +#include "config.h" + #include <stdio.h> #include <string.h> @@ -351,3 +354,49 @@ done: return has_owner; } +/* +* Compare versions of nmcli and NM daemon. +* Return: TRUE - the versions match (when only major and minor match, print a warning) +* FALSE - versions mismatch +*/ +gboolean +nmc_versions_match (NmCli *nmc) +{ + const char *nm_ver = NULL; + const char *dot; + gboolean match = FALSE; + + g_return_val_if_fail (nmc != NULL, FALSE); + + /* --nocheck option - don't compare the versions */ + if (nmc->nocheck_ver) + return TRUE; + + nmc->get_client (nmc); + nm_ver = nm_client_get_version (nmc->client); + if (nm_ver) { + if (!strcmp (nm_ver, VERSION)) + match = TRUE; + else { + dot = strchr (nm_ver, '.'); + if (dot) { + dot = strchr (dot + 1, '.'); + if (dot && !strncmp (nm_ver, VERSION, dot-nm_ver)) { + fprintf(stderr, + _("Warning: nmcli (%s) and NetworkManager (%s) versions don't match. Use --nocheck to suppress the warning.\n"), + VERSION, nm_ver); + match = TRUE; + } + } + } + } + + if (!match) { + g_string_printf (nmc->return_text, _("Error: nmcli (%s) and NetworkManager (%s) versions don't match. Force execution using --nocheck, but the results are unpredictable."), + VERSION, nm_ver ? nm_ver : _("unknown")); + nmc->return_value = NMC_RESULT_ERROR_VERSIONS_MISMATCH; + } + + return match; +} + |