Fixing nginx random segfaults

Logs in our client’s machine were filled with messages about nginx segfaults:

Sep 24 12:02:34 hostname kernel: nginx[8290]: segfault at 8 ip 00000000004935f0 sp 00007fff6698fd40 error 4 in nginx[400000+b5000]
Sep 24 12:02:34 hostname kernel: nginx[8292]: segfault at 8 ip 00000000004935f0 sp 00007fff6698fd40 error 4 in nginx[400000+b5000]
Sep 24 12:02:36 hostname kernel: nginx[8295]: segfault at 8 ip 00000000004935f0 sp 00007fff6698fd40 error 4 in nginx[400000+b5000]
Sep 24 12:02:36 hostname kernel: nginx[8296]: segfault at 8 ip 00000000004935f0 sp 00007fff6698fd40 error 4 in nginx[400000+b5000]

If you have more than one virtual host and you are using SSL on all of them, you may have incurred in this bug.

As the report states, a workaround is to specify the SSL session cache inside the http block instead than in each server’s block. We disabled it completely for testing and the segfaults went away.

Cycle through file names containing spaces in Bash

If you have a long list of file names and some of them contain spaces, in a Bash “for” cycle you would end up with the names split in several entries, for example:

$ $ ls -1 tmp/
Another file with spaces
File 1 with spaces
$ for F in $(ls -1 tmp) ; do echo $F ; done
Another
file
with
spaces
File
1
with
spaces

Manipulating the Bash Internal Field Separator (as detailed in the Advanced Bash Scripting Guide), we can tell Bash to ignore spaces:

$ IFS="$(printf '\n\t')"
$ for F in $(ls -1 tmp) ; do echo $F ; done
Another file with spaces
File 1 with spaces

I suggest you save your IFS in another variable before changing it, so you can restore it after you’re done.