diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2016-09-12 15:03:58 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2016-10-30 19:46:49 -0400 |
commit | 5cfe15f00db02dd55f76d8f578eac20422fe2238 (patch) | |
tree | 23adbaf943151e38a553c07173715525754a95ea | |
parent | b72211fb30f605f7cc54ee066953fca8a4d7463e (diff) | |
download | trace-cmd-5cfe15f00db02dd55f76d8f578eac20422fe2238.tar.gz |
trace-cmd listen: Simplify adding of client_pids
Now that we leave holes in the client_pids array, we can remove the complex
logic around allocating client_pids in blocks. Just use realloc each time,
as it only grows the array, and we never shrink it.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-listen.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/trace-listen.c b/trace-listen.c index ee8639fc..1890b6df 100644 --- a/trace-listen.c +++ b/trace-listen.c @@ -742,8 +742,6 @@ static int do_connection(int cfd, struct sockaddr_storage *peer_addr, static int *client_pids; static int free_pids; static int saved_pids; -static int size_pids; -#define PIDS_BLOCK 32 static void add_process(int pid) { @@ -762,18 +760,10 @@ static void add_process(int pid) warning("Could not find free pid"); } if (!client) { - if (!client_pids) { - size_pids = PIDS_BLOCK; - client_pids = malloc(sizeof(*client_pids) * size_pids); - if (!client_pids) - pdie("allocating pids"); - } else if (!(saved_pids % PIDS_BLOCK)) { - size_pids += PIDS_BLOCK; - client_pids = realloc(client_pids, - sizeof(*client_pids) * size_pids); - if (!client_pids) - pdie("realloc of pids"); - } + client_pids = realloc(client_pids, + sizeof(*client_pids) * (saved_pids + 1)); + if (!client_pids) + pdie("allocating pids"); client = &client_pids[saved_pids++]; } *client = pid; |