From owner-freebsd-questions@FreeBSD.ORG Wed Jul 30 04:39:41 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CCCF837B401 for ; Wed, 30 Jul 2003 04:39:41 -0700 (PDT) Received: from studnet.sk (kripel.unitra.sk [193.87.12.67]) by mx1.FreeBSD.org (Postfix) with ESMTP id D8F1A43FA3 for ; Wed, 30 Jul 2003 04:39:35 -0700 (PDT) (envelope-from rado@kripel.studnet.sk) Received: from kripel.studnet.sk (rado@localhost [127.0.0.1]) by studnet.sk (8.12.9/angel's version) with ESMTP id h6UBdUkN068993 for ; Wed, 30 Jul 2003 13:39:30 +0200 (CEST) Received: (from rado@localhost) by kripel.studnet.sk (8.12.9/8.12.9/Submit) id h6UBdU2j068956 for questions@FreeBSD.org; Wed, 30 Jul 2003 13:39:30 +0200 (CEST) (envelope-from rado) Date: Wed, 30 Jul 2003 13:39:30 +0200 From: Radko Keves To: questions@FreeBSD.org Message-ID: <20030730113930.GA54565@studnet.sk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="wac7ysb48OaltWcw" Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Content-Filtered-By: Mailman/MimeDel 2.1.1 Subject: how to access cr_ruid in ucred struct with kvm_read X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jul 2003 11:39:42 -0000 --wac7ysb48OaltWcw Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline hi all i try to access cr_ruid field of ucred struct with kvm_read like this: (rewrited example from cyellow-0.01.tar.gz - tools/listprocs.c original doesn't work too) [...] LIST_HEAD(proclist, proc); int main(int argc, char **argv) { int i; char *buf; kvm_t *kd; struct proc *p_ptr, p; struct ucred cred; struct proclist allproc; char errbuf[_POSIX2_LINE_MAX]; struct nlist nl[] = { { NULL }, { NULL }, }; nl[0].n_name = "allproc"; kd = kvm_openfiles(NULL,NULL,NULL,O_RDONLY,errbuf); if(!kd) { fprintf(stderr,"ERROR: %s\n",errbuf); exit(-1); } if(kvm_nlist(kd,nl) < 0) { fprintf(stderr,"ERROR: %s\n",kvm_geterr(kd)); exit(-1); } if(!nl[0].n_value) { fprintf(stderr,"ERROR: allproc not found (very weird...)\n"); exit(-1); } kvm_read(kd,nl[0].n_value, &allproc, sizeof(struct proclist)); printf("PID\tUID\n\n"); for(p_ptr = allproc.lh_first; p_ptr; p_ptr = p.p_list.le_next) { kvm_read(kd,(unsigned long)p_ptr, &p, sizeof(struct proc)); kvm_read(kd,(unsigned long)p.p_ucred, cred, sizeof(struct ucred)); printf("%d\t%d\n", p.p_pid, cred->cr_ruid); } if(kvm_close(kd) < 0) { fprintf(stderr,"ERROR: %s\n",kvm_geterr(kd)); exit(-1); } [...] and have found this error messages: 1, storage size of `cred' isn't known (struct ucred cred;) 2, sizeof applied to an incomplete type ( kvm_read(kd,(unsigned long)p.p_ucred, cred, sizeof(struct ucred));) my questions: 1, can anybody help me with this problem, how to access cr_ruid ? 2, is retyping pointer to unsigned long addr okay ? 3, is better way to access this structure without kernel module ? of course original package i attache thanks -- bye - R --wac7ysb48OaltWcw--