Issue 8183 - ldap_init() failed at sub thread but runs ok at main.
Summary: ldap_init() failed at sub thread but runs ok at main.
Status: VERIFIED FEEDBACK
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: slapd (show other issues)
Version: 2.4.39
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-02 06:14 UTC by 1727647302@qq.com
Modified: 2021-02-22 18:06 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description 1727647302@qq.com 2015-07-02 06:14:04 UTC
Full_Name: wondersoft
Version: 2.4.39
OS: CentOS 6.6 X86_64
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (182.50.119.36)


Hi:

My server is CentOS 6.6(x86_64). When I create a thread on the main(), it's
failed on ldap_init(), but it's ok at main not running on a sub thread. But
using the same version and the same code, it runs pretty well at CentOS
6.6(x86_32).

Test code is here:
void pthread_ldap() 
{ 
    LDAP *ld = NULL; 
   
	ld=(LDAP*)ldap_init(HOSTNAME,0);
	if(ld ==NULL) { 
        perror("ldap_init"); 
        return ; 
    } 
	
	int protocolVersion = LDAP_VERSION3;
	
	//It failed here, if ituns s on CentOS 6.6(x86_64) as a sub thread.
	ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &(protocolVersion));
	
    return ; 
 
} 

int main()
{
    int ret = 0;
    
    pthread_attr_t attr_attribute;
    pthread_attr_init(&attr_attribute);
    pthread_attr_setdetachstate(&attr_attribute,PTHREAD_CREATE_DETACHED);
    pthread_t pid;
   
    //If no sub thread created, it's ok
    //pthread_ldap();
    if( pthread_create( &pid, &attr_attribute, (void*)pthread_ldap, NULL ) ) {
		perror(" Create pthread_ldap ERROR");
    }  
}

  gdb chasing result:
  
(gdb) 
222 rc = ldap_set_option(ld, LDAP_OPT_HOST_NAME, defhost);
(gdb) 
223 if ( rc != LDAP_SUCCESS ) {
(gdb) p ld
$6 = (LDAP *) 0x7ffff00008c0
 
(gdb) 
pthread_ldap () at OPENLDAP_exam.c8686
186 printf("ldap_init ld = %d\n", ld);
(gdb) p ld
$7 = (LDAP *) 0xfffffffff00008c0
 
gcc version:
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
OS version:
Linux localhost.localdomain 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC
2014 x86_64 x86_64 x86_64 GNU/Linux 
 
gcc command:
gcc OPENLDAP_exam.c -g -o OPENLDAP_exam -L/usr/local/lib -lldap -llber -lpthread
Comment 1 Quanah Gibson-Mount 2017-04-03 16:49:43 UTC
moved from Incoming to Software Bugs
Comment 2 Quanah Gibson-Mount 2021-02-22 18:06:28 UTC
Can you reproduce this with the OpenLDAP 2.5 alpha?