From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chunyan Liu Subject: [PATCH V3 2/6] libxl_read_file_contents: fix reading sysfs file Date: Sun, 19 Apr 2015 11:50:48 +0800 Message-ID: <1429415452-6161-3-git-send-email-cyliu@suse.com> References: <1429415452-6161-1-git-send-email-cyliu@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1429415452-6161-1-git-send-email-cyliu@suse.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: lars.kurth@citrix.com, wei.liu2@citrix.com, ian.campbell@citrix.com, george.dunlap@eu.citrix.com, Chunyan Liu , ian.jackson@citrix.com, caobosimon@gmail.com List-Id: xen-devel@lists.xenproject.org Sysfs file has size=4096 but actual file content is less than that. Current libxl_read_file_contents will treat it as error when file size and actual file content differs, so reading sysfs file content with this function always fails. Fix it so that we can reuse this function to get sysfs file content in later pvusb work. Signed-off-by: Chunyan Liu --- tools/libxl/libxl_utils.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 9053b27..18ad2b8 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -363,12 +363,9 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, if (!data) goto xe; rs = fread(data, 1, datalen, f); - if (rs != datalen) { + if (rs != datalen && !feof(f)) { if (ferror(f)) LOGE(ERROR, "failed to read %s", filename); - else if (feof(f)) - LOG(ERROR, "%s changed size while we were reading it", - filename); else abort(); goto xe; -- 1.8.5.2