diff options
author | bde <bde@FreeBSD.org> | 1998-01-16 16:45:05 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1998-01-16 16:45:05 +0000 |
commit | ff6b6a564b57bd38c2dca277dff3eb4921ee9df7 (patch) | |
tree | e3c77793a9d50e993c8bde24ddf410b0f31631a8 /lib/libkvm | |
parent | ca3cb4105e9b072852ae3d77968513c0193473c2 (diff) | |
download | FreeBSD-src-ff6b6a564b57bd38c2dca277dff3eb4921ee9df7.zip FreeBSD-src-ff6b6a564b57bd38c2dca277dff3eb4921ee9df7.tar.gz |
Fixed bugs in the conversion of kvm to to use procfs in rev.1.3. All
are in kvm_uread():
- the setting of errno before checking it in the lseek() was lost.
- EOF handling was lost. kvm_uread() retried forever on EOF. EOF is
not really an error, but report it one as in rev.1.2.
- reporting of errno after a read error was lost.
Fixed style bugs in rev.1.3 and rev.1.12.
Not fixed: errno is not reported after lseek() failures.
Diffstat (limited to 'lib/libkvm')
-rw-r--r-- | lib/libkvm/kvm_proc.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index d167f34..d8a1b8e 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -686,30 +686,35 @@ kvm_uread(kd, p, uva, buf, len) int fd; if (!ISALIVE(kd)) { - _kvm_err(kd, kd->program, "cannot read user space from dead kernel"); - return(0); + _kvm_err(kd, kd->program, + "cannot read user space from dead kernel"); + return (0); } - cp = buf; - sprintf(procfile, "/proc/%d/mem", p->p_pid); fd = open(procfile, O_RDONLY, 0); - if (fd < 0) { _kvm_err(kd, kd->program, "cannot open %s", procfile); close(fd); return (0); } - + cp = buf; while (len > 0) { + errno = 0; if (lseek(fd, (off_t)uva, 0) == -1 && errno != 0) { - _kvm_err(kd, kd->program, "invalid address (%x) in %s", uva, procfile); + _kvm_err(kd, kd->program, "invalid address (%x) in %s", + uva, procfile); break; } amount = read(fd, cp, len); if (amount < 0) { - _kvm_err(kd, kd->program, "error reading %s", procfile); + _kvm_syserr(kd, kd->program, "error reading %s", + procfile); + break; + } + if (amount == 0) { + _kvm_err(kd, kd->program, "EOF reading %s", procfile); break; } cp += amount; @@ -718,5 +723,5 @@ kvm_uread(kd, p, uva, buf, len) } close(fd); - return (ssize_t)(cp - buf); + return ((ssize_t)(cp - buf)); } |