aboutsummaryrefslogtreecommitdiffstats
path: root/trace-hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'trace-hash.c')
-rw-r--r--trace-hash.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/trace-hash.c b/trace-hash.c
index 1197913..ed53ee1 100644
--- a/trace-hash.c
+++ b/trace-hash.c
@@ -19,6 +19,7 @@
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 */ 20 */
21#include <stdio.h> 21#include <stdio.h>
22#include <stdlib.h>
22#include <string.h> 23#include <string.h>
23#include <stdarg.h> 24#include <stdarg.h>
24 25
@@ -155,3 +156,65 @@ struct filter_task *filter_task_hash_copy(struct filter_task *hash)
155 156
156 return new_hash; 157 return new_hash;
157} 158}
159
160int *filter_task_pids(struct filter_task *hash)
161{
162 struct filter_task_item *task;
163 int *pids;
164 int count = 0;
165 int i;
166
167 if (!hash->count)
168 return NULL;
169
170 pids = malloc(sizeof(*pids) * (hash->count + 1));
171 if (!pids)
172 return NULL;
173
174 for (i = 0; i < FILTER_TASK_HASH_SIZE; i++) {
175 task = hash->hash[i];
176 while (task) {
177 pids[count++] = task->pid;
178 task = task->next;
179 }
180 }
181 pids[count] = -1;
182
183 return pids;
184}
185
186/**
187 * filter_task_compare - compare two task hashs to see if they are equal
188 * @hash1: one hash to compare
189 * @hash2: another hash to compare to @hash1
190 *
191 * Returns 1 if the two hashes are the same, 0 otherwise.
192 */
193int filter_task_compare(struct filter_task *hash1, struct filter_task *hash2)
194{
195 int *pids;
196 int ret = 0;
197 int i;
198
199 /* If counts don't match, then they obviously are not the same */
200 if (hash1->count != hash2->count)
201 return 0;
202
203 /* If both hashes are empty, they are the same */
204 if (!hash1->count && !hash2->count)
205 return 1;
206
207 /* Now compare the pids of one hash with the other */
208 pids = filter_task_pids(hash1);
209 for (i = 0; pids[i] >= 0; i++) {
210 if (!filter_task_find_pid(hash2, pids[i]))
211 break;
212 }
213
214 if (pids[i] == -1)
215 ret = 1;
216
217 free(pids);
218
219 return ret;
220}