how to access cr_ruid in ucred struct with kvm_read

Radko Keves rado at studnet.sk
Wed Jul 30 04:39:42 PDT 2003


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


More information about the freebsd-questions mailing list