Lines Matching full:hp
83 static void hook_remove(struct hookproc *hp);
84 static void hook_free(struct hookproc *hp);
148 struct hookproc *hp; in hook_fini() local
153 while ((hp = TAILQ_FIRST(&hookprocs)) != NULL) { in hook_fini()
154 PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); in hook_fini()
155 PJDLOG_ASSERT(hp->hp_pid > 0); in hook_fini()
157 hook_remove(hp); in hook_fini()
158 hook_free(hp); in hook_fini()
170 struct hookproc *hp; in hook_alloc() local
173 hp = malloc(sizeof(*hp)); in hook_alloc()
174 if (hp == NULL) { in hook_alloc()
176 sizeof(*hp)); in hook_alloc()
180 hp->hp_pid = 0; in hook_alloc()
181 hp->hp_birthtime = hp->hp_lastreport = time(NULL); in hook_alloc()
182 (void)strlcpy(hp->hp_comm, path, sizeof(hp->hp_comm)); in hook_alloc()
185 (void)snprlcat(hp->hp_comm, sizeof(hp->hp_comm), " %s", in hook_alloc()
188 if (strlen(hp->hp_comm) >= sizeof(hp->hp_comm) - 1) { in hook_alloc()
190 free(hp); in hook_alloc()
193 hp->hp_magic = HOOKPROC_MAGIC_ALLOCATED; in hook_alloc()
194 return (hp); in hook_alloc()
198 hook_add(struct hookproc *hp, pid_t pid) in hook_add() argument
201 PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ALLOCATED); in hook_add()
202 PJDLOG_ASSERT(hp->hp_pid == 0); in hook_add()
204 hp->hp_pid = pid; in hook_add()
206 hp->hp_magic = HOOKPROC_MAGIC_ONLIST; in hook_add()
207 TAILQ_INSERT_TAIL(&hookprocs, hp, hp_next); in hook_add()
212 hook_remove(struct hookproc *hp) in hook_remove() argument
215 PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); in hook_remove()
216 PJDLOG_ASSERT(hp->hp_pid > 0); in hook_remove()
219 TAILQ_REMOVE(&hookprocs, hp, hp_next); in hook_remove()
220 hp->hp_magic = HOOKPROC_MAGIC_ALLOCATED; in hook_remove()
224 hook_free(struct hookproc *hp) in hook_free() argument
227 PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ALLOCATED); in hook_free()
228 PJDLOG_ASSERT(hp->hp_pid > 0); in hook_free()
230 hp->hp_magic = 0; in hook_free()
231 free(hp); in hook_free()
237 struct hookproc *hp; in hook_find() local
241 TAILQ_FOREACH(hp, &hookprocs, hp_next) { in hook_find()
242 PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); in hook_find()
243 PJDLOG_ASSERT(hp->hp_pid > 0); in hook_find()
245 if (hp->hp_pid == pid) in hook_find()
249 return (hp); in hook_find()
255 struct hookproc *hp; in hook_check_one() local
258 hp = hook_find(pid); in hook_check_one()
259 if (hp == NULL) { in hook_check_one()
264 hook_remove(hp); in hook_check_one()
268 pid, hp->hp_comm); in hook_check_one()
271 pid, WTERMSIG(status), hp->hp_comm); in hook_check_one()
275 hp->hp_comm); in hook_check_one()
277 hook_free(hp); in hook_check_one()
283 struct hookproc *hp, *hp2; in hook_check() local
295 TAILQ_FOREACH_SAFE(hp, &hookprocs, hp_next, hp2) { in hook_check()
296 PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); in hook_check()
297 PJDLOG_ASSERT(hp->hp_pid > 0); in hook_check()
303 if (kill(hp->hp_pid, 0) == -1 && errno == ESRCH) { in hook_check()
305 hp->hp_pid, hp->hp_comm); in hook_check()
306 hook_remove(hp); in hook_check()
307 hook_free(hp); in hook_check()
314 if (now - hp->hp_lastreport < REPORT_INTERVAL) in hook_check()
321 (uintmax_t)(now - hp->hp_birthtime), hp->hp_pid, in hook_check()
322 hp->hp_comm); in hook_check()
323 hp->hp_lastreport = now; in hook_check()
341 struct hookproc *hp; in hook_execv() local
361 hp = hook_alloc(path, args); in hook_execv()
362 if (hp == NULL) in hook_execv()
365 pjdlog_debug(1, "Executing hook: %s", hp->hp_comm); in hook_execv()
371 hook_free(hp); in hook_execv()
386 hook_add(hp, pid); in hook_execv()