[Nagiosplug-devel] tip for plugin development and temp files
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.
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
> "3.3. Don't make temp files unless absolutely required",
> 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
> 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
> 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
> So my advice would be to name temp files like :
> or any combination so that temp files never collide.
> Hope this helps ;-)
More information about the Devel