[emt] r212 committed - Fixed a bug where if a user installed the rpm then ran emt_view before...

1 view
Skip to first unread message

e...@googlecode.com

unread,
Aug 20, 2010, 6:32:52 PM8/20/10
to emt...@googlegroups.com
Revision: 212
Author: eric.bergen
Date: Fri Aug 20 15:29:00 2010
Log: Fixed a bug where if a user installed the rpm then ran emt_view before
emt_gather had a chance to run the csv file was created and own by the user
who ran emt_view instead of the emt user. Now the file will be opened read
only and if the output handler needs to write it reopens the file
read/write.

http://code.google.com/p/emt/source/detail?r=212

Modified:
/trunk/plugins/output/local_text.php

=======================================
--- /trunk/plugins/output/local_text.php Sun May 10 14:52:39 2009
+++ /trunk/plugins/output/local_text.php Fri Aug 20 15:29:00 2010
@@ -33,12 +33,13 @@
if (!isset($this->config['output_file']))
log_error_and_exit("local_text output handler needs
output_file specified under [local_text] in emt.cnf");

- $this->fp = @fopen($this->config['output_file'], 'a');
- if (!$this->fp) {
- //try to open read only
- if (!($this->fp = fopen($this->config['output_file'], 'r')))
- log_error_and_exit("Unable to open log file " .
$this->config['output_file']);
- }
+ /**
+ * Open the file read only first. The close method will upgrade it
to writeable if it needs to
+ * This fixes a bug where running emt_view before the file existed
created the file as the user
+ * that ran emt_view
+ */
+ if (!($this->fp = fopen($this->config['output_file'], 'r')))
+ log_error("Unable to open csv file " .
$this->config['output_file']);
}

function write($field)
@@ -71,8 +72,16 @@
{
$this->output = preg_replace('/,$/', '',
trim($this->output)) . "\n";

- if (fwrite($this->fp, $this->output, strlen($this->output)) ===
FALSE)
- log_error("Failed to write to {$this->config['output_file']}");
+ if ($this->output)
+ {
+ fclose($this->fp);
+
+ if (!($this->fp = fopen($this->config['output_file'], 'w')))
+ log_error_and_exit("Unable to open log file " .
$this->config['output_file']);
+
+ if (fwrite($this->fp, $this->output, strlen($this->output))
=== FALSE)
+ log_error("Failed to write to
{$this->config['output_file']}");
+ }
}

/**

Reply all
Reply to author
Forward
0 new messages