dns: split create_resolv_conf() out of write_resolv_conf()
authorThomas Haller <thaller@redhat.com>
Mon, 21 Mar 2016 15:34:05 +0000 (16:34 +0100)
committerThomas Haller <thaller@redhat.com>
Wed, 23 Mar 2016 08:09:06 +0000 (09:09 +0100)
src/dns-manager/nm-dns-manager.c

index 26f3b2c..06f2b51 100644 (file)
@@ -410,12 +410,10 @@ dispatch_netconfig (NMDnsManager *self,
        return SR_SUCCESS;
 }
 
-static gboolean
-write_resolv_conf (FILE *f,
-                   char **searches,
-                   char **nameservers,
-                   char **options,
-                   GError **error)
+static char *
+create_resolv_conf (char **searches,
+                    char **nameservers,
+                    char **options)
 {
        gs_free char *searches_str = NULL;
        gs_free char *nameservers_str = NULL;
@@ -443,9 +441,9 @@ write_resolv_conf (FILE *f,
                for (i = 0; i < num; i++) {
                        if (i == 3) {
                                g_string_append (str, "# ");
-                               g_string_append (str, _("NOTE: the libc resolver may not support more than 3 nameservers."));
+                               g_string_append (str, "NOTE: the libc resolver may not support more than 3 nameservers.");
                                g_string_append (str, "\n# ");
-                               g_string_append (str, _("The nameservers listed below may not be recognized."));
+                               g_string_append (str, "The nameservers listed below may not be recognized.");
                                g_string_append_c (str, '\n');
                        }
 
@@ -456,10 +454,23 @@ write_resolv_conf (FILE *f,
                nameservers_str = g_string_free (str, FALSE);
        }
 
-       if (fprintf (f, "# Generated by NetworkManager\n%s%s%s",
-                    searches_str ? searches_str : "",
-                    nameservers_str ? nameservers_str : "",
-                    options_str ? options_str : "") < 0) {
+       return g_strdup_printf ("# Generated by NetworkManager\n%s%s%s",
+                               searches_str ?: "",
+                               nameservers_str ?: "",
+                               options_str ?: "");
+}
+
+static gboolean
+write_resolv_conf (FILE *f,
+                   char **searches,
+                   char **nameservers,
+                   char **options,
+                   GError **error)
+{
+       gs_free char *content = NULL;
+
+       content = create_resolv_conf (searches, nameservers, options);
+       if (fprintf (f, "%s", content) < 0) {
                g_set_error (error,
                             NM_MANAGER_ERROR,
                             NM_MANAGER_ERROR_FAILED,