[Pm-utils] [PATCH 01/17] Made init_logfile a little more paranoid about what it overwrites.

Victor Lowther victor.lowther at gmail.com
Sat Feb 9 18:31:05 PST 2008


---
 pm/functions.in |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/pm/functions.in b/pm/functions.in
index d7836b2..67764df 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -180,9 +180,17 @@ get_power_status()
 . "${SLEEP_FUNCTIONS}"
 
 init_logfile() {
-	if [ -n "$1" ]; then
-		exec > "$1" 2>&1
+	if [ -h "$1" ]; then
+		echo "$1 is a symbolic link, refusing to overwrite."
+		return 1
+	elif [ -O "$1" ]; then
+		echo "We do not own $1, refusing to overwrite."
+		return 1
+	elif [ -z "$1" ]; then
+		echo "Please pass a filename to init_logfile."
+		return 1
 	fi
+	exec > "$1" 2>&1
 }
 
 pm_main()
-- 
1.5.3.8



More information about the Pm-utils mailing list