[Freeswitch-svn] [commit] r10494 - freeswitch/trunk/src

FreeSWITCH SVN anthm at freeswitch.org
Fri Nov 21 07:55:18 PST 2008


Author: anthm
Date: Fri Nov 21 10:55:17 2008
New Revision: 10494

Log:
fix issue where pid file is accidentally truncated (part2)

Modified:
   freeswitch/trunk/src/switch.c

Modified: freeswitch/trunk/src/switch.c
==============================================================================
--- freeswitch/trunk/src/switch.c	(original)
+++ freeswitch/trunk/src/switch.c	Fri Nov 21 10:55:17 2008
@@ -610,15 +610,13 @@
 						 pid_path,
 						 SWITCH_FOPEN_READ,
 						 SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE,
-						 pool) != SWITCH_STATUS_SUCCESS) {
-		fprintf(stderr, "Cannot open pid file %s.\n", pid_path);
-		return 255;
+						 pool) == SWITCH_STATUS_SUCCESS) {
+
+		old_pid_len = sizeof(old_pid_buffer);
+		switch_file_read(fd, old_pid_buffer, &old_pid_len);
+		switch_file_close(fd);
 	}
 
-	old_pid_len = sizeof(old_pid_buffer);
-	switch_file_read(fd, old_pid_buffer, &old_pid_len);
-	switch_file_close(fd);
-	
 	if (switch_file_open(&fd,
 						 pid_path,
 						 SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE | SWITCH_FOPEN_TRUNCATE,
@@ -631,7 +629,9 @@
 	if (switch_file_lock(fd, SWITCH_FLOCK_EXCLUSIVE | SWITCH_FLOCK_NONBLOCK) != SWITCH_STATUS_SUCCESS) {
 		fprintf(stderr, "Cannot lock pid file %s.\n", pid_path);
 		old_pid_len = strlen(old_pid_buffer);
-		switch_file_write(fd, old_pid_buffer, &old_pid_len);
+		if (strlen(old_pid_buffer)) {
+			switch_file_write(fd, old_pid_buffer, &old_pid_len);
+		}
 		return 255;
 	}
 



More information about the Freeswitch-svn mailing list