Permalink
Browse files

log more specific error in case of stream failure

git-svn-id: http://monit.googlecode.com/svn/trunk@213 808b68a2-07de-11de-a1f0-819f45317607
  • Loading branch information...
martin2812
martin2812 committed Jul 29, 2010
1 parent 34d0d88 commit 9470ce7f5ed695cf6d98452039a94b364a486ec2
Showing with 18 additions and 12 deletions.
  1. +10 −9 md5.c
  2. +8 −3 util.c
View
19 md5.c
@@ -162,15 +162,16 @@ md5_stream (stream, resblock)
sum += n;
}
while (sum < BLOCKSIZE && n != 0);
- if (n == 0 && ferror (stream))
- return 1;
-
- /* If end of file is reached, end the loop. */
- if (n == 0)
- break;
-
- /* Process buffer with BLOCKSIZE bytes. Note that
- BLOCKSIZE % 64 == 0
+ if (n == 0) {
+ int error = ferror(stream);
+ if (error) {
+ LogError("md5_stream: stream error -- sum=%d, error=0x%x\n", sum, error);
+ return error;
+ } else
+ break; /* If end of file is reached, end the loop. */
+ }
+
+ /* Process buffer with BLOCKSIZE bytes. Note that BLOCKSIZE % 64 == 0
*/
md5_process_block (buffer, BLOCKSIZE, &ctx);
}
View
11 util.c
@@ -1440,6 +1440,7 @@ int Util_getChecksum(char *file, int hashtype, char *buf, int bufsize) {
hashlength = 20;
break;
default:
+ LogError("checksum: invalid hash type: 0x%x\n", hashtype);
return FALSE;
}
@@ -1462,14 +1463,18 @@ int Util_getChecksum(char *file, int hashtype, char *buf, int bufsize) {
}
fclose(f);
- if (fresult)
+ if (fresult) {
+ LogError("checksum: file %s stream error (0x%x)\n", file, fresult);
return FALSE;
+ }
Util_digest2Bytes(sum, hashlength, buf);
return TRUE;
- }
- }
+ } else
+ LogError("checksum: failed to open file %s -- %s\n", file, STRERROR);
+ } else
+ LogError("checksum: file %s is not regular file\n", file);
return FALSE;
}

0 comments on commit 9470ce7

Please sign in to comment.