From ff6b6a564b57bd38c2dca277dff3eb4921ee9df7 Mon Sep 17 00:00:00 2001 From: bde Date: Fri, 16 Jan 1998 16:45:05 +0000 Subject: 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. --- lib/libkvm/kvm_proc.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'lib/libkvm') 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)); } -- cgit v1.1