From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id F41221381F3 for ; Sun, 14 Apr 2013 03:45:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 55B44E0905; Sun, 14 Apr 2013 03:45:30 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B5E77E0905 for ; Sun, 14 Apr 2013 03:45:29 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B0E0833E008 for ; Sun, 14 Apr 2013 03:45:28 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id BA95DE4073 for ; Sun, 14 Apr 2013 03:45:26 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1365492326.e4668a5061de4f225d4e9d534ff6212e634e45d2.WilliamH@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/librc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/librc/librc.c X-VCS-Directories: src/librc/ X-VCS-Committer: WilliamH X-VCS-Committer-Name: William Hubbs X-VCS-Revision: e4668a5061de4f225d4e9d534ff6212e634e45d2 X-VCS-Branch: master Date: Sun, 14 Apr 2013 03:45:26 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 3a6d8765-ca08-4a64-a40c-608c9abdb627 X-Archives-Hash: 12c978f2c5b3bcaed2ac802debb36631 commit: e4668a5061de4f225d4e9d534ff6212e634e45d2 Author: Natanael Copa gmail com> AuthorDate: Thu Nov 8 15:51:00 2012 +0000 Commit: William Hubbs gentoo org> CommitDate: Tue Apr 9 07:25:26 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=e4668a50 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 alpinelinux.org> --- src/librc/librc.c | 20 +++++++++++++++----- 1 files 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);