On 2011-02-18 17:16, Derek J. Balling wrote:

> But also my complaint is: Why *isn't* puppet-agent noticing
> that resolv.conf has changed? This seems like something that
> would only be caused by not using the standard gethostbyname()
> calls and such, > since *those* should reflect the change in
> resolv.conf almost immediately.... :-/

Except that they don't...  At least the GNU libc implementation does
not re-read resolv.conf unless you call res_init().  I'm attaching
a test program that you can use to verify it yourself.  It will call
gethostbyname() twice, optionally re-initialize the resolver before
the second call.  You are supposed to change your resolv.conf between
the two calls.

I *think* other Unix libc implementations does the same, but I don't
have any machine available where I can test this at the moment.


        /Bellman

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

#define _BSD_SOURCE
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <arpa/inet.h>
#include <resolv.h>
#include <netdb.h>
#include <sysexits.h>


void showhost(char *hostname)
{
    struct hostent *he;
    int i;
    char buf[4096];

    he = gethostbyname(hostname);
    if (he == NULL)
	printf("gethostbyname(%s) failed: %d\n", hostname, h_errno);
    else
    {
	for (i = 0 ;  he->h_addr_list[i] ;  i++)
	{
	    printf("gethostbyname(%s): %s\n",
		   hostname,
		   inet_ntop(he->h_addrtype, he->h_addr_list[i],
			     buf, sizeof buf));
	}
    }
}

void usage(char **argv)
{
    fprintf(stderr, "Usage: %s [-r] hostname\n", argv[0]);
    exit(EX_USAGE);
}


int main(int argc, char **argv)
{
    char *host;
    int reread_resolvconf = 0;

    if (argc < 2)
	usage(argv);
    reread_resolvconf = !strcmp(argv[1], "-r");
    if (argc != 2 + reread_resolvconf)
	usage(argv);
    host = argv[1 + reread_resolvconf];

    showhost(host);
    fputs("Press Return: ", stdout);
    fflush(stdout);
    getc(stdin);
    if (reread_resolvconf) {
	fputs("Re-initializing resolver\n", stdout);
	res_init();
    }
    showhost(host);

    return 0;
}

Reply via email to