Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_descrip.c
Show First 20 Lines • Show All 4,284 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
export_kinfo_to_sb(struct export_fd_buf *efbuf) | export_kinfo_to_sb(struct export_fd_buf *efbuf) | ||||
{ | { | ||||
struct kinfo_file *kif; | struct kinfo_file *kif; | ||||
kif = &efbuf->kif; | kif = &efbuf->kif; | ||||
if (efbuf->remainder != -1) { | if (efbuf->remainder != -1) { | ||||
if (efbuf->remainder < kif->kf_structsize) { | if (efbuf->remainder < kif->kf_structsize) | ||||
/* Terminate export. */ | return (ENOMEM); | ||||
efbuf->remainder = 0; | |||||
return (0); | |||||
} | |||||
efbuf->remainder -= kif->kf_structsize; | efbuf->remainder -= kif->kf_structsize; | ||||
} | } | ||||
return (sbuf_bcat(efbuf->sb, kif, kif->kf_structsize) == 0 ? 0 : ENOMEM); | if (sbuf_bcat(efbuf->sb, kif, kif->kf_structsize) != 0) | ||||
return (sbuf_error(efbuf->sb)); | |||||
return (0); | |||||
} | } | ||||
cem: Is the ordering of sbuf_bcat() -> sbuf_error() well-defined as used here? Or should this be an… | |||||
Not Done Inline ActionsThe "?" operator is a sequence point, i.e., the first expression must be evaluated before the ones following "?". markj: The "?" operator is a sequence point, i.e., the first expression must be evaluated before the… | |||||
Done Inline ActionsI think I'd still prefer if/else for clarity. It doesn't fit in a single line anymore anyways. cem: I think I'd still prefer if/else for clarity. It doesn't fit in a single line anymore anyways. | |||||
Not Done Inline ActionsOk. It didn't fit before either (> 80 cols). markj: Ok. It didn't fit before either (> 80 cols). | |||||
Not Done Inline ActionsHeh, oops :-) cem: Heh, oops :-) | |||||
static int | static int | ||||
export_file_to_sb(struct file *fp, int fd, cap_rights_t *rightsp, | export_file_to_sb(struct file *fp, int fd, cap_rights_t *rightsp, | ||||
struct export_fd_buf *efbuf) | struct export_fd_buf *efbuf) | ||||
{ | { | ||||
int error; | int error; | ||||
if (efbuf->remainder == 0) | if (efbuf->remainder == 0) | ||||
return (0); | return (ENOMEM); | ||||
export_file_to_kinfo(fp, fd, rightsp, &efbuf->kif, efbuf->fdp, | export_file_to_kinfo(fp, fd, rightsp, &efbuf->kif, efbuf->fdp, | ||||
efbuf->flags); | efbuf->flags); | ||||
FILEDESC_SUNLOCK(efbuf->fdp); | FILEDESC_SUNLOCK(efbuf->fdp); | ||||
error = export_kinfo_to_sb(efbuf); | error = export_kinfo_to_sb(efbuf); | ||||
FILEDESC_SLOCK(efbuf->fdp); | FILEDESC_SLOCK(efbuf->fdp); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
export_vnode_to_sb(struct vnode *vp, int fd, int fflags, | export_vnode_to_sb(struct vnode *vp, int fd, int fflags, | ||||
struct export_fd_buf *efbuf) | struct export_fd_buf *efbuf) | ||||
{ | { | ||||
int error; | int error; | ||||
if (efbuf->remainder == 0) | if (efbuf->remainder == 0) | ||||
return (0); | return (ENOMEM); | ||||
if (efbuf->pdp != NULL) | if (efbuf->pdp != NULL) | ||||
PWDDESC_XUNLOCK(efbuf->pdp); | PWDDESC_XUNLOCK(efbuf->pdp); | ||||
export_vnode_to_kinfo(vp, fd, fflags, &efbuf->kif, efbuf->flags); | export_vnode_to_kinfo(vp, fd, fflags, &efbuf->kif, efbuf->flags); | ||||
error = export_kinfo_to_sb(efbuf); | error = export_kinfo_to_sb(efbuf); | ||||
if (efbuf->pdp != NULL) | if (efbuf->pdp != NULL) | ||||
PWDDESC_XLOCK(efbuf->pdp); | PWDDESC_XLOCK(efbuf->pdp); | ||||
return (error); | return (error); | ||||
} | } | ||||
Show All 29 Lines | kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, | ||||
if (p->p_pgrp != NULL && p->p_pgrp->pg_session != NULL) { | if (p->p_pgrp != NULL && p->p_pgrp->pg_session != NULL) { | ||||
cttyvp = p->p_pgrp->pg_session->s_ttyvp; | cttyvp = p->p_pgrp->pg_session->s_ttyvp; | ||||
if (cttyvp != NULL) | if (cttyvp != NULL) | ||||
vrefact(cttyvp); | vrefact(cttyvp); | ||||
} | } | ||||
fdp = fdhold(p); | fdp = fdhold(p); | ||||
pdp = pdhold(p); | pdp = pdhold(p); | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
efbuf = malloc(sizeof(*efbuf), M_TEMP, M_WAITOK); | efbuf = malloc(sizeof(*efbuf), M_TEMP, M_WAITOK); | ||||
efbuf->fdp = NULL; | efbuf->fdp = NULL; | ||||
efbuf->pdp = NULL; | efbuf->pdp = NULL; | ||||
efbuf->sb = sb; | efbuf->sb = sb; | ||||
efbuf->remainder = maxlen; | efbuf->remainder = maxlen; | ||||
efbuf->flags = flags; | efbuf->flags = flags; | ||||
error = 0; | |||||
if (tracevp != NULL) | if (tracevp != NULL) | ||||
export_vnode_to_sb(tracevp, KF_FD_TYPE_TRACE, FREAD | FWRITE, | error = export_vnode_to_sb(tracevp, KF_FD_TYPE_TRACE, | ||||
FREAD | FWRITE, efbuf); | |||||
if (error == 0 && textvp != NULL) | |||||
error = export_vnode_to_sb(textvp, KF_FD_TYPE_TEXT, FREAD, | |||||
efbuf); | efbuf); | ||||
if (textvp != NULL) | if (error == 0 && cttyvp != NULL) | ||||
export_vnode_to_sb(textvp, KF_FD_TYPE_TEXT, FREAD, efbuf); | error = export_vnode_to_sb(cttyvp, KF_FD_TYPE_CTTY, | ||||
if (cttyvp != NULL) | FREAD | FWRITE, efbuf); | ||||
export_vnode_to_sb(cttyvp, KF_FD_TYPE_CTTY, FREAD | FWRITE, | if (error != 0 || pdp == NULL || fdp == NULL) | ||||
efbuf); | |||||
error = 0; | |||||
if (pdp == NULL || fdp == NULL) | |||||
goto fail; | goto fail; | ||||
efbuf->fdp = fdp; | efbuf->fdp = fdp; | ||||
efbuf->pdp = pdp; | efbuf->pdp = pdp; | ||||
PWDDESC_XLOCK(pdp); | PWDDESC_XLOCK(pdp); | ||||
pwd = pwd_hold_pwddesc(pdp); | pwd = pwd_hold_pwddesc(pdp); | ||||
if (pwd != NULL) { | if (pwd != NULL) { | ||||
/* working directory */ | /* working directory */ | ||||
if (pwd->pwd_cdir != NULL) { | if (pwd->pwd_cdir != NULL) { | ||||
vrefact(pwd->pwd_cdir); | vrefact(pwd->pwd_cdir); | ||||
export_vnode_to_sb(pwd->pwd_cdir, KF_FD_TYPE_CWD, | error = export_vnode_to_sb(pwd->pwd_cdir, | ||||
FREAD, efbuf); | KF_FD_TYPE_CWD, FREAD, efbuf); | ||||
} | } | ||||
/* root directory */ | /* root directory */ | ||||
if (pwd->pwd_rdir != NULL) { | if (error == 0 && pwd->pwd_rdir != NULL) { | ||||
vrefact(pwd->pwd_rdir); | vrefact(pwd->pwd_rdir); | ||||
export_vnode_to_sb(pwd->pwd_rdir, KF_FD_TYPE_ROOT, | error = export_vnode_to_sb(pwd->pwd_rdir, | ||||
FREAD, efbuf); | KF_FD_TYPE_ROOT, FREAD, efbuf); | ||||
} | } | ||||
/* jail directory */ | /* jail directory */ | ||||
if (pwd->pwd_jdir != NULL) { | if (error == 0 && pwd->pwd_jdir != NULL) { | ||||
vrefact(pwd->pwd_jdir); | vrefact(pwd->pwd_jdir); | ||||
export_vnode_to_sb(pwd->pwd_jdir, KF_FD_TYPE_JAIL, | error = export_vnode_to_sb(pwd->pwd_jdir, | ||||
FREAD, efbuf); | KF_FD_TYPE_JAIL, FREAD, efbuf); | ||||
} | } | ||||
} | } | ||||
PWDDESC_XUNLOCK(pdp); | PWDDESC_XUNLOCK(pdp); | ||||
if (error != 0) | |||||
goto fail; | |||||
if (pwd != NULL) | if (pwd != NULL) | ||||
pwd_drop(pwd); | pwd_drop(pwd); | ||||
FILEDESC_SLOCK(fdp); | FILEDESC_SLOCK(fdp); | ||||
lastfile = fdlastfile(fdp); | lastfile = fdlastfile(fdp); | ||||
for (i = 0; refcount_load(&fdp->fd_refcnt) > 0 && i <= lastfile; i++) { | for (i = 0; refcount_load(&fdp->fd_refcnt) > 0 && i <= lastfile; i++) { | ||||
if ((fp = fdp->fd_ofiles[i].fde_file) == NULL) | if ((fp = fdp->fd_ofiles[i].fde_file) == NULL) | ||||
continue; | continue; | ||||
#ifdef CAPABILITIES | #ifdef CAPABILITIES | ||||
rights = *cap_rights(fdp, i); | rights = *cap_rights(fdp, i); | ||||
#else /* !CAPABILITIES */ | #else /* !CAPABILITIES */ | ||||
rights = cap_no_rights; | rights = cap_no_rights; | ||||
#endif | #endif | ||||
/* | /* | ||||
* Create sysctl entry. It is OK to drop the filedesc | * Create sysctl entry. It is OK to drop the filedesc | ||||
* lock inside of export_file_to_sb() as we will | * lock inside of export_file_to_sb() as we will | ||||
* re-validate and re-evaluate its properties when the | * re-validate and re-evaluate its properties when the | ||||
* loop continues. | * loop continues. | ||||
*/ | */ | ||||
error = export_file_to_sb(fp, i, &rights, efbuf); | error = export_file_to_sb(fp, i, &rights, efbuf); | ||||
if (error != 0 || efbuf->remainder == 0) | if (error != 0) | ||||
break; | break; | ||||
} | } | ||||
FILEDESC_SUNLOCK(fdp); | FILEDESC_SUNLOCK(fdp); | ||||
fail: | fail: | ||||
if (fdp != NULL) | if (fdp != NULL) | ||||
fddrop(fdp); | fddrop(fdp); | ||||
if (pdp != NULL) | if (pdp != NULL) | ||||
pddrop(pdp); | pddrop(pdp); | ||||
▲ Show 20 Lines • Show All 684 Lines • Show Last 20 Lines |
Is the ordering of sbuf_bcat() -> sbuf_error() well-defined as used here? Or should this be an if()/else?