Tag Archives: freebsd

apache deaths with signal 4

Yesterday I did an major upgrade to an rather busy website (should be in the top 10 most used in my country). Basically I moved the code from the old 32 bit single-core webserver running FreeBSD 4.8, Apache 1.3 and PHP 4.X to a new 64 bit, 4 core server running FreeBSD 7.0, Apache 2.2, PHP 5.2. As you might imagine changing so many variables at once caused several surprises. Most interesting one was that Apache died on some pages with signal 4 (SIGILL) which stands for illegal instruction. It’s not that uncommon to see apache deaths with signals 11 (SIGSEGV) and 6 (SIGBUS) which are usually caused by bugs in some PHP modules but signal 4 was something new to me. Quick Google search turned up some threads were people reported getting rid of it by changing module orders in PHPs extensions.ini file and a bug report about PHP function preg_replace() sometimes causing it.

I tried both theories and neither one was the case that I had. Then I spent some time looking at the coredump with GDB but in the end I resorted to good old binary search strategy. So to make a long story short the cause turned out to be a recursive function in the website code that under some circumstances never stopped recursing until it overflowed it’s stack.

FreeBSD & Huawei E630

I recently got Huawei E630 PCMCIA data card that can handle HSDPA/UMTS/EDGE/GPRS/GSM. Cursory look at the internet told me that this card should work under Linux so I was almost sure that I can get it working under FreeBSD (eventually). After plugging it in I was a little surprised to find that it presented itself to the system as a USB mass storage device and SCSI CD-ROM device cd0 tried to handle it (without much success). After doing some research I found that some of the Huawei cards contain this mass storage part that they use to store drivers for Windows and you have to send a magic request to it in order to force it into modem mode.

I found a small program by Hans Petter Selasky that tries to send this message and it indeed seemed to work at least as far as sending of the message is concerned but the problem for me was that the system had already recognized the device as a storage device and so I had no way of attaching ubsa/ucom devices to it. It might be that it would work if you remove the umass device from the kernel and load only the ubsa & ucom modules after running this program. Anyway instead of trying this I took proposed patch against OpenBSDs umsm driver that did the necessary poking in the initialization routine and hacked it into FreeBSDs ubsa driver (patch).

In general it seems to work quite well. Sometimes I get ucom0: ubsa_request: STALLED messages from the kernel when dialing, but it usually works fine at the next attempt.

Here’s what it outputs to the syslog when I insert the card:

ohci0: <NEC uPD 9210 USB controller> mem 0xb0207000-0xb0207fff irq 16 at device 0.0 on cardbus0
ohci0: [GIANT-LOCKED]
ohci0: [ITHREAD]
usb5: OHCI version 1.0
usb5: <NEC uPD 9210 USB controller> on ohci0
usb5: USB revision 1.0
uhub5: <NEC OHCI root hub, class 9/0, rev 1.00/1.00, addr 1> on usb5
uhub5: 1 port with 1 removable, self powered
ohci1: <NEC uPD 9210 USB controller> mem 0xb0208000-0xb0208fff irq 16 at device 0.1 on cardbus0
ohci1: [GIANT-LOCKED]
ohci1: [ITHREAD]
usb6: OHCI version 1.0
usb6: <NEC uPD 9210 USB controller> on ohci1
usb6: USB revision 1.0
uhub6: <NEC OHCI root hub, class 9/0, rev 1.00/1.00, addr 1> on usb6
uhub6: 1 port with 1 removable, self powered
ucom0: <HUAWEI Technologies HUAWEI Mobile, class 0/0, rev 1.10/0.00, addr 2> on uhub5
ucom0: Could not find interrupt in
device_attach: ucom0 attach returned 6
ucom0: <HUAWEI Technologies HUAWEI Mobile, class 0/0, rev 1.10/0.00, addr 2> on uhub5
ucom0: failed to set configuration: IOERROR
device_attach: ucom0 attach returned 6
ucom0: at uhub5 port 1 (addr 2) disconnected
ucom0: <HUAWEI Technologies HUAWEI Mobile, class 0/0, rev 1.10/0.00, addr 2> on uhub5

And here’s my /etc/ppp/ppp.conf file:

umts:
set device /dev/cuaU0
set speed 384000
set phone *99***1\#
set authname ""
set authkey ""
set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
\"\" AT OK-AT-OK ATE1Q0 OK \\dATDT\\T TIMEOUT 40 CONNECT"
add default HISADDR
set ifaddr 10.0.0.1/0 10.0.0.2/0 0.0.0.0 0.0.0.0

To establish a connection I just use the command ppp -background umts

PS
It’s also a little annoying that the system always panics when you remove the card. It seems to be a known problem with the teardown ordering in the current USB stack and is said to be fixed in the FreeBSDs new USB stack that is currently still in the perforce.