2016-05-03 1:04 GMT+03:00 Alexander Bluhm <alexander.bl...@gmx.net>: > On Sun, May 01, 2016 at 01:24:19AM +0300, Vadim Zhukov wrote: >> When matching by PID, we'd better return ESRCH expicitly rather >> than zero entries. This makes, for example, fstat(1) behaviour >> more consistent and makes it easier to replace "if lsof -p ..." >> checks in third-party code with "if fstat -p ...". >> >> For libkvm, I explicitly test for ESRCH to avoid going inside >> kmem without real need. >> >> Tested on amd64. >> >> Comments? Okays? > > Your use case makes sense. So I think this should go in. > > Can we have the same logic for KERN_FILE_BYPID and KERN_FILE_BYUID?
I don't have strong opinion here. On one side, while PID matching is a single match by definition, UID matching is not. On the other side, if you're looking for particular UID, you do know something about already... If you want it so, then let it be so. I'll send adjusted patch a bit later, having to close laptop ASAP. > man kvm_getfiles says (-1 for all processes), but code does arg > 0. > I think it should be arg => 0 like in KERN_FILE_BYUID. > > The (arg < -1) EINVAL check is missing in KERN_FILE_BYUID. Does > anyone know why? I was stumbled by those differences as well, but preferred to keep the current logic; it could be fixed separately anyway. > errno ESRCH should be documented in kvm_getfiles(3). At the moment, there is not errors section in kvm_getfiles(3) at all. I'm not sure what else should go there: EINVAL? > exit code 1 should be documented in fstat(1). Should it behave > like grep? > 0 One or more lines were selected. > 1 No lines were selected. > >1 An error occurred. I think that's good idea. Thank you for review!