Re: [Patch] Update /etc/resolv.conf on a stateless client



On Fri, 2008-12-19 at 12:16 +0100, Harald Hoyer wrote:
> rediff against git repo
> plain text document attachment
> (0001-Try-to-write-to-etc-resolv.conf-directly-as-a-fallb.patch)
> From 0c524af3cc989f7bfbf60186c69a348fa8b1eafd Mon Sep 17 00:00:00 2001
> From: Harald Hoyer <harald redhat com>
> Date: Fri, 19 Dec 2008 12:08:33 +0100
> Subject: [PATCH] Try to write to /etc/resolv.conf directly as a fallback
> 
> /etc/resolv.conf might be bind mounted on a stateless client.

Finally committed and pushed.

Thanks,
Dan

>  src/named-manager/nm-named-manager.c |   25 +++++++++++++++++--------
>  1 files changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/src/named-manager/nm-named-manager.c b/src/named-manager/nm-named-manager.c
> index adb76fd..b697eca 100644
> --- a/src/named-manager/nm-named-manager.c
> +++ b/src/named-manager/nm-named-manager.c
> @@ -332,18 +332,27 @@ update_resolv_conf (const char *domain,
>  	const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
>  	char tmp_resolv_conf_realpath [PATH_MAX];
>  	FILE *f;
> +	int do_rename = 1;
> +	int old_errno = 0;
>  
>  	if (!realpath(tmp_resolv_conf, tmp_resolv_conf_realpath))
>  		strcpy(tmp_resolv_conf_realpath, tmp_resolv_conf);
>  
>  	if ((f = fopen (tmp_resolv_conf_realpath, "w")) == NULL) {
> -		g_set_error (error,
> -				   NM_NAMED_MANAGER_ERROR,
> -				   NM_NAMED_MANAGER_ERROR_SYSTEM,
> -				   "Could not open %s: %s\n",
> -				   tmp_resolv_conf_realpath,
> -				   g_strerror (errno));
> -		return FALSE;
> +		do_rename = 0;
> +		old_errno = errno;
> +		if ((f = fopen (RESOLV_CONF, "w")) == NULL) {
> +			g_set_error (error,
> +					   NM_NAMED_MANAGER_ERROR,
> +					   NM_NAMED_MANAGER_ERROR_SYSTEM,
> +					   "Could not open %s: %s\nCould not open %s: %s\n",
> +					   tmp_resolv_conf_realpath,
> +					   g_strerror (old_errno),
> +					   RESOLV_CONF,
> +					   g_strerror (errno));
> +			return FALSE;
> +		}
> +		strcpy(tmp_resolv_conf_realpath, RESOLV_CONF);
>  	}
>  
>  	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) {
>  			g_set_error (error,
>  					   NM_NAMED_MANAGER_ERROR,
> _______________________________________________
> NetworkManager-list mailing list
> NetworkManager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]