From b8162aa0c9949012533f0436d057c8cc5bea571d Mon Sep 17 00:00:00 2001 From: kib Date: Fri, 15 May 2009 14:41:44 +0000 Subject: Revert r192094. The revision caused problems for sysctl(3) consumers that expect that oldlen is filled with required buffer length even when supplied buffer is too short and returned error is ENOMEM. Redo the fix for kern.proc.filedesc, by reverting the req->oldidx when remaining buffer space is too short for the current kinfo_file structure. Also, only ignore ENOMEM. We have to convert ENOMEM to no error condition to keep existing interface for the sysctl, though. Reported by: ed, Florian Smeets Tested by: pho --- sys/kern/kern_descrip.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'sys/kern/kern_descrip.c') diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index f29b0eb..e0008e6 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2883,6 +2883,7 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER_ARGS) struct proc *p; struct tty *tp; int vfslocked; + size_t oldidx; name = (int *)arg1; if ((p = pfind((pid_t)name[0])) == NULL) @@ -3061,14 +3062,26 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER_ARGS) strlen(kif->kf_path) + 1; kif->kf_structsize = roundup(kif->kf_structsize, sizeof(uint64_t)); + oldidx = req->oldidx; error = SYSCTL_OUT(req, kif, kif->kf_structsize); - if (error) + if (error) { + if (error == ENOMEM) { + /* + * The hack to keep the ABI of sysctl + * kern.proc.filedesc intact, but not + * to account a partially copied + * kinfo_file into the oldidx. + */ + req->oldidx = oldidx; + error = 0; + } break; + } } FILEDESC_SUNLOCK(fdp); fddrop(fdp); free(kif, M_TEMP); - return (0); + return (error); } static SYSCTL_NODE(_kern_proc, KERN_PROC_FILEDESC, filedesc, CTLFLAG_RD, -- cgit v1.1