From 560d1e39a57d93ec6e0bee5c67785be414649393 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Dutta <vivek.dutta@iopsys.eu> Date: Mon, 17 Feb 2025 18:23:07 +0530 Subject: [PATCH] Fix run_cmd executions --- src/tools.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tools.c b/src/tools.c index dd0caee..1ed091f 100644 --- a/src/tools.c +++ b/src/tools.c @@ -256,20 +256,24 @@ char *generate_duid(bool sysnchronise, int number) int run_cmd(const char *cmd, char *output, size_t out_len) { int ret = -1; - FILE *pp; // program pointer + FILE *pp = NULL; // program pointer if (cmd == NULL) // null command to run, silently ignore return 0; - // init the buffer - memset(output, 0, out_len); - pp = popen(cmd, "r"); // flawfinder: ignore + if (pp == NULL) { + fprintf(stderr, "Failed to run [%s]", cmd); + return -1; + } if (output == NULL || out_len == 0) { + ret = pclose(pp); return ret; } + // init the buffer + memset(output, 0, out_len); if (pp != NULL) { char line[512] = {0}; -- GitLab