#41291 [NEW]: FastCGI does not set SO_REUSEADDR

2007-05-04 Thread fmajid at kefta dot com
From: fmajid at kefta dot com
Operating system: Solaris
PHP version:  5.2.2
PHP Bug Type: CGI related
Bug description:  FastCGI does not set SO_REUSEADDR

Description:

The CGI/FastCGI SAPI does not set the SO_REUSEADDR option. This can
prevent the FastCGI server from being restarted if it exits with sockets in
the TIME_WAIT state.

The patch below fixes this.

That said, a much better option would be to refactor the fastcgi.c code to
use php_network_bind_socket_to_local_addr instead of reinventing the square
wheel.

*** php-5.2.1/sapi/cgi/fastcgi.c~   Mon Jan  1 01:36:12 2007
--- php-5.2.1/sapi/cgi/fastcgi.cFri May  4 11:45:39 2007
***
*** 253,258 
--- 253,261 
int   listen_socket;
sa_t  sa;
socklen_t sock_len;
+ #ifdef SO_REUSEADDR
+   int   val = 1;
+ #endif

if ((s = strchr(path, ':'))) {
port = atoi(s+1);
***
*** 308,313 
--- 311,319 

/* Create, bind socket and start listen on it */
if ((listen_socket = socket(sa.sa.sa_family, SOCK_STREAM, 0)) < 0
||
+ #ifdef SO_REUSEADDR
+   setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR,
(char*)&val, sizeof(val)) < 0 ||
+ #endif
bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 ||
listen(listen_socket, backlog) < 0) {



Reproduce code:
---
Run a FastCGI web server and start the FastCGI SAPI using php -b.
Kill the FastCGI process.
Attempt to restart it.

Expected result:

FastCGI server restarting normally

Actual result:
--
alamut ~>php-cgi -b 127.0.0.1: -c /home/majid/web/conf
Cannot bind/listen socket - [125] Address already in use.
Couldn't create FastCGI listen socket on port 127.0.0.1:


-- 
Edit bug report at http://bugs.php.net/?id=41291&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41291&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41291&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41291&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41291&r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=41291&r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=41291&r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=41291&r=needscript
Try newer version:http://bugs.php.net/fix.php?id=41291&r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=41291&r=support
Expected behavior:http://bugs.php.net/fix.php?id=41291&r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=41291&r=notenoughinfo
Submitted twice:  
http://bugs.php.net/fix.php?id=41291&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41291&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41291&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41291&r=dst
IIS Stability:http://bugs.php.net/fix.php?id=41291&r=isapi
Install GNU Sed:  http://bugs.php.net/fix.php?id=41291&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41291&r=float
No Zend Extensions:   http://bugs.php.net/fix.php?id=41291&r=nozend
MySQL Configuration Error:http://bugs.php.net/fix.php?id=41291&r=mysqlcfg


Bug #16005: Conflict between OpenLDAP and Oracle

2002-03-11 Thread fmajid

From: [EMAIL PROTECTED]
Operating system: Solaris 8/Intel
PHP version:  4.1.2
PHP Bug Type: LDAP related
Bug description:  Conflict between OpenLDAP and Oracle

PHP dumps core when compiled with both LDAP and OCI8. The reason is the
Oracle client libraries include an LDAP library, and PHP is calling the
Oracle ldap_modify_s instead of the OpenLDAP ldap_modify_s. We are using
OpenLDAP 1.2.11 and Oracle 8.1.6.

Short-term workaround: use LD_PRELOAD, e.g. add:

LD_PRELOAD=/usr/local/ldap/lib/libldap.so
export LD_PRELOAD

to your Apache start scripts.

Here is the gdb backtrace:

(gdb) r -X -f /usr/local/apache/conf/httpd-kefta.conf
Starting program: /usr/local/apache/bin/httpd -X -f
/usr/local/apache/conf/httpd
-kefta.conf
[New LWP 1]
[New LWP 2]
[New LWP 3]
warning: Lowest section in /usr/lib/libintl.so.1 is .dynamic at 0074
[New LWP 4]
warning: Lowest section in /usr/lib/libintl.so.1 is .dynamic at 0074

Program received signal SIGSEGV, Segmentation fault.
0xde589e0a in gsleenSBerPrintf () from
/export/home/oracle/lib/libclntsh.so.8.0
(gdb) bt
#0  0xde589e0a in gsleenSBerPrintf ()
   from /export/home/oracle/lib/libclntsh.so.8.0
#1  0xde580234 in gslcmom_Modify ()
   from /export/home/oracle/lib/libclntsh.so.8.0
#2  0xde57d8e7 in ldap_modify_s ()
   from /export/home/oracle/lib/libclntsh.so.8.0
#3  0xdee2f440 in php_ldap_do_modify (ht=3, return_value=0x81f5d0c,
this_ptr=0x0, return_value_used=0, oper=2) at ldap.c:1364
#4  0xdee2f5e1 in zif_ldap_modify (ht=3, return_value=0x81f5d0c,
this_ptr=0x0,
return_value_used=0) at ldap.c:1399
#5  0xdedd51b9 in execute (op_array=0x8195fc0) at ./zend_execute.c:1590
#6  0xdedd540c in execute (op_array=0x819296c) at ./zend_execute.c:1630
#7  0xdede66b0 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
at zend.c:814
#8  0xdedf98c1 in php_execute_script (primary_file=0x8047808) at
main.c:1307
#9  0xdedf3d4a in apache_php_module_main (r=0x818a750,
display_source_mode=0)
at sapi_apache.c:90
#10 0xdedf4f00 in send_php (r=0x818a750, display_source_mode=0,
filename=0x818c338 "/usr/local/apache/htdocs/mail/mailforward.php")
at mod_php4.c:575
#11 0xdedf4f73 in send_parsed_php (r=0x818a750) at mod_php4.c:590
#12 0x8088945 in ap_invoke_handler (r=0x818a750) at http_config.c:517
#13 0x809e794 in process_request_internal (r=0x818a750) at
http_request.c:1308
#14 0x809e7fe in ap_process_request (r=0x818a750) at http_request.c:1324
---Type  to continue, or q  to quit---q
Quit
(gdb) i sym

Here is the final link stage in compiling PHP. Please note -lldap is
supplied before -lclntsh, and thus OpenLDAP should resolve first, but
apparently this is not the case:

/bin/sh /home/majid/src/php-4.1.2/libtool --silent --mode=link gcc  -I.
-I/home/
majid/src/php-4.1.2/ -I/home/majid/src/php-4.1.2/main
-I/home/majid/src/php-4.1.
2 -I/usr/local/ldap/include -I/export/home/oracle/rdbms/demo
-I/export/home/orac
le/network/public -Iexpat/xmltok -Iexpat/xmlparse -Iimap-4.7c/c-client
-I/usr/lo
cal/apache/include -I/home/majid/src/php-4.1.2/Zend
-I/usr/local/include/freetyp
e -I/usr/local/include -I/usr/local/ldap/include
-I/usr/local/mysql/include/mysq
l -I/export/home/oracle/rdbms/public -I/export/home/oracle/rdbms/demo
-I/export/
home/oracle/network/public -I/home/majid/src/php-4.1.2/ext/xml/expat 
-D_POSIX_P
THREAD_SEMANTICS -DSOLARIS2=280 -DMOD_SSL=208106 -DEAPI -DEAPI_MM
-DUSE_EXPAT -I
/home/majid/src/php-4.1.2/TSRM -g -DEAPI -prefer-pic   -o libphp4.la
-rpath /hom
e/majid/src/php-4.1.2/libs -export-symbols
/home/majid/src/php-4.1.2/sapi/apache
/php.sym -avoid-version -L/usr/ucblib
-L/usr/local/lib/gcc-lib/i386-pc-solaris2.
8/2.95.2 -L/usr/local/lib -L/usr/local/ldap/lib
-L/usr/local/mysql/lib/mysql -L/
export/home/oracle/lib  -R /usr/ucblib -R
/usr/local/lib/gcc-lib/i386-pc-solaris
2.8/2.95.2 -R /usr/local/lib -R /usr/local/ldap/lib -R
/usr/local/mysql/lib/mysq
l -R /export/home/oracle/lib stub.lo  Zend/libZend.la 
sapi/apache/libsapi.la  m
ain/libmain.la  regex/libregex.la  ext/gd/libgd.la ext/imap/libimap.la
ext/ldap/
libldap.la ext/mhash/libmhash.la ext/mysql/libmysql.la ext/oci8/liboci8.la
ext/p
cre/libpcre.la ext/posix/libposix.la ext/session/libsession.la
ext/standard/libs
tandard.la ext/xml/libxml.la  TSRM/libtsrm.la -L/usr/local/ldap/lib
-L/usr/local
/lib -lgd -lmhash -llber -lldap -L/export/home/oracle/lib -lclient8
-lclntsh -L/
usr/local/mysql/lib/mysql -lmysqlclient -lpam -limap -ldl -lm -lthread
-laio -le
lf -ldl -lgen -lnsl -lsocket -lmysqlclient -lmhash -lldap -llber -lcrypt
-lpam -
lgd -lttf -lcrypt -lresolv -lresolv -lresolv -lm -ldl -lnsl -lsocket
-lsocket -l
gcc -lcrypt -lclntsh



-- 
Edit bug report at http://bugs.php.net/?id=16005&edit=1
-- 
Fixed in CVS:http://bugs.php.net/fix.php?id=16005&r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=16005&r=alreadyfixed
Need backtrace:  http://bugs.php.net/fix.php?id=16005&r