[Nagiosplug-devel] tip for plugin development and temp files
Matthieu Fournet
fournet.matthieu at gmail.com
Tue Dec 27 22:44:45 CET 2011
Hi all,
I'd like to add my 10 cents to the plugins developer guidelines (at section
"3.3. Don't make temp files unless absolutely required",
http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN254),
regarding the use of temporary files.
Of course I agree with this piece of advice, but considering there's no
other solution than creating a temp file (carefully, and cleaning
everything before leaving !), there's one more rule developers have to keep
in mind : make temp files name unique.
Indeed, we all tend to name temp files like "tmp" or "temp", or whatever.
But in case of concurrent executions (the same plugin is run on the same
poller for 2 differents hosts, OR 2 distinct plugins running simultaneously
create temp files), you'll end up with both plugin trying to read / write /
open / delete the same file, and you may encounter some "file not found"
errors, whereas while running plugins manually, everything works just fine.
So my advice would be to name temp files like :
tmp_[plugin_name]_[timestamp]
or any combination so that temp files never collide.
Hope this helps ;-)
Cheers
Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20111227/aec7b0f7/attachment.html>
More information about the Devel
mailing list