Skip to content

Commit

Permalink
allow '*' as a subscriber name that implies trust of the CN connectin…
Browse files Browse the repository at this point in the history
…g requesting a durable stream
  • Loading branch information
postwait committed Feb 20, 2013
1 parent 0178e0e commit 927b6f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/noit_jlog_listener.c
Expand Up @@ -303,6 +303,7 @@ noit_jlog_handler(eventer_t e, int mask, void *closure,
if(!ac->service_ctx) { if(!ac->service_ctx) {
noit_log_stream_t ls; noit_log_stream_t ls;
const char *logname, *type; const char *logname, *type;
int first_attempt = 1;
char path[PATH_MAX], subscriber[256], *sub; char path[PATH_MAX], subscriber[256], *sub;
jcl = ac->service_ctx = noit_jlog_closure_alloc(); jcl = ac->service_ctx = noit_jlog_closure_alloc();
if(!noit_hash_retr_str(ac->config, if(!noit_hash_retr_str(ac->config,
Expand Down Expand Up @@ -351,20 +352,30 @@ noit_jlog_handler(eventer_t e, int mask, void *closure,
char *esub = strchr(sub, ')'); char *esub = strchr(sub, ')');
if(esub) { if(esub) {
*esub = '\0'; *esub = '\0';
*sub = '\0'; *sub++ = '\0';
} }
} }


jcl->jlog = jlog_new(path); jcl->jlog = jlog_new(path);
if(ac->cmd == NOIT_JLOG_DATA_TEMP_FEED) if(ac->cmd == NOIT_JLOG_DATA_TEMP_FEED) {
add_sub:
if(jlog_ctx_add_subscriber(jcl->jlog, jcl->subscriber, JLOG_END) == -1) { if(jlog_ctx_add_subscriber(jcl->jlog, jcl->subscriber, JLOG_END) == -1) {
snprintf(errbuff, sizeof(errbuff), snprintf(errbuff, sizeof(errbuff),
"jlog reader[%s] error: %s", jcl->subscriber, "jlog reader[%s] error: %s", jcl->subscriber,
jlog_ctx_err_string(jcl->jlog)); jlog_ctx_err_string(jcl->jlog));
errstr = errbuff; errstr = errbuff;
noitL(noit_error, "%s\n", errstr); noitL(noit_error, "%s\n", errstr);
} }
}
if(jlog_ctx_open_reader(jcl->jlog, jcl->subscriber) == -1) { if(jlog_ctx_open_reader(jcl->jlog, jcl->subscriber) == -1) {
if(sub && !strcmp(sub, "*")) {
if(first_attempt) {
jlog_ctx_close(jcl->jlog);
jcl->jlog = jlog_new(path);
first_attempt = 0;
goto add_sub;
}
}
snprintf(errbuff, sizeof(errbuff), snprintf(errbuff, sizeof(errbuff),
"jlog reader[%s] error: %s", jcl->subscriber, "jlog reader[%s] error: %s", jcl->subscriber,
jlog_ctx_err_string(jcl->jlog)); jlog_ctx_err_string(jcl->jlog));
Expand Down
8 changes: 5 additions & 3 deletions src/utils/noit_log.c
Expand Up @@ -454,7 +454,7 @@ jlog_logio_open(noit_log_stream_t ls) {
jlog_asynch_ctx *actx; jlog_asynch_ctx *actx;
jlog_ctx *log = NULL; jlog_ctx *log = NULL;
pthread_attr_t tattr; pthread_attr_t tattr;
int i, listed, found; int i, listed, found, allow_unmatched = 0;


if(jlog_lspath_to_fspath(ls, path, sizeof(path), &sub) <= 0) return -1; if(jlog_lspath_to_fspath(ls, path, sizeof(path), &sub) <= 0) return -1;
log = jlog_new(path); log = jlog_new(path);
Expand Down Expand Up @@ -497,20 +497,22 @@ jlog_logio_open(noit_log_stream_t ls) {
if(sub) { if(sub) {
/* Match all configured subscribers against jlog's list. */ /* Match all configured subscribers against jlog's list. */
for(p=strtok(sub, ",");p;p=strtok(NULL, ",")) { for(p=strtok(sub, ",");p;p=strtok(NULL, ",")) {
if(!strcmp(p,"*")) allow_unmatched = 1;
for(i=0;i<listed;i++) { for(i=0;i<listed;i++) {
if((subs[i]) && (strcmp(p, subs[i]) == 0)) { if((subs[i]) && (strcmp(p, subs[i]) == 0)) {
free(subs[i]); free(subs[i]);
subs[i] = NULL; subs[i] = NULL;
break; break;
} }
} }
if(i == listed) if(i == listed && strcmp(p,"*"))
jlog_ctx_add_subscriber(log, p, JLOG_BEGIN); jlog_ctx_add_subscriber(log, p, JLOG_BEGIN);
} }


/* Remove all unmatched subscribers. */ /* Remove all unmatched subscribers. */
for(i=0;i<listed;i++) { for(i=0;i<listed;i++) {
if(subs[i]) { if(subs[i] &&
(!allow_unmatched || subs[i][0] == '~')) {
jlog_ctx_remove_subscriber(log, subs[i]); jlog_ctx_remove_subscriber(log, subs[i]);
free(subs[i]); free(subs[i]);
subs[i] = NULL; subs[i] = NULL;
Expand Down
2 changes: 1 addition & 1 deletion test/t/testconfig.pm
Expand Up @@ -142,7 +142,7 @@ sub make_logs_config {
<log name="debug" disabled="$opts->{logs_debug}->{''}" timestamps="true"/> <log name="debug" disabled="$opts->{logs_debug}->{''}" timestamps="true"/>
</console_output> </console_output>
<feeds> <feeds>
<log name="feed" type="jlog" path="$cwd/logs/$opts->{name}.feed(stratcon)"/> <log name="feed" type="jlog" path="$cwd/logs/$opts->{name}.feed(*)"/>
</feeds> </feeds>
<components> <components>
}; };
Expand Down

0 comments on commit 927b6f9

Please sign in to comment.