Verified Commit dc0d9766 authored by Karel Koci's avatar Karel Koci 🤘

Fix cppcheck warnings and that way tests

All warning in events are just suppressed because we are planning on
dropping events.c anyway.
parent 155c2ff0
......@@ -423,6 +423,7 @@ static void command_check_complete(struct watched_command *command) {
}
static void command_terminated_callback(struct wait_id id, void *data, pid_t pid, int status) {
// cppcheck-suppress shadowVar ;; (just ignore)
struct watched_command *command = data;
ASSERT(command->pid == pid);
ASSERT(memcmp(&command->child, &id, sizeof id) == 0);
......@@ -449,6 +450,7 @@ static void command_event(struct bufferevent *buffer, short events __attribute__
* Therefore, find which buffer it is, extract its content (if it
* is output of the command) and close it.
*/
// cppcheck-suppress shadowVar ;; (just ignore)
struct watched_command *command = data;
struct bufferevent **buffer_var = NULL;
char **result = NULL;
......@@ -474,6 +476,7 @@ static void command_event(struct bufferevent *buffer, short events __attribute__
ASSERT(*result_size == bufferevent_read(buffer, *result, *result_size));
}
bufferevent_free(buffer);
// cppcheck-suppress nullPointer ;; (Probably caused by else branch that results in to program termination so we always should have valid pointer)
*buffer_var = NULL;
if (result)
// Is this the last one?
......@@ -482,6 +485,7 @@ static void command_event(struct bufferevent *buffer, short events __attribute__
static void command_write(struct bufferevent *buffer, void *data) {
// Everything is written. Free the bufferevent & close the socket.
// cppcheck-suppress shadowVar ;; (just ignore)
struct watched_command *command = data;
ASSERT(command->input_buffer == buffer);
bufferevent_free(buffer);
......@@ -513,6 +517,7 @@ static struct wait_id register_command(struct events *events, command_callback_t
nonblock(out_pipe[0]);
ASSERT_MSG(fcntl(err_pipe[0], F_SETFD, (long)FD_CLOEXEC) != -1, "Failed to set close on exec on commands stderr pipe: %s", strerror(errno));
nonblock(err_pipe[0]);
// cppcheck-suppress shadowVar ;; (just ignore)
struct watched_command *command = malloc(sizeof *command);
*command = (struct watched_command) {
.events = events,
......@@ -963,6 +968,7 @@ void events_wait(struct events *events, size_t nid, struct wait_id *ids) {
break;
}
case WT_COMMAND: {
// cppcheck-suppress shadowVar ;; (just ignore)
struct watched_command *command = command_lookup(events, id.pointers.command, id.pid);
ASSERT(command);
enum command_kill_status ks;
......
......@@ -303,7 +303,7 @@ static int lua_run_generic(lua_State *L, bool utils) {
return luaL_error(L, "The 3rd argument of run_command is a string input or nil");
int term_timeout = luaL_checkinteger(L, 4);
int kill_timeout = luaL_checkinteger(L, 5);
const char *command = luaL_checkstring(L, 6);
const char *cmd = luaL_checkstring(L, 6);
struct log_buffer log;
log_buffer_init(&log, LL_DBG);
// The rest of the args are args for the command ‒ get them into an array
......@@ -318,9 +318,9 @@ static int lua_run_generic(lua_State *L, bool utils) {
if (log.f) {
fclose(log.f);
if (utils) {
DBG("Util command: %s %s", command, log.char_buffer);
DBG("Util command: %s %s", cmd, log.char_buffer);
} else
DBG("Command: %s %s", command, log.char_buffer);
DBG("Command: %s %s", cmd, log.char_buffer);
free(log.char_buffer);
}
// Data for the callbacks. It will get freed there.
......@@ -336,9 +336,9 @@ static int lua_run_generic(lua_State *L, bool utils) {
input = lua_tolstring(L, 3, &input_size);
struct wait_id id;
if (utils)
id = run_util_a(events, command_terminated, command_postfork, data, input_size, input, term_timeout, kill_timeout, command, args);
id = run_util_a(events, command_terminated, command_postfork, data, input_size, input, term_timeout, kill_timeout, cmd, args);
else
id = run_command_a(events, command_terminated, command_postfork, data, input_size, input, term_timeout, kill_timeout, command, args);
id = run_command_a(events, command_terminated, command_postfork, data, input_size, input, term_timeout, kill_timeout, cmd, args);
push_wid(L, &id);
// Return 1 value ‒ the wait_id
return 1;
......@@ -488,7 +488,7 @@ static int lua_subprocess(lua_State *L) {
callback_data.callback = register_value(L, 4);
cmd_index++;
}
const char *command = luaL_checkstring(L, cmd_index);
const char *cmd = luaL_checkstring(L, cmd_index);
const char *args[lua_gettop(L) - cmd_index - 1];
for (int i = cmd_index + 1; i <= lua_gettop(L); i++) {
args[i - cmd_index - 1] = luaL_checkstring(L, i);
......@@ -496,7 +496,7 @@ static int lua_subprocess(lua_State *L) {
args[lua_gettop(L) - cmd_index] = NULL;
char *output;
int ec = lsubproclc(type, message, &output, timeout, subprocess_callback, &callback_data, command, args);
int ec = lsubproclc(type, message, &output, timeout, subprocess_callback, &callback_data, cmd, args);
// Free callback data callback name
if (callback_data.callback)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment