Skip to content

Commit 7300fdb

Browse files
author
tymon.huang
committed
add more return value check on file operations and remind user meaningful message if failed
Signed-off-by: tymon.huang <[email protected]>
1 parent 8b3b734 commit 7300fdb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/util.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,14 @@ save_pid_file(const char *pf)
401401
FILE *f = fopen(pf, "w");
402402
if (f) {
403403
fprintf(f, "%d\n", getpid());
404-
fclose(f);
404+
405+
int ret = fclose(f);
406+
if (ret == EOF) /* check the return value of fclose */
407+
debug(LOG_ERR, "fclose() on file %s was failed (%s)", pf, strerror(errno));
405408
}
409+
410+
/* fopen return NULL, open file failed */
411+
debug(LOG_ERR, "fopen() on flie %s was failed (%s)", pf, strerror(errno));
406412
}
407413

408414
return;

0 commit comments

Comments
 (0)