diff options
author | Thomas Haller <thaller@redhat.com> | 2018-10-19 12:11:27 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-10-23 10:36:07 +0200 |
commit | 61717cc57553817ae5330e830195b64e42327098 (patch) | |
tree | 745b9783c99f0a2adc5808e3ab9015fc17e75fd8 | |
parent | 71c3483ac47958d2df06f9458507532c6c23b0a9 (diff) | |
download | NetworkManager-61717cc57553817ae5330e830195b64e42327098.tar.gz |
initrd: use cleanup attribute and return early from output_conn()
-rw-r--r-- | src/initrd/nm-initrd-generator.c | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c index 0b4d19bae8..0fdfb00996 100644 --- a/src/initrd/nm-initrd-generator.c +++ b/src/initrd/nm-initrd-generator.c @@ -40,42 +40,38 @@ output_conn (gpointer key, gpointer value, gpointer user_data) const char *basename = key; NMConnection *connection = value; char *connections_dir = user_data; - GKeyFile *file; + gs_unref_keyfile GKeyFile *file = NULL; gs_free char *data = NULL; - GError *error = NULL; + gs_free_error GError *error = NULL; gsize len; - if (!nm_connection_normalize (connection, NULL, NULL, &error)) { - g_print ("%s\n", error->message); - g_error_free (error); - return; - } + if (!nm_connection_normalize (connection, NULL, NULL, &error)) + goto err_out; file = nm_keyfile_write (connection, NULL, NULL, &error); - if (file == NULL) { - g_print ("%s\n", error->message); - g_error_free (error); - return; - } + if (file == NULL) + goto err_out; data = g_key_file_to_data (file, &len, &error); - if (!data) { - g_print ("%s\n", error->message); - g_error_free (error); - } else if (connections_dir) { - gs_free char *basename_w_ext = g_strconcat (basename, ".nmconnection", NULL); - char *filename = g_build_filename (connections_dir, basename_w_ext, NULL); - - if (!nm_utils_file_set_contents (filename, data, len, 0600, &error)) { - g_print ("%s\n", error->message); - g_error_free (error); - } - g_free (filename); - } else { + if (!data) + goto err_out; + + if (connections_dir) { + gs_free char *filename = NULL; + gs_free char *full_filename = NULL; + + full_filename = g_build_filename (connections_dir, + nm_construct_name_a ("%s.nmconnection", basename, &filename), + NULL); + + if (!nm_utils_file_set_contents (filename, data, len, 0600, &error)) + goto err_out; + } else g_print ("\n*** Connection '%s' ***\n\n%s\n", basename, data); - } - g_key_file_free (file); + return; +err_out: + g_print ("%s\n", error->message); } #define DEFAULT_CONNECTIONS_DIR NMRUNDIR "/system-connections" |