Borrowing costs soar as Andy Burnham eyes 'flexibility' in fiscal rules under new Chancellor John Healey
Kevin Keegan dead at 75: Football legend passes away following battle with cancer as devastated family pay heartbreaking tribute to England icon
Man, 28, is charged with murder of Ann Widdecombe after former Tory minister was found dead at home
PETER HITCHENS: Critics warn Andy Burnham will take us back to the 70s. But with low crime and plenty of jobs, many of us would welcome it
Woman 'is raped in a park in broad daylight': Police appeal for witnesses
Secret Lives of Gypsy Wives fans say 'finally some good TV' as they binge-watch series
KEMI BADENOCH: In the 1980s Britons were proud of their country, richer and happier. I want to make us like that again
Dartford Crossing delays as motorbike crash partially shuts road
Severe delays on major route due to crash
Drinking 5 Cups of Coffee a Day Could Reduce Heart Risk
Read more of this story at Slashdot.
Europe slaps AliExpress with €550 million fine for selling dodgy goods
Paralyzed mother's face is picture of anguish as she prepares to stand trial for killing three young children in America's saddest murder trial
Acropolis stabbing attack leaves two US tourists injured
Woman allegedly 'spat in rail staff's face' after jumping ticket barrier
Bison attack survivor gives no-nonsense interview from his hospital bed
Trump unleashes shock 50 percent tariffs on Canada in explosive trade war over wine, cars and hockey sticks day after friendly exchange with Mark Carney at World Cup final as PM responds
CodeSOD: Classic WTF: Fork and Log
A few years back, Adam C. was brought in to help with some performance problems that appeared while load testing a VXML Platform. The project was already well behind and they couldn't figure out why the system kept falling over under a very slight load. To make matters worse, Adam had absolutely no prior knowledge of the system or its software other than Wikipedia’s definition of what VXML is.
A veteran to these sorts of situations, Adam grabbed a coffee, a donut, and then started picking through the application logs to get a feel for what the system is doing and where something might be going wrong.
Looking in /var/log/messages, he was pleased to find with several days’ worth of messages, but over and over again, the same entry popped up:
Exception encountered writing error log."Seriously, who logs an error that they can't log an error? ...and is that even possible?" Adam wondered aloud after seeing the same senseless message for what he figured to be the hundredth time.
Frustrated, and hoping to learn what ludicrous conditions might precipitate a log to contain such a message, Adam dug into the source and hit paydirt in the form of this wonderful nugget of code:
public void error(String logID, String errStr) { StringBuffer errLogCmd = new StringBuffer("/usr/bin/logger -p "); try { Runtime rt = Runtime.getRuntime(); errLogCmd.append(errlogFacility); errLogCmd.append(" -t "); errLogCmd.append(logID); errLogCmd.append(" "); errLogCmd.append(errStr); rt.exec(errLogCmd.toString()); } catch (Exception ele) { System.out.println("Exception encountered writing error log." + ele.getMessage()); } } As he mentally parsed his way through the code, Adam could feel his breakfast tickling up from the back of his throat in reaction to the number of WTF’s he found himself facing.He couldn’t decide what about the implementation was worse - forking off an external process to log something, the fact that log4j could have been used to send stuff to syslog (which the project used elsewhere), or that since the program's output was already piped to /usr/bin/log, just doing a System.out.println() would have been equivalent to this code.
As it turned out, this wasn’t the root cause behind the performance problems, but needless to say, that code got junked rather quickly and he moved on to looking for the next performance bottleneck.
[Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!