TS-2188 healthcheck plugin doesn't parse config files properly This is part of the fixes to the healthcheck plugins, such that we don't segfault. This part of the fix actually makes sure we properly parse the configuration file as was expected.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/49d00ff1 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/49d00ff1 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/49d00ff1 Branch: refs/heads/5.0.x Commit: 49d00ff1fe2d8097952aa857d1b4d79103825043 Parents: a27b9e7 Author: Leif Hedstrom <[email protected]> Authored: Mon Sep 9 13:29:28 2013 -0600 Committer: Leif Hedstrom <[email protected]> Committed: Mon Sep 9 13:37:28 2013 -0600 ---------------------------------------------------------------------- .../experimental/healthchecks/healthchecks.c | 42 +++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/49d00ff1/plugins/experimental/healthchecks/healthchecks.c ---------------------------------------------------------------------- diff --git a/plugins/experimental/healthchecks/healthchecks.c b/plugins/experimental/healthchecks/healthchecks.c index 3c550b7..47b4f7b 100644 --- a/plugins/experimental/healthchecks/healthchecks.c +++ b/plugins/experimental/healthchecks/healthchecks.c @@ -312,14 +312,11 @@ parse_configs(const char* fname) int state = 0; char *ok=NULL, *miss=NULL, *mime=NULL; - prev_finfo = finfo; - finfo = TSmalloc(sizeof(HCFileInfo)); - memset(finfo, 0, sizeof(HCFileInfo)); - - if (NULL == head_finfo) - head_finfo = finfo; - if (prev_finfo) - prev_finfo->_next = finfo; + /* Allocate a new config-info, if we don't have one already */ + if (!finfo) { + finfo = TSmalloc(sizeof(HCFileInfo)); + memset(finfo, 0, sizeof(HCFileInfo)); + } if (fgets(buf, sizeof(buf) - 1, fd)) { str = strtok_r(buf, SEPARATORS, &save); @@ -353,12 +350,25 @@ parse_configs(const char* fname) str = strtok_r(NULL, SEPARATORS, &save); } - finfo->ok = gen_header(ok, mime, &finfo->o_len); - finfo->miss = gen_header(miss, mime, &finfo->m_len); - finfo->data = TSmalloc(sizeof(HCFileData)); - memset(finfo->data, 0, sizeof(HCFileData)); - reload_status_file(finfo, finfo->data); - TSDebug(PLUGIN_NAME, "Parsed: %s %s %s %s %s", finfo->path, finfo->fname, mime, ok, miss); + /* Fill in the info if everything was ok */ + if (state > 4) { + TSDebug(PLUGIN_NAME, "Parsed: %s %s %s %s %s", finfo->path, finfo->fname, mime, ok, miss); + finfo->ok = gen_header(ok, mime, &finfo->o_len); + finfo->miss = gen_header(miss, mime, &finfo->m_len); + finfo->data = TSmalloc(sizeof(HCFileData)); + memset(finfo->data, 0, sizeof(HCFileData)); + reload_status_file(finfo, finfo->data); + + /* Add it the linked list */ + TSDebug(PLUGIN_NAME, "Adding path=%s to linked list", finfo->path); + if (NULL == head_finfo) { + head_finfo = finfo; + } else { + prev_finfo->_next = finfo; + } + prev_finfo = finfo; + finfo = NULL; /* We used this one up, get a new one next iteration */ + } } } fclose(fd); @@ -491,8 +501,10 @@ health_check_origin(TSCont contp ATS_UNUSED, TSEvent event ATS_UNUSED, void *eda const char* path = TSUrlPathGet(reqp, url_loc, &path_len); while (info) { - if (info->p_len == path_len && !memcmp(info->path, path, path_len)) + if (info->p_len == path_len && !memcmp(info->path, path, path_len)) { + TSDebug(PLUGIN_NAME, "Found match for /%.*s", path_len, path); break; + } info = info->_next; }
