From 27902c91064f5900fa0ae8116d3e1d0bcd9477bc Mon Sep 17 00:00:00 2001 From: Vineeth Vijayan Date: Wed, 7 Jun 2023 14:10:56 +0200 Subject: [PATCH] zdev: add proper value input for the ZDEV_SITE_ID key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit udev does not allow an empty value for keys when importing output from an external program. Providing an empty value for any key invokes a warning during the parsing. Currently, ZDEV_SITE_ID for fallback sites are not assigned any value. Add an empty double quotes as the value in case of failover sites. This modification is tested on udevadm version 253 on fedora38. Also verify that the ZDEV_SITE_ID is properly written, if not log the error. Fixes: c8ad5f57d0fc ("zdev: modify zdev_id to read the site_id from loadparm") Reported-by: Alexander Egorenkov Signed-off-by: Vineeth Vijayan Reviewed-by: Peter Oberparleiter Signed-off-by: Jan Höppner --- zdev/src/zdev_id.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/zdev/src/zdev_id.c b/zdev/src/zdev_id.c index c341d31c..9ad99618 100644 --- a/zdev/src/zdev_id.c +++ b/zdev/src/zdev_id.c @@ -213,16 +213,28 @@ out: static void write_zdev_site_id(int site_id) { FILE *fd; + int rc; fd = fopen(ZDEV_SITE_ID_FILE, "w"); if (!fd) - err(1, "Could not write to zdev_site_id file"); - if (site_id == SITE_FALLBACK) - fprintf(fd, "ZDEV_SITE_ID=\n"); - else - fprintf(fd, "ZDEV_SITE_ID=%d\n", site_id); + goto err; - fclose(fd); + if (site_id == SITE_FALLBACK) + rc = fprintf(fd, "ZDEV_SITE_ID=\"\"\n"); + else + rc = fprintf(fd, "ZDEV_SITE_ID=%d\n", site_id); + + if (rc < 0) { + fclose(fd); + goto err; + } + + if (fclose(fd)) + goto err; + + return; +err: + err(1, "Could not write to zdev_site_id file"); } /* Read the loadparm and extract the current site_id. @@ -265,7 +277,7 @@ static void process_loadparm(const char *filename) out: write_zdev_site_id(site_id); if (site_id == SITE_FALLBACK) - printf("ZDEV_SITE_ID=\n"); + printf("ZDEV_SITE_ID=\"\"\n"); else printf("ZDEV_SITE_ID=%d\n", site_id); }