Monday, April 28, 2008
I must have forgotten my cardboard programmer that day …
D'oh!
Smirk called today, saying a customer had a problem sending mail with one
of their PHP scripts. The server in question was running my PHP/sendmail
wrapper and the testing that Smirk did showed that the PHP mail()
function wasn't returning anything! Funny, for a function that
supposedly returns a bool
…
With Wlofie
playing the part of cardboard programmer,
I did some testing, found that indeed, there was a problem—at first, it
looked like the system was terminating the program with random signals. One
time it would terminate with a SIGXFSZ
, then with
SIGTTIN
, then with SIGWINCH
!
I then stared at the code until I bled …
else /* parent process */ { pid_t cstat; int status; cstat = waitpid(child,&status,0); if (WIFEXITED(cstat)) rc = WEXITSTATUS(cstat); else rc = EXIT_FAILURE; unlink(tmpfile); /* make sure we clean up after ourselves */ exit(rc); }
It was then i saw my mistake—I was checking the wrong variable!
Sigh.
The type of mistake a statically typed language should catch. And before you say “unit testing” my tests were basically “did the email go through? Yup? Then it works”—the thought to check the return code of my program as a whole didn't occur to me (hey, the email got through, right? that meant that it worked).
I changed WIFEXITED(cstat)
to WIFEXITED(status)
and WEXITSTATUS(cstat)
to WEXITSTATUS(status)
and
it worked.
I also checked PHP, and for the life of me, I can't figure out
why it was returning undef
, but then again, PHP is the
scripting language du jour so it
may be I didn't check the precise version we're running.