summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-06-21 12:35:52 +0200
committerThomas Haller <thaller@redhat.com>2019-06-26 12:26:11 +0200
commite5b21344c505d530df7d91f878e86836ace8b935 (patch)
treea8b5967862b71e46b6c4e5d1e0369fb9e769f8e1
parenta4642c78f7c9501eb758fc8903dc1cd2f075ea9d (diff)
downloadNetworkManager-e5b21344c505d530df7d91f878e86836ace8b935.tar.gz
ifcfg-rh: cleanup utils_detect_ifcfg_path()
- avoid cloing the basename. Determining the basename can be done conveniently with strrchr(). - use cleanup macro for temporary variable. - while in practice it should not happen, check that the colon in the name of alias file names is not followed by another '/'.
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
index 9a05572660..038f3dacc9 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
@@ -316,36 +316,41 @@ utils_is_ifcfg_alias_file (const char *alias, const char *ifcfg)
char *
utils_detect_ifcfg_path (const char *path, gboolean only_ifcfg)
{
- gs_free char *base = NULL;
- char *ptr, *ifcfg = NULL;
+ const char *base;
g_return_val_if_fail (path != NULL, NULL);
if (utils_should_ignore_file (path, only_ifcfg))
return NULL;
- base = g_path_get_basename (path);
+ base = strrchr (path, '/');
+ if (!base)
+ base = path;
+ else
+ base += 1;
- if (strncmp (base, IFCFG_TAG, NM_STRLEN (IFCFG_TAG)) == 0) {
+ if (NM_STR_HAS_PREFIX (base, IFCFG_TAG)) {
if (base[NM_STRLEN (IFCFG_TAG)] == '\0')
return NULL;
if (utils_is_ifcfg_alias_file (base, NULL)) {
+ gs_free char *ifcfg = NULL;
+ char *ptr;
+
ifcfg = g_strdup (path);
ptr = strrchr (ifcfg, ':');
- if (ptr && ptr > ifcfg) {
+ if ( ptr
+ && ptr > ifcfg
+ && !strchr (ptr, '/')) {
*ptr = '\0';
if (g_file_test (ifcfg, G_FILE_TEST_EXISTS)) {
/* the file has a colon, so it is probably an alias.
* To be ~more~ certain that this is an alias file,
* check whether a corresponding base file exists. */
- if (only_ifcfg) {
- g_free (ifcfg);
+ if (only_ifcfg)
return NULL;
- }
- return ifcfg;
+ return g_steal_pointer (&ifcfg);
}
}
- g_free (ifcfg);
}
return g_strdup (path);
}