[Orca-checkins] r329 - trunk/orca/data_gatherers/orcallator
Blair Zajac
blair at orcaware.com
Sat May 29 23:06:27 PDT 2004
Author: blair
Date: Sat May 29 23:04:43 2004
New Revision: 329
Modified:
trunk/orca/data_gatherers/orcallator/orcallator.se
Log:
* data_gatherers/orcallator/orcallator.se
(check_output_log_filename):
Optimize the determination of the output log file to write to.
Patch by Dmitry Berezin <dberezin at surfside.rutgers.edu>.
Fix a race condition. When orcallator.se looks for an output log
filename to write to, if it finds an uncompressed log file, it
will spawn a compression program in the background to compress
it. If the compression program does not finish compressing and
removing the uncompressed log file by the time orcallator.se
finishes the next interval and enters check_output_log_filename
again, then because check_output_log_filename() didn't check for
the existence of a partially compressed log file, it will spawn
another compression program in the background. This can cause
problems. Now, check that there are no compressed log files
before compressing the uncompressed log file. Bug found by
Dmitry Berezin <dberezin at surfside.rutgers.edu>.
Modified: trunk/orca/data_gatherers/orcallator/orcallator.se
==============================================================================
--- trunk/orca/data_gatherers/orcallator/orcallator.se (original)
+++ trunk/orca/data_gatherers/orcallator/orcallator.se Sat May 29 23:04:43 2004
@@ -699,7 +699,8 @@
char tm_buf[32];
int file_number;
int need_new_log_file;
- int exists;
+ int exists_uncompressed;
+ int exists_compressed;
int result;
int i;
@@ -744,33 +745,53 @@
// Get the new filename. Check for already existing uncompressed
// log filenames and compressed log filenames.
- file_number = 0;
strftime(tm_buf, sizeof(tm_buf), "%Y-%m-%d", now);
+
+ // If the previous log filename has the same date, then increment
+ // the file number, otherwise reset it to 0. The first time
+ // through, output_filename will be nil.
+ if (nil != output_filename && output_filename =~ tm_buf) {
+ file_number++;
+ } else {
+ file_number = 0;
+ }
+
while (1 == 1) {
- exists = 0;
+
+ // Check for the existence of uncompressed and compressed log
+ // files. If there is an uncompressed log file but no
+ // compressed ones, then compress it in the background. If
+ // either an uncompressed or compressed log file exist, then
+ // check the next file number.
output_filename = sprintf("%s/orcallator-%s-%03d", output_directory,
tm_buf,
file_number);
result = stat(output_filename, log_file_stat);
if (result != -1) {
- exists = 1;
- if (compress != nil) {
- system(sprintf(compress, output_filename));
- }
+ exists_uncompressed = 1;
} else {
- for (i=0; i<NUMBER_COMPRESS_SUFFIXES; ++i) {
- compressed_filename = sprintf("%s%s", output_filename,
- compression_suffixes[i]);
- result = stat(compressed_filename, log_file_stat);
- if (result != -1) {
- exists = 1;
- break;
- }
+ exists_uncompressed = 0;
+ }
+
+ exists_compressed = 0;
+ for (i=0; i<NUMBER_COMPRESS_SUFFIXES; ++i) {
+ compressed_filename = sprintf("%s%s", output_filename,
+ compression_suffixes[i]);
+ result = stat(compressed_filename, log_file_stat);
+ if (result != -1) {
+ exists_compressed = 1;
+ break;
}
}
- if (exists != 0) {
- file_number++;
+ if (nil != compress &&
+ 0 != exists_uncompressed &&
+ 0 == exists_compressed) {
+ system(sprintf(compress, output_filename));
+ }
+
+ if (0 != exists_uncompressed || 0 != exists_compressed) {
+ ++file_number;
} else {
break;
}
More information about the Orca-checkins
mailing list