summaryrefslogtreecommitdiff
path: root/usr/src/lib/libproc/common/Pcontrol.c
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@fingolfin.org>2021-07-31 12:39:35 -0700
committerRobert Mustacchi <rm@fingolfin.org>2021-08-17 09:03:20 -0700
commit50d4d24e9f62b588d2123e06f654ecb230e4857c (patch)
treee4b9ce4fd49312a421b2657193e33564719fec2f /usr/src/lib/libproc/common/Pcontrol.c
parentf0089e391b2bc4be2755f1a1b51fb4cd9b8f3988 (diff)
downloadillumos-gate-50d4d24e9f62b588d2123e06f654ecb230e4857c.tar.gz
13987 libproc could use standard lists
Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Patrick Mooney <pmooney@pfmooney.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/libproc/common/Pcontrol.c')
-rw-r--r--usr/src/lib/libproc/common/Pcontrol.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/usr/src/lib/libproc/common/Pcontrol.c b/usr/src/lib/libproc/common/Pcontrol.c
index d9e3c8b9ea..d6ea26c9ed 100644
--- a/usr/src/lib/libproc/common/Pcontrol.c
+++ b/usr/src/lib/libproc/common/Pcontrol.c
@@ -28,6 +28,7 @@
* Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright 2015, Joyent, Inc.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
+ * Copyright 2021 Oxide Computer Company
*/
#include <assert.h>
@@ -501,6 +502,7 @@ Pxcreate(const char *file, /* executable file name */
P->agentstatfd = -1;
Pinit_ops(&P->ops, &P_live_ops);
Pinitsym(P);
+ Pinitfd(P);
/*
* Open the /proc/pid files.
@@ -804,6 +806,7 @@ again: /* Come back here if we lose it in the Window of Vulnerability */
P->agentstatfd = -1;
Pinit_ops(&P->ops, &P_live_ops);
Pinitsym(P);
+ Pinitfd(P);
/*
* Open the /proc/pid files
@@ -1182,6 +1185,7 @@ void
Pfree(struct ps_prochandle *P)
{
uint_t i;
+ fd_info_t *fip;
if (P->ucaddrs != NULL) {
free(P->ucaddrs);
@@ -1199,12 +1203,9 @@ Pfree(struct ps_prochandle *P)
free(P->hashtab);
}
- while (P->num_fd > 0) {
- fd_info_t *fip = list_next(&P->fd_head);
- list_unlink(fip);
+ while ((fip = list_remove_head(&P->fd_head)) != NULL) {
proc_fdinfo_free(fip->fd_info);
free(fip);
- P->num_fd--;
}
(void) mutex_unlock(&P->proc_lock);
(void) mutex_destroy(&P->proc_lock);
@@ -1673,7 +1674,7 @@ Prelease(struct ps_prochandle *P, int flags)
}
if (P->state == PS_IDLE) {
- file_info_t *fptr = list_next(&P->file_head);
+ file_info_t *fptr = list_head(&P->file_head);
dprintf("Prelease: releasing handle %p PS_IDLE of file %s\n",
(void *)P, fptr->file_pname);
Pfree(P);
@@ -2964,10 +2965,10 @@ Plwp_iter(struct ps_prochandle *P, proc_lwp_f *func, void *cd)
*/
if (P->state == PS_DEAD) {
core_info_t *core = P->data;
- lwp_info_t *lwp = list_prev(&core->core_lwp_head);
- uint_t i;
+ lwp_info_t *lwp;
- for (i = 0; i < core->core_nlwp; i++, lwp = list_prev(lwp)) {
+ for (lwp = list_tail(&core->core_lwp_head); lwp != NULL;
+ lwp = list_prev(&core->core_lwp_head, lwp)) {
if (lwp->lwp_psinfo.pr_sname != 'Z' &&
(rv = func(cd, &lwp->lwp_status)) != 0)
break;
@@ -3036,10 +3037,10 @@ retry:
*/
if (P->state == PS_DEAD) {
core_info_t *core = P->data;
- lwp_info_t *lwp = list_prev(&core->core_lwp_head);
- uint_t i;
+ lwp_info_t *lwp;
- for (i = 0; i < core->core_nlwp; i++, lwp = list_prev(lwp)) {
+ for (lwp = list_tail(&core->core_lwp_head); lwp != NULL;
+ lwp = list_prev(&core->core_lwp_head, lwp)) {
sp = (lwp->lwp_psinfo.pr_sname == 'Z')? NULL :
&lwp->lwp_status;
if ((rv = func(cd, sp, &lwp->lwp_psinfo)) != 0)
@@ -3949,6 +3950,7 @@ Pgrab_ops(pid_t pid, void *data, const ps_ops_t *ops, int flags)
P->agentctlfd = -1;
P->agentstatfd = -1;
Pinitsym(P);
+ Pinitfd(P);
P->data = data;
Pread_status(P);