Top «Prev(2005-11-25) Latest Next(2005-12-07)» Edit

pterjan's diary


2005-12-02

  Why you should always test return value

Today I lost the code I had been writing half the day, on an almost finished client code. Here is the guilty code, it was in a clone script written this summer (by someone I won't name here, he will recognize) during an internship.

if( -d "/tmp/wrap/" )
{
       system("/bin/umount /tmp/wrap/new 1>/dev/null 2>&1") if( -d "/tmp/wrap/new");
       system("/bin/umount /tmp/wrap/old 1>/dev/null 2>&1") if( -d "/tmp/wrap/old");
       system("rm -rf /tmp/wrap");
}

/tmp/wrap/old is used to mount the root partition of the original disk in order to update some stuff, /tmp/wrap/new being the copy.

Now, imagine umount want to tell me something like umount: /tmp/wrap/old: device is busy (want because it is muted). Yes, this code turns into rm -rf / and you lose all your work since last backup...

And now to have more fun, imagine that this same day, something in the deployement system is broken and you can't reinstall the machine. For even more fun, add that the project had to be finished today and you may understand how I currently feel.

If so, please help me find a large axe before the next time I meet the author.

(yes I should have saved the code more often but the USB key I bought last week died this morning...)

Today's TSUKKOMI(Total: 3) [Add a TSUKKOMI]
  lrz (2005-12-03 20:36)

I do not have an axe but a very good blame stick, that has been used several times with great satisfaction. I can lend it to you if you let me punish him once or twice :-)

  yoho (2005-12-04 19:46)

s/Yes, this code turns into rm -rf \//Yes, this code turns into rm -rf \/tmp\/wrap/<br><br>My 2ยข :)

  yoho (2005-12-04 19:49)

Oops, ok, now I understand... /tmp/wrap/{new|old} is the mounted "/", so ignore my previous comment ;)


2004|06|07|08|09|11|
2005|01|02|05|06|07|08|09|10|11|12|
2006|01|02|03|06|08|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|12|
2011|02|04|06|
2012|01|05|11|
2013|01|02|04|06|
2014|02|
2015|06|
2017|05|07|12|