[Nagiosplug-devel] tip for plugin development and temp files

Paul Green paulg at greenwand.net
Wed Dec 28 11:35:05 CET 2011


Could I suggest process ID rather than timestamp, as it's shorter and
removes the remote chance of a clash altogether.

Cheers

Paul

On Tue, 27 Dec 2011 22:44:45 +0100, Matthieu Fournet
<fournet.matthieu at gmail.com> wrote:
> 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




More information about the Devel mailing list