linux - gethostbyname() sometimes could not dns forever -




in 1 of our product(embeded platform using rtl8196e chips), program fails dns forever before program restarted.

more investigation found if program starts before network ready(e.g.: before dhcped udhcpc), following calling gethostbyname() failed ever, @ time ping working when network ok.

some tests have done illustrate:(in simplest form, e.g.: omit print result of gethostbyname)

the programs started before network ready(e.g.: before eth0 has ip dhcp)

program 1: not ip ever after network ok(ping ok)

while (1) {   res_init();   gethostbyname(...); //not work   sleep(5); } 

program 2: execution of gethostbyname() in forked process works

while (1) {   pid = fork();   ...   if (pid == 0)      res_init();      gethostbyname(...); //works   else      waitpid(pid1,...);   sleep(5); } 

program 3: execution of gethostbyname() both failed in child/parent process

while (1) {   pid = fork();   ...   if (pid == 0)      res_init();      gethostbyname(...); //not work   else      res_init();      gethostbyname(...); //not work      waitpid(pid1,...);   sleep(5); } 

i totally blank what's reason weird behavior... glic or kernel?

any explanation appreciated.

ok, had dive ulibc code , find issue.

there bug in libc/inet/resolv.c __dns_lookup().

the variable local_ns not increase @ case select next dns server.

so process calls gethostbyname() use false dns server ip forever.

due resolv.conf follows: nameserver 192.168.0.1 nameserver 0.0.0.0 nameserver 8.8.8.8

it deadlock 0.0.0.0 query dns...





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -