Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

On second thought, the mktemp solution was a kludge.

Better solution: Add a configurable variable replacement for the tempfile
creation method and use that in plugins that require a tempfile.  This
uses a shell script that tries a variety of tempfile creation methods.
  • Loading branch information...
commit 7f66120069238c2c7c9e97fb18a09ae46138b103 1 parent 232efb2
@LupeChristoph LupeChristoph authored
View
1  Makefile
@@ -142,6 +142,7 @@ build-stamp:
-e 's|@@PYTHON@@|$(PYTHON)|g' \
-e 's|@@OSTYPE@@|$(OSTYPE)|g' \
-e 's|@@HOSTNAME@@|$(HOSTNAME)|g' \
+ -e 's|@@MKTEMP@@|$(MKTEMP)|g' \
-e 's|@@VERSION@@|$(VERSION)|g' \
-e 's|@@PLUGSTATE@@|$(PLUGSTATE)|g' \
-e 's|@@CGIDIR@@|$(CGIDIR)|g' \
View
5 Makefile.config
@@ -61,6 +61,11 @@ OSTYPE = $(shell uname | tr '[A-Z]' '[a-z]')
# files)
HOSTNAME = $(shell hostname)
+# What is the safest way to create a tempfile.
+# Default is to figure it out by testing various methods.
+# Replace this with a known platform-specific method
+MKTEMP = $(shell ./test-mktemp)
+
# Munin version number.
VERSION = $(shell cat RELEASE)
View
16 node/node.d/amavis.in
@@ -14,22 +14,12 @@
# amavislog - file where amavis logs are written
#
+@@MKTEMP@@
+
AMAVIS_LOG=${logfile:-/var/log/mail/mail.info}
LOGTAIL=${logtail:-`which logtail`}
STATEFILE=@@PLUGSTATE@@/amavis.offset
-
-case `uname -s` in
-Linux)
- TEMP_FILE=`mktemp -p /tmp/ munin-amavis.XXXXXX`
- if [ $? != 0 ]; then
- TEMP_FILE=`mktemp /tmp/munin-amavis.XXXXXX`
- fi
- ;;
-FreeBSD)
- TEMP_FILE=`mktemp -t /tmp`
- STATUS=$?
- ;;
-esac
+TEMP_FILE=`mktempfile munin-amavis.XXXXXX`
if [ -z "$TEMP_FILE" ]; then
# Yes, this is unsafe
View
22 node/node.d/courier_.in
@@ -38,25 +38,11 @@ SERVICE=${service:-`basename $0 | sed 's/^courier_//g'`}
OFFSET_FILE=@@PLUGSTATE@@/courier_${SERVICE}.offset
LOGTAIL=${logtail:-/usr/sbin/logtail}
-case `uname -s` in
-Linux)
- TEMP_FILE=`mktemp -p /tmp/ munin-courier.XXXXXX`
- if [ $? != 0 ]; then
- TEMP_FILE=`mktemp /tmp/munin-courier.XXXXXX`
- fi
- ;;
-FreeBSD)
- TEMP_FILE=`mktemp -t /tmp`
- STATUS=$?
- ;;
-esac
+mktempfile () {
+@@MKTEMP@@
+}
-if [ -z "$TEMP_FILE" ]; then
- # Yes, this is unsafe
- TEMP_FILE=/tmp/munin-courier.$$
- rm -rf $TEMP_FILE
- touch $TEMP_FILE
-fi
+TEMP_FILE=`mktempfile munin-courier.XXXXXX`
if [ ! -f "$TEMP_FILE" ]; then
exit 3
View
24 node/node.d/perdition.in
@@ -23,31 +23,15 @@
# buffy perdition[27754]: Fatal error establishing SSL connection to client
# buffy perdition[5139]: Fatal error negotiating setup. Exiting child.
+mktempfile () {
+@@MKTEMP@@
+}
# Set the location of the perdition logs
PERDITION_LOG=${logfile:-/var/log/perdition.log}
OFFSET_FILE=@@PLUGSTATE@@/perdition.offset
LOGTAIL=${logtail:-/usr/sbin/logtail}
-
-case `uname -s` in
-Linux)
- TEMP_FILE=`mktemp -p /tmp/ munin-perdition.XXXXXX`
- if [ $? != 0 ]; then
- TEMP_FILE=`mktemp /tmp/munin-perdition.XXXXXX`
- fi
- ;;
-FreeBSD)
- TEMP_FILE=`mktemp -t /tmp`
- STATUS=$?
- ;;
-esac
-
-if [ -z "$TEMP_FILE" ]; then
- # Yes, this is unsafe
- TEMP_FILE=/tmp/munin-perdition.$$
- rm -rf $TEMP_FILE
- touch $TEMP_FILE
-fi
+TEMP_FILE=`mktempfile munin-perdition.XXXXXX
if [ ! -f "$TEMP_FILE" ]; then
exit 3
View
67 test-mktemp
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+# This file tries to determine the best method to create a tempfile
+# by testing various methods.
+
+# Copyright (c) 2005, Lutz Peter Christoph
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# * The name and aliases of Lutz Peter Christoph ("Lupe Christoph",
+# "Lutz Christoph") may not be used to endorse or promote products
+# derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+testfun () {
+ TEMP_FILE=`eval $MKTEMP 2>/dev/null`
+ STATUS=$?
+ if [ $STATUS = 0 -a -n "$TEMP_FILE" -a -f "$TEMP_FILE" ]; then
+ rm -f $TEMP_FILE
+ echo $MKTEMP
+ exit
+ else
+ rm -f $TEMP_FILE
+ fi
+}
+
+# Preferred
+MKTEMP='mktemp -p /tmp/ $1'
+testfun temp.XXXXXX
+
+# FreeBSD way
+MKTEMP="mktemp -t /tmp"
+testfun temp.XXXXXX
+
+# Plain mktemp
+MKTEMP="mktemp /tmp/$1"
+testfun temp.XXXXXX
+
+# No mktemp at all
+MKTEMP='rm -rf /tmp/$1.$$ && touch /tmp/$1.$$ && chmod 600 /tmp/$1.$$ && echo /tmp/$1.$$'
+testfun temp.XXXXXX
+
+exit 1
Please sign in to comment.
Something went wrong with that request. Please try again.