problem s funkci res_query v RH8
Leo Hadacz
leo.hadacz na siemens.com
Úterý Březen 11 20:45:06 CET 2003
Zdravim,
mam nasledujici kratky kod:
---------------------------
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <resolv.h> // defines for name server and IPv6
#include <arpa/nameser.h> // nameserver definitions
#include <pthread.h>
int make_res();
void * thr1_func (void *);
int main (int argc, char *argv[])
{
pthread_t thr1;
printf ("Outside any thread.\n");
make_res();
pthread_create (&thr1, NULL, thr1_func, NULL);
pthread_join (thr1, NULL);
printf ("The threads are finished.\n");
exit (EXIT_SUCCESS);
}
int make_res()
{
char *domain = "uuu.xxx";
char srv[MAXDNAME];
unsigned char response[4096]; // response header+buffer
int len; // buffer length
sprintf(srv, "%s.%s.%s.", "aaa", "bbb", domain);
if ((len = res_query (srv, C_IN, T_SRV, response, sizeof (response))) > 0) {
printf ("res_query: DNS search OK.\n");
return 0;
}
else {
printf ("res_query: DNS search failed!\n");
return -1;
}
}
void * thr1_func (void *nothing)
{
printf ("I am thread 1.\n");
sleep(1);
make_res();
return (NULL);
}
---------------------------
ktery prekladam takto:
g++ -c -Wall -D_REENTRANT -DLINUX -DUSE_SBUF dp-thr1.cpp -o dp-thr1.o
g++ dp-thr1.o -lpthread -lresolv -o dp-thr1
Odpovidajici zaznam v DNS je
aaa.bbb IN SRV 0 1 3306 some_value
Na RedHatu 7.3 funguji obe volani funkce res_query: mimo thread i uvnitr
threadu. Tedy vysledek spusteni je:
---------------------------
$ ./dp-thr1
Outside any thread.
res_query: DNS search OK.
I am thread 1.
res_query: DNS search OK.
The threads are finished.
---------------------------
Na RedHatu 8.0 volani res_query mimo thread dopadne dobre, ale uvnitr
threadu skonci s chybou (funkce vrati -1), tj. vysledek je:
$ ./dp-thr1
Outside any thread.
res_query: DNS search OK.
I am thread 1.
res_query: DNS search failed!
The threads are finished.
---------------------------
Nevite nekdo co je spatne?
Leo
--
Leo Hadacz, ANF DATA / Siemens, +420 54310 6586
Další informace o konferenci Linux