--Quanah ------------ Forwarded Message ------------ Date: Monday, October 23, 2017 12:43 AM -0700 From: Xin Li <delphij@delphij.net> To: Quanah Gibson-Mount <quanah@symas.com>, Xin LI <delphij@gmail.com>Cc: d@delphij.net, Pietro Cerutti <gahr@gahr.ch>, Xin LI <delphij@freebsd.org>
Subject: Re: kqueue in OpenLDAP for FreeBSD Hi, Quanah, I finally got some time to twiddle with OpenLDAP (again). It looks like the EBADF is expected, because fork(2) says: • The child process has its own copy of the parent's descriptors, except for descriptors returned by kqueue(2), which are not inherited from the parent process. And slapd does have a fork() after the initial kqueue(), which rendered it invalid. The kqueue() is part of SLAP_SOCK_INIT(), which is part of slapd_daemon_init(). Then, after that, fork() happen in lutil_detach(), and doing this hack would (incorrectly) make slapd to start: diff --git a/libraries/liblutil/detach.c b/libraries/liblutil/detach.c index c6464c038..f47d36548 100644 --- a/libraries/liblutil/detach.c +++ b/libraries/liblutil/detach.c @@ -73,7 +73,7 @@ lutil_detach( int debug, int do_close ) #ifdef HAVE_THR pid = fork1(); #else - pid = fork(); + pid = rfork(RFPROC); #endif switch ( pid ) { It is incorrect because the code in slapd/main.c seems to expect the child to write a "1" to it before exiting with EXIT_SUCCESS() and obviously if the two processes shares the same file table, the parent would consider the start was failed because read() would fail. I think the right fix would be to move the lutil_detach() to before slapd_daemon_init(), see attachment, but it seems that some code after the initial daemon initialization is still trying to output to stderr, etc. What do you think? Cheers, ---------- End Forwarded Message ---------- -- Quanah Gibson-Mount Product Architect Symas Corporation Packaged, certified, and supported LDAP solutions powered by OpenLDAP: <http://www.symas.com>
--- Begin Message ---
- To: Quanah Gibson-Mount <quanah@symas.com>, Xin LI <delphij@gmail.com>
- Subject: Re: kqueue in OpenLDAP for FreeBSD
- From: Xin Li <delphij@delphij.net>
- Date: Sun, 22 Oct 2017 23:43:05 -0700
- Authentication-results: zmcc-5-mta-1.zmailcloud.com (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=delphij.net
- Cc: d@delphij.net, Pietro Cerutti <gahr@gahr.ch>, Xin LI <delphij@freebsd.org>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delphij.net; s=anubis; t=1508740990; x=1508755390; bh=lHOLEU7RrRbdsqZiIrERFdjtGcmjK0d4J65y4NciNAE=; h=Cc:Subject:To:References:From:Date:In-Reply-To; b=pSf21voW+1hi95e1Gk7n0Etfo4WpoqUlF4m7Ukgp6+Sw1OreGQEjQPiBMq0Wo6htG P/+uPZswNtPxpr/6yGE9Fsrxku8Bygk6Qv/o3pR9rRe0bKhvrh+jqAcM0KvcjgG9cV geciuENhFuihiQm9Jh/4383kqyrcrgnufON8XY4Q=
- In-reply-to: <77291973D4E980CDD2C6B12D@[192.168.1.30]>
- References: <1EEAC653239F6692643DB632@192.168.1.30> <058DB23288D5009E6DBB5BCD@192.168.1.30> <CAGMYy3shfuAS85XowEVaFcnOUKpU2PDMqm8+PWzch93f0j_bXg@mail.gmail.com> <WM!a464e9245a6039036609ea76ee2d9e4d48947932ced97d50fe93b3951122d1549508f510bddbbc94dc5a58711bef7c3a!@mailstronghold-2.zmailcloud.com> <6C1DC7E9BE41FA3CD93838AC@192.168.1.30> <CAGMYy3tWs52_RvSjQHtg17D1vOE9BM4YWEpO9k1Oc82L+0fJsA@mail.gmail.com> <WM!989b88c2339699eecc479074ef90267785f2f7857ca6a68544f30ecbc534e2146b4db747de2aede7c8f671fd55da9d58!@mailstronghold-3.zmailcloud.com> <62041328E5AFD06BBFCFDF96@[192.168.1.30]> <D8979E6E67B623588F99E3B7@[192.168.1.30]> <5b003a32-e2cc-0ae0-1dc9-1f994b4b06a4@delphij.net> <WM!a1b49a63e95c1d3f455af9c2777883d03dd1e46303f3c7e5270170ec581ec4658216e91e73f74b5dec589501ad7b5d03!@mailstronghold-3.zmailcloud.com> <A3DFF2D02CD1C134AAC9771D@[192.168.1.30]> <77291973D4E980CDD2C6B12D@[192.168.1.30]> <cff1e448-975f-f832-4ced-7c68108abf49@delphij.net>
- User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.4.0
Hi, Quanah, I finally got some time to twiddle with OpenLDAP (again). It looks like the EBADF is expected, because fork(2) says: • The child process has its own copy of the parent's descriptors, except for descriptors returned by kqueue(2), which are not inherited from the parent process. And slapd does have a fork() after the initial kqueue(), which rendered it invalid. The kqueue() is part of SLAP_SOCK_INIT(), which is part of slapd_daemon_init(). Then, after that, fork() happen in lutil_detach(), and doing this hack would (incorrectly) make slapd to start: diff --git a/libraries/liblutil/detach.c b/libraries/liblutil/detach.c index c6464c038..f47d36548 100644 --- a/libraries/liblutil/detach.c +++ b/libraries/liblutil/detach.c @@ -73,7 +73,7 @@ lutil_detach( int debug, int do_close ) #ifdef HAVE_THR pid = fork1(); #else - pid = fork(); + pid = rfork(RFPROC); #endif switch ( pid ) { It is incorrect because the code in slapd/main.c seems to expect the child to write a "1" to it before exiting with EXIT_SUCCESS() and obviously if the two processes shares the same file table, the parent would consider the start was failed because read() would fail. I think the right fix would be to move the lutil_detach() to before slapd_daemon_init(), see attachment, but it seems that some code after the initial daemon initialization is still trying to output to stderr, etc. What do you think? Cheers, On 10/20/17 09:00, Quanah Gibson-Mount wrote: > --On Friday, October 20, 2017 8:15 AM -0700 Quanah Gibson-Mount > <quanah@symas.com> wrote: > >> Thanks, I'll play around with the build some. I'm limiting slapd to as >> minimal a build as possible with my configure: >> >> ./configure --without-tls --without-cyrus-sasl --enable-ldap >> --enable-meta --enable-accesslog --enable-ppolicy --enable-rewrite >> --enable-rwm --prefix=/tmp/q > > > I've updated my configure to: > > CFLAGS="-O2 -pipe -fstack-protector -DLDAP_DEPRECATED > -fno-strict-aliasing" \ > ./configure \ > --with-threads=posix --with-tls=openssl --disable-dependency-tracking \ > --enable-dynamic --without-cyrus-sasl \ > --localstatedir=/var/db --enable-crypt --enable-ldap \ > --enable-meta --enable-rewrite --enable-null \ > --enable-monitor --disable-seqmod --enable-syncprov \ > --enable-mdb --without-fetch \ > --prefix=/tmp/q > > > And I still have no issues. I'm unable to get the freebsd version of > libtool to build shared libraries, so I can't test dynamic modules. > > --Quanah > > > -- > > Quanah Gibson-Mount > Product Architect > Symas Corporation > Packaged, certified, and supported LDAP solutions powered by OpenLDAP: > <http://www.symas.com> >diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 0a053c3ee..18d840c5a 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -692,6 +692,9 @@ unhandled_option:; ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug); ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug); ldif_debug = slap_debug; + if ( check != CHECK_NONE ) { + no_detach = 1; + } if ( version ) { fprintf( stderr, "%s\n", Versionstr ); @@ -739,6 +742,29 @@ unhandled_option:; global_host = ldap_pvt_get_fqdn( NULL ); ber_str2bv( global_host, 0, 0, &global_host_bv ); +#ifndef HAVE_WINSOCK + if ( !no_detach ) { + if ( lutil_pair( waitfds ) < 0 ) { + Debug( LDAP_DEBUG_ANY, + "main: lutil_pair failed: %d\n", + 0, 0, 0 ); + rc = 1; + goto destroy; + } + pid = lutil_detach( no_detach, 0 ); + if ( pid ) { + char buf[4]; + rc = EXIT_SUCCESS; + close( waitfds[1] ); + if ( read( waitfds[0], buf, 1 ) != 1 ) + rc = EXIT_FAILURE; + _exit( rc ); + } else { + close( waitfds[0] ); + } + } +#endif /* HAVE_WINSOCK */ + if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) { rc = 1; SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 ); @@ -911,29 +937,6 @@ unhandled_option:; (void) SIGNAL( SIGBREAK, slap_sig_shutdown ); #endif -#ifndef HAVE_WINSOCK - if ( !no_detach ) { - if ( lutil_pair( waitfds ) < 0 ) { - Debug( LDAP_DEBUG_ANY, - "main: lutil_pair failed: %d\n", - 0, 0, 0 ); - rc = 1; - goto destroy; - } - pid = lutil_detach( no_detach, 0 ); - if ( pid ) { - char buf[4]; - rc = EXIT_SUCCESS; - close( waitfds[1] ); - if ( read( waitfds[0], buf, 1 ) != 1 ) - rc = EXIT_FAILURE; - _exit( rc ); - } else { - close( waitfds[0] ); - } - } -#endif /* HAVE_WINSOCK */ - #ifdef CSRIMALLOC mal_leaktrace(1); #endifAttachment: signature.asc
Description: OpenPGP digital signature
--- End Message ---