mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 12:18:13 +02:00
dns: refactor create_resolv_conf() to use GString for constructing content
This commit is contained in:
parent
20a7e489ee
commit
95b006c244
1 changed files with 24 additions and 31 deletions
|
|
@ -586,49 +586,42 @@ create_resolv_conf (char **searches,
|
|||
char **nameservers,
|
||||
char **options)
|
||||
{
|
||||
gs_free char *searches_str = NULL;
|
||||
gs_free char *nameservers_str = NULL;
|
||||
gs_free char *options_str = NULL;
|
||||
char *tmp_str;
|
||||
GString *str;
|
||||
int i;
|
||||
gsize i;
|
||||
|
||||
if (searches) {
|
||||
tmp_str = g_strjoinv (" ", searches);
|
||||
searches_str = g_strconcat ("search ", tmp_str, "\n", NULL);
|
||||
g_free (tmp_str);
|
||||
str = g_string_new_len ("# Generated by NetworkManager\n", 245);
|
||||
|
||||
if (searches && searches[0]) {
|
||||
g_string_append (str, "search");
|
||||
for (i = 0; searches[i]; i++) {
|
||||
g_string_append_c (str, ' ');
|
||||
g_string_append (str, searches[i]);
|
||||
}
|
||||
g_string_append_c (str, '\n');
|
||||
}
|
||||
|
||||
if (options) {
|
||||
tmp_str = g_strjoinv (" ", options);
|
||||
options_str = g_strconcat ("options ", tmp_str, "\n", NULL);
|
||||
g_free (tmp_str);
|
||||
}
|
||||
|
||||
if (nameservers) {
|
||||
int num = g_strv_length (nameservers);
|
||||
|
||||
str = g_string_new ("");
|
||||
for (i = 0; i < num; i++) {
|
||||
if (nameservers && nameservers[0]) {
|
||||
for (i = 0; nameservers[i]; 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, "\n# ");
|
||||
g_string_append (str, "The nameservers listed below may not be recognized.");
|
||||
g_string_append_c (str, '\n');
|
||||
g_string_append (str, "# NOTE: the libc resolver may not support more than 3 nameservers.\n");
|
||||
g_string_append (str, "# The nameservers listed below may not be recognized.\n");
|
||||
}
|
||||
|
||||
g_string_append (str, "nameserver ");
|
||||
g_string_append (str, nameservers[i]);
|
||||
g_string_append_c (str, '\n');
|
||||
}
|
||||
nameservers_str = g_string_free (str, FALSE);
|
||||
}
|
||||
|
||||
return g_strdup_printf ("# Generated by NetworkManager\n%s%s%s",
|
||||
searches_str ?: "",
|
||||
nameservers_str ?: "",
|
||||
options_str ?: "");
|
||||
if (options && options[0]) {
|
||||
g_string_append (str, "options");
|
||||
for (i = 0; options[i]; i++) {
|
||||
g_string_append_c (str, ' ');
|
||||
g_string_append (str, options[i]);
|
||||
}
|
||||
g_string_append_c (str, '\n');
|
||||
}
|
||||
|
||||
return g_string_free (str, FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue