From 3d04a9695c0a72e73bfe9aa3114608c899c0e81d Mon Sep 17 00:00:00 2001 From: Eric Chanudet Date: Mon, 3 Apr 2017 17:17:22 -0400 Subject: [PATCH] xcpmd: Check for xenstore_ls return value. xenstore_ls() can fail and return NULL, if Xenstore is not running for example. Check the value and log a warning in this case. Signed-off-by: Eric Chanudet OXT-1012 --- xcpmd/src/battery.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xcpmd/src/battery.c b/xcpmd/src/battery.c index 9370a564..2a1fc989 100644 --- a/xcpmd/src/battery.c +++ b/xcpmd/src/battery.c @@ -346,6 +346,12 @@ static void make_xenstore_battery_dir(unsigned int battery_index) { bool flag; dir_entries = xenstore_ls(&num_entries, "/pm"); + if (!dir_entries) { + xcpmd_log(LOG_WARNING, + "Listing directory /pm failed with error `%s'\n", strerror(errno)); + return; + } + snprintf(xenstore_path, 255, "%s%i", XS_BATTERY_PATH, battery_index); flag = false;