]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: close adjtime on write error [coverity scan]
authorKarel Zak <kzak@redhat.com>
Fri, 11 Jun 2021 13:17:42 +0000 (15:17 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 11 Jun 2021 13:17:42 +0000 (15:17 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/hwclock.c

index 6b4e8ce5b0737d9003f54557d68d0b0226d3b750..e9102e33a7e84e7136a4aec6f7f1fc0c2f21b72b 100644 (file)
@@ -901,13 +901,18 @@ static int save_adjtime(const struct hwclock_control *ctl,
        }
 
        if (!ctl->testing) {
+               int rc;
+
                fp = fopen(ctl->adj_file_name, "w");
                if (fp == NULL) {
                        warn(_("cannot open %s"), ctl->adj_file_name);
                        return EXIT_FAILURE;
                }
 
-               if (fputs(content, fp) < 0 || close_stream(fp) != 0) {
+               rc = fputs(content, fp) < 0;
+               rc += close_stream(fp);
+
+               if (rc) {
                        warn(_("cannot update %s"), ctl->adj_file_name);
                        return EXIT_FAILURE;
                }