core: update resolv.conf directly if opening the tempfile fails
This commit is contained in:

committed by
Dan Williams

parent
42b4d04fe1
commit
b96c60dae0
@@ -332,19 +332,28 @@ update_resolv_conf (const char *domain,
|
|||||||
const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
|
const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
|
||||||
char tmp_resolv_conf_realpath [PATH_MAX];
|
char tmp_resolv_conf_realpath [PATH_MAX];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
int do_rename = 1;
|
||||||
|
int old_errno = 0;
|
||||||
|
|
||||||
if (!realpath (tmp_resolv_conf, tmp_resolv_conf_realpath))
|
if (!realpath (tmp_resolv_conf, tmp_resolv_conf_realpath))
|
||||||
strcpy (tmp_resolv_conf_realpath, tmp_resolv_conf);
|
strcpy (tmp_resolv_conf_realpath, tmp_resolv_conf);
|
||||||
|
|
||||||
if ((f = fopen (tmp_resolv_conf_realpath, "w")) == NULL) {
|
if ((f = fopen (tmp_resolv_conf_realpath, "w")) == NULL) {
|
||||||
|
do_rename = 0;
|
||||||
|
old_errno = errno;
|
||||||
|
if ((f = fopen (RESOLV_CONF, "w")) == NULL) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
NM_NAMED_MANAGER_ERROR,
|
NM_NAMED_MANAGER_ERROR,
|
||||||
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
||||||
"Could not open %s: %s\n",
|
"Could not open %s: %s\nCould not open %s: %s\n",
|
||||||
tmp_resolv_conf_realpath,
|
tmp_resolv_conf_realpath,
|
||||||
|
g_strerror (old_errno),
|
||||||
|
RESOLV_CONF,
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
strcpy (tmp_resolv_conf_realpath, RESOLV_CONF);
|
||||||
|
}
|
||||||
|
|
||||||
write_resolv_conf (f, domain, searches, nameservers, error);
|
write_resolv_conf (f, domain, searches, nameservers, error);
|
||||||
|
|
||||||
@@ -359,7 +368,7 @@ update_resolv_conf (const char *domain,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*error == NULL) {
|
if (*error == NULL && do_rename) {
|
||||||
if (rename (tmp_resolv_conf, RESOLV_CONF) < 0) {
|
if (rename (tmp_resolv_conf, RESOLV_CONF) < 0) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
NM_NAMED_MANAGER_ERROR,
|
NM_NAMED_MANAGER_ERROR,
|
||||||
|
Reference in New Issue
Block a user