Skip to content

Commit e014f48

Browse files
committed
in_forward: Check return values from mutex functions
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent d4496e6 commit e014f48

File tree

1 file changed

+29
-7
lines changed
  • plugins/in_forward

1 file changed

+29
-7
lines changed

plugins/in_forward/fw.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ static int in_fw_init(struct flb_input_instance *ins,
358358

359359
static void in_fw_pause(void *data, struct flb_config *config)
360360
{
361+
int ret;
361362
struct flb_in_fw_config *ctx = data;
363+
362364
if (config->is_running == FLB_TRUE) {
363365
/*
364366
* This is the case when we are not in a shutdown phase, but
@@ -367,11 +369,20 @@ static void in_fw_pause(void *data, struct flb_config *config)
367369
* and wait for the ingestion to resume.
368370
*/
369371
flb_input_collector_pause(ctx->coll_fd, ctx->ins);
370-
if (pthread_mutex_lock(&ctx->conn_mutex)) {
371-
fw_conn_del_all(ctx);
372-
ctx->is_paused = FLB_TRUE;
372+
373+
ret = pthread_mutex_lock(&ctx->conn_mutex);
374+
if (ret != 0) {
375+
flb_plg_error(ctx->ins, "cannot lock collector mutex");
376+
return;
377+
}
378+
379+
fw_conn_del_all(ctx);
380+
ctx->is_paused = FLB_TRUE;
381+
ret = pthread_mutex_unlock(&ctx->conn_mutex);
382+
if (ret != 0) {
383+
flb_plg_error(ctx->ins, "cannot unlock collector mutex");
384+
return;
373385
}
374-
pthread_mutex_unlock(&ctx->conn_mutex);
375386
}
376387

377388
/*
@@ -388,13 +399,24 @@ static void in_fw_pause(void *data, struct flb_config *config)
388399
}
389400

390401
static void in_fw_resume(void *data, struct flb_config *config) {
402+
int ret;
391403
struct flb_in_fw_config *ctx = data;
404+
392405
if (config->is_running == FLB_TRUE) {
393406
flb_input_collector_resume(ctx->coll_fd, ctx->ins);
394-
if (pthread_mutex_lock(&ctx->conn_mutex)) {
395-
ctx->is_paused = FLB_FALSE;
407+
408+
ret = pthread_mutex_lock(&ctx->conn_mutex);
409+
if (ret != 0) {
410+
flb_plg_error(ctx->ins, "cannot lock collector mutex");
411+
return;
412+
}
413+
414+
ctx->is_paused = FLB_FALSE;
415+
ret = pthread_mutex_unlock(&ctx->conn_mutex);
416+
if (ret != 0) {
417+
flb_plg_error(ctx->ins, "cannot unlock collector mutex");
418+
return;
396419
}
397-
pthread_mutex_unlock(&ctx->conn_mutex);
398420
}
399421
}
400422

0 commit comments

Comments
 (0)