Skip to content
Browse files

bugfix: rule read "aa.log" without comma and file_limit

  • Loading branch information...
1 parent ac1915a commit 7aa9b5955be07dc2d2342de32ba40d62c66f6425 @HardySimpson committed Aug 8, 2012
Showing with 34 additions and 26 deletions.
  1. +1 −1 doc/zlog.conf
  2. +33 −25 src/rule.c
View
2 doc/zlog.conf
@@ -28,7 +28,7 @@ default.* >stdout; simple
simple
my_.INFO >stderr;
-my_cat.!ERROR "/var/log/aa.log"
+my_cat.!ERROR "aa.log"
my_dog.=DEBUG >syslog, LOG_LOCAL0; simple
my_dog.=DEBUG | /usr/bin/cronolog /www/logs/example_%Y%m%d.log ; normal
my_mice.* $record_func , "record_path%c"; normal
View
58 src/rule.c
@@ -458,8 +458,7 @@ static int syslog_facility_atoi(char *facility)
if (STRICMP(facility, ==, "LOG_USER"))
return LOG_USER;
- zc_error("wrong syslog facility[%s],"
- "must in LOG_LOCAL[0-7] or LOG_USER", facility);
+ zc_error("wrong syslog facility[%s], must in LOG_LOCAL[0-7] or LOG_USER", facility);
return -187;
}
@@ -692,12 +691,19 @@ zlog_rule_t *zlog_rule_new(char *line,
* *file_limit [20MB * 12 ~ "aa.#i.log" ] [LOG_LOCAL0]
*/
memset(file_path, 0x00, sizeof(file_path));
- nscan = sscanf(output, " %[^,], %n", file_path, &nread);
+ nscan = sscanf(output, " %[^,],", file_path);
if (nscan < 1) {
zc_error("sscanf [%s] fail", action);
goto err;
}
- file_limit = output + nread;
+
+ file_limit = strchr(output, ',');
+ if (file_limit) {
+ file_limit++; /* skip the , */
+ while( isspace(*file_limit) ) {
+ file_limit++;
+ }
+ }
p = NULL;
switch (file_path[0]) {
@@ -724,29 +730,31 @@ zlog_rule_t *zlog_rule_new(char *line,
goto err;
}
- memset(archive_max_size, 0x00, sizeof(archive_max_size));
- nscan = sscanf(file_limit, " %s * %d ~",
- archive_max_size, &(a_rule->archive_max_count));
- if (nscan) {
- a_rule->archive_max_size = zc_parse_byte_size(archive_max_size);
- }
-
- p = strchr(file_limit, '"');
- if (p) { /* archive file path exist */
- rc = zlog_rule_parse_path(p, a_rule->archive_path, sizeof(a_rule->file_path),
- &(a_rule->archive_specs));
- if (rc) {
- zc_error("zlog_rule_parse_path fail");
- goto err;
+ if (file_limit) {
+ memset(archive_max_size, 0x00, sizeof(archive_max_size));
+ nscan = sscanf(file_limit, " %s * %d ~",
+ archive_max_size, &(a_rule->archive_max_count));
+ if (nscan) {
+ a_rule->archive_max_size = zc_parse_byte_size(archive_max_size);
}
- p = strchr(a_rule->archive_path, '#');
- if ( (p == NULL) && (
- (strchr(p, 'r') == NULL) || (strchr(p, 's') == NULL)
- )
- ) {
- zc_error("archive_path must contain #r or #s");
- goto err;
+ p = strchr(file_limit, '"');
+ if (p) { /* archive file path exist */
+ rc = zlog_rule_parse_path(p, a_rule->archive_path, sizeof(a_rule->file_path),
+ &(a_rule->archive_specs));
+ if (rc) {
+ zc_error("zlog_rule_parse_path fail");
+ goto err;
+ }
+
+ p = strchr(a_rule->archive_path, '#');
+ if ( (p == NULL) && (
+ (strchr(p, 'r') == NULL) || (strchr(p, 's') == NULL)
+ )
+ ) {
+ zc_error("archive_path must contain #r or #s");
+ goto err;
+ }
}
}

0 comments on commit 7aa9b59

Please sign in to comment.
Something went wrong with that request. Please try again.