Skip to content

Dtracing gethostbyname_r

July 2, 2008

Today’s dtrace “one liner” is to dig into why a process that is failing when a call to gethostbyname_r(). Now if the application reported all that was going on this would not be needed, meanwhile in the real world we are lucky enough to have dtrace. To test it out I’m tracing the getent(1) command. In real life it would use the -p flag to dtrace and the process ID of the daemon.

/usr/sbin/dtrace -n ‘pid$target::gethostbyname_r:entry {         self->name = arg0; } pid$target::gethostbyname_r:return / arg1 == 0 / {         ustack(5); } pid$target::gethostbyname_r:return / self->name / {         printf("%s", copyinstr(self->name));         self->name = 0 }’ -c "getent hosts xxxxxdredd" dtrace: description ‘pid$target::gethostbyname_r:entry ‘ matched 3 probes dtrace: pid 4748 has exited CPU     ID                    FUNCTION:NAME   2  48759           gethostbyname_r:return                libnsl.so.1`gethostbyname_r+0xc4               getent`dogethost+0x54               getent`main+0x7c               getent`_start+0x108    2  48759           gethostbyname_r:return xxxxxdredd  

It would be nice to be able to get the h_errno value as well but so far I’ve not managed that.

Update:

Jon Haslem kindly explained to me the subtleties of copyin() so that I can get the h_errno value.

 /usr/sbin/dtrace -Zn ‘pid$target::gethostbyname_r:entry {         self->name = arg0;          self->errno = arg4;  } pid$target::gethostbyname_r:return / arg1 == 0 / {         ustack(5);         printf(“%d %s h_errno %x”, pid,                 copyinstr(self->name),          *(int *)copyin(self->errno,sizeof(int))); }’ -c “getent hosts xxxxxdredd” dtrace: description ‘pid$target::gethostbyname_r:entry ‘ matched 2 probes dtrace: pid 5087 has exited CPU     ID                    FUNCTION:NAME   2  48764            gethostbyname_r:entry errno: d4220008   2  48765           gethostbyname_r:return                libnsl.so.1`gethostbyname_r+0xc4               getent`dogethost+0x54               getent`main+0x7c               getent`_start+0x108 5087 xxxxxdredd h_errno 1  #  

Advertisements

From → Solaris

2 Comments
  1. Anonymous permalink

    The *debug* option mentioned in the options sections of the resolve.conf man page appears to be little known and very useful for getting applications to spit out what they are doing with resolver.
    Does have the disadvantage of being system wide. Not looked into a way of setting RES_DEBUG on a per process level, but should be possible.

  2. [Trackback] The gethostbyname.d “one
    liner” is now no longer anywhere near a one liner as to not
    be funny. It does however do all the things you would want it to
    do. Printing the entire hostent 1
    structure on success and all the h_error valu…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: