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 <ncopa@alpinelinux.org>
This commit is contained in:
Natanael Copa 2012-11-08 15:51:00 +00:00 committed by William Hubbs
parent 56f1752ce1
commit e4668a5061

View File

@ -168,7 +168,7 @@ file_regex(const char *file, const char *regex)
char *line = NULL; char *line = NULL;
size_t len = 0; size_t len = 0;
regex_t re; regex_t re;
bool retval = false; bool retval = true;
int result; int result;
if (!(fp = fopen(file, "r"))) if (!(fp = fopen(file, "r")))
@ -184,11 +184,21 @@ file_regex(const char *file, const char *regex)
} }
while ((rc_getline(&line, &len, fp))) { while ((rc_getline(&line, &len, fp))) {
if (regexec(&re, line, 0, NULL, 0) == 0) char *str = line;
retval = true; /* some /proc files have \0 separated content so we have to
if (retval) loop through the 'line' */
break; 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); fclose(fp);
free(line); free(line);
regfree(&re); regfree(&re);