From 9550cf25ff45ab012cdb9a48be82a04d1ea710b1 Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Tue, 29 Mar 2016 17:33:48 +0300 Subject: [PATCH] LU-7936 utils: fix resource lost Close file handle before return from function. Change-Id: I1cea4c1d60672b945cd524367e91fb27df185c87 Signed-off-by: Dmitry Eremin Reviewed-on: http://review.whamcloud.com/19193 Tested-by: Jenkins Reviewed-by: Bob Glossman Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/utils/liblustreapi_hsm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lustre/utils/liblustreapi_hsm.c b/lustre/utils/liblustreapi_hsm.c index d95383a..95ac6da 100644 --- a/lustre/utils/liblustreapi_hsm.c +++ b/lustre/utils/liblustreapi_hsm.c @@ -472,6 +472,7 @@ out_free: */ int llapi_hsm_register_event_fifo(const char *path) { + int rc; int read_fd; struct stat statbuf; @@ -508,17 +509,19 @@ int llapi_hsm_register_event_fifo(const char *path) /* Open the FIFO for writes, but don't block on waiting * for a reader. */ llapi_hsm_event_fd = open(path, O_WRONLY | O_NONBLOCK); - if (llapi_hsm_event_fd < 0) { - llapi_error(LLAPI_MSG_ERROR, errno, - "cannot open(%s) for write", path); - return -errno; - } + rc = -errno; /* Now close the reader. An external monitoring process can * now open the FIFO for reads. If no reader comes along the * events are lost. NOTE: Only one reader at a time! */ close(read_fd); + if (llapi_hsm_event_fd < 0) { + llapi_error(LLAPI_MSG_ERROR, -rc, + "cannot open(%s) for write", path); + return rc; + } + /* Ignore SIGPIPEs -- can occur if the reader goes away. */ signal(SIGPIPE, SIG_IGN); -- 1.8.3.1