From e4668a5061de4f225d4e9d534ff6212e634e45d2 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 8 Nov 2012 15:51:00 +0000 Subject: Fix autodetection of lxc The /proc/1/environ contains various \0 terminated strings. The current code will only work when the search string is in the first of those. To fix this we look for strings in entire buffer. Signed-off-by: Natanael Copa --- src/librc/librc.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/librc/librc.c b/src/librc/librc.c index d82880f..40b975a 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -168,7 +168,7 @@ file_regex(const char *file, const char *regex) char *line = NULL; size_t len = 0; regex_t re; - bool retval = false; + bool retval = true; int result; if (!(fp = fopen(file, "r"))) @@ -184,11 +184,21 @@ file_regex(const char *file, const char *regex) } while ((rc_getline(&line, &len, fp))) { - if (regexec(&re, line, 0, NULL, 0) == 0) - retval = true; - if (retval) - break; + char *str = line; + /* some /proc files have \0 separated content so we have to + loop through the 'line' */ + do { + if (regexec(&re, str, 0, NULL, 0) == 0) + goto found; + str += strlen(str) + 1; + /* len is the size of allocated buffer and we don't + want call regexec BUFSIZE times. find next str */ + while (*str == '\0' && str < line + len) + str++; + } while (str < line + len); } + retval = false; +found: fclose(fp); free(line); regfree(&re); -- cgit v1.2.3