- checksum_file-clear-errno.diff: Avoid stale errno to be picked up and report an error without any error actually occuring. (This lead to occasional build fails on armv7 on Ubuntu 20.04 and Fedora 32/33, nowhere else.) OBS-URL: https://build.opensuse.org/request/show/878068 OBS-URL: https://build.opensuse.org/package/show/Base:System/dd_rescue?expand=0&rev=58
50 lines
1.6 KiB
Diff
50 lines
1.6 KiB
Diff
commit 91461f37813dfce13c4a30e9c7a252c1e4267b28
|
|
Author: Kurt Garloff <kurt@garloff.de>
|
|
Date: Tue Mar 9 12:31:45 2021 +0100
|
|
|
|
Avoid reporting spurious errors.
|
|
|
|
errno could have stale values which we don't want to
|
|
report by mistake.
|
|
|
|
For mysterious reasons, this caused an issue on armv7 on Fedora 32/33
|
|
and xUbuntu 20.04, but not anywhere else. Maybe glibc is lazy there
|
|
to initialize errno properly?
|
|
|
|
Signed-off-by: Kurt Garloff <kurt@garloff.de>
|
|
|
|
diff --git a/checksum_file.c b/checksum_file.c
|
|
index 61e2482..41bae1a 100644
|
|
--- a/checksum_file.c
|
|
+++ b/checksum_file.c
|
|
@@ -130,6 +130,7 @@ int get_chks(const char* cnm, const char* nm, char* chks, int wantedln)
|
|
/* update chksum */
|
|
int upd_chks(const char* cnm, const char *nm, const char *chks, int acc)
|
|
{
|
|
+ errno = 0;
|
|
FILE *f = fopen_chks(cnm, "r+", 0);
|
|
int err = 0;
|
|
char oldchks[MAXHASHSLN+2];
|
|
@@ -139,15 +140,17 @@ int upd_chks(const char* cnm, const char *nm, const char *chks, int acc)
|
|
f = fopen_chks(cnm, "w", acc);
|
|
if (!f)
|
|
return -errno;
|
|
- fprintf(f, "%s *%s\n", chks, bnm);
|
|
- err = -errno;
|
|
+ if (fprintf(f, "%s *%s\n", chks, bnm) <= 0)
|
|
+ err = -errno;
|
|
} else {
|
|
off_t pos = find_chks(f, nm, oldchks, strlen(chks));
|
|
if (pos == -ENOENT || strlen(chks) != strlen(oldchks)) {
|
|
fclose(f);
|
|
f = fopen_chks(cnm, "a", 0);
|
|
- fprintf(f, "%s *%s\n", chks, bnm);
|
|
- err = -errno;
|
|
+ if (!f)
|
|
+ return -errno;
|
|
+ if (fprintf(f, "%s *%s\n", chks, bnm) <= 0)
|
|
+ err = -errno;
|
|
} else {
|
|
if (strcmp(chks, oldchks)) {
|
|
if (pwrite(fileno(f), chks, strlen(chks), pos) <= 0)
|